WCF Exception Shielding Error

While using the WCF Exception Shielding policy in Enterprise Library’s Exception Handler Block to shield exceptions and return Fault Contracts I came across an error. I named the shielding policy “WCF Shielding Policy” and implemented a FaultContract for each type of desired or expected exception.

While testing the policy, we were unable to return a proper FaultContract from the WCF Service.  The only error that we received was the generic Communication Error:

System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to (path of service).
 This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down).
See server logs for more details. --->  System.Net.WebException: The underlying connection was closed:
An unexpected error occurred on a receive.
  System.IO.IOException: Unable to read data from the transport connection: An existing connection was
forcibly closed by the remote host.
 System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.

This error is incredibly deceiving and led to many dead ends while trying to track down the root cause of the error. I re-wrote the app.config file and removed and re-added the service references, all to no avail.

The cause of the problem was simply in the name of the policy. If you don’t name your shielding policy “WCF Exception Shielding” verbatim then the policy will not be found and the error above will be thrown.  If you do name your policy something different or you implement different policies for different types of exceptions then you have to explicitly state in the ExceptionShielding attribute the name of the policy as follows:

C#:[ExceptionShielding("MyPolicy")]
VB: <ExceptionShielding ("MyPolicy")>

I renamed the policy to the default name and started receiving the Fault Contracts as expected.

Hope this helps eliminate some headaches for someone.

-Craig

General

Comments (0)

Permalink

Write iPhone Applications in C# using MonoTouch

The mono project has released a new Mono edition for Apple’s iPhone and iPod Touch.  This allows you to write full featured applications for the iPod touch using C#. 

This is not a JIT Compiler, but is a static compiler that turns .NET executables into native applications. 

For more information, check out the project at : http://www.mono-project.com/MonoTouch

General

Comments (0)

Permalink

Spring and Functional Tests

Recently on our project we created a “functional” unit test for some services. The test was designed to check the entire call stack from the service layer to the DAO and return some expected results. We are using Spring for dependency injection through our entire application. This functional test initially only referenced the service DLL’s as this is all we thought that had to be referenced.  Upon execution, the test was failing due to “null or empty Context”. We knew that we had referenced the context in the configuration file correctly, but were perplexed at how the spring context were not loading.

We finally realized that it was an issue with Resharper and how the tests were executed differently then when run is Visual Studio using default run (ctrl + r, t)

Once this was solved, we were getting reference exceptions.

To solve this error, it is necessary to reference in your test project all of the DLL’s that are referenced in your Spring xml file. It will not work unless you do so.

-Craig

General

Comments (0)

Permalink

RESTFul Services in Silverlight - CT Code Camp June 2009

Downloade the Presentation and Code 

The Connecticut User Group organized a full day code camp event in Bloomfield, CT. The topic I presented on was “RESTFul Services and Silverlight”. The presentation was organized around the following main topics:

  • Web Services via SOAP
  • RESTFul Services
  • Creating a WCF RESTFul Service
  • Consuming a Custom WCF RESTFul Service in Silverlight

The attached slide deck will provide you with highlights on each topic. The code samples revolve around the AdventureWorks Database. I have partitioned the code into Data Access, Service Layer and a UI Layer.

  • Database: AdventureWorksDB from code plex. You can download it from here: http://www.codeplex.com/MSFTDBProdSamples
  • Data Access: Used Nettiers and Codesmith to Generate the CRUD methods to access Adventure Works.
  • Service Layer: WCF, ASMX and WCF REST service examples. I have also included a sample service from John Papa’s Data Services with Silverlight book. I would recommend this book for who ever is working with Siverlight
  • UI Layer: Consists of a ASP.NET web site that houses the silverlight controls and the silverlight controls themselves. The services are conusmed by silverlight.

During the actual presentation, i also created a simple WCF Service and demo’ed how to use a simple SOAP WCF service in a silverlight client using the Asynchronous pattern.

Check the samples out!

Happy coding

Reddy (reddy.kadasani@tallan.com)

.NET Framework
Presentations
User Groups
WCF

Comments (0)

Permalink

Content from LINQ Code Camp Presentation (6/13/09)

On June 13, 2009 I was privileged to give a presentation at the Hartford Code Camp at New Foundations in Bloomfield, CT.   The event was a great success, with 29 presenters,  35 sessions, and more than 150 people in attendance.  I’d like to say thank you to anyone who was able to attend my session on LINQ, my group was great and had a lot of insightful and pointed questions.

As promised, I’m posting the content from the presentation including the PowerPoint files and Demo Code. 

If anyone has any questions about the content, please feel free to e-mail me at mgerety@tallan.com

Presentation and Content Files: LINQ Presentation And Files

.NET Framework
Presentations

Comments (0)

Permalink

Convert Multi-page image to Collection of Bitmaps

Recently on a project, we had the need to convert a saved multi-page tiff to a collection of bitmaps for viewing in a UI using standard GDI+ methods. These bitmaps also needed to be printed in a high quality way for submission to a government agency.  This method ensures that no quality will be lost from the creation of the new bitmap objects.

/////////////////////////////////////////
// by Craig Vallee
// Consultant
// Tallan, Inc.
/////////////////////////////////////////

private static List<Bitmap> ImageToBitmap()
{
    //Create and Image object from file path and name
    Image originalImage = Image.FromFile(@"C:\Temp\Your_File.tif");

    //Create a collection of Bitmap objects 
    List<Bitmap> bitmapList = new List<Bitmap>();

    //Place holders for setting resolution of new Bitmap objects
    var xResolution = originalImage.HorizontalResolution;
    var yResolution = originalImage.VerticalResolution;

    //Create FrameDimesion for iteration through file frames
    FrameDimension frameDimension = new FrameDimension(originalImage.FrameDimensionsList[0]);

    //Framecount of image for iteration through file frames
    int frameCount = originalImage.GetFrameCount(FrameDimension.Page);

    //Simple iteration through file frames
    for (int i = 0; i < frameCount; ++i)
    {
        //Create bitmap to hold individual frame
        Bitmap bmp;

        //Moves active frame pointer to next frame in iteration
        originalImage.SelectActiveFrame(frameDimension, i);

        //Cast image frame to Bitamp holder
        bmp = (Bitmap)originalImage;

        //Create new Bitmap from placeholder
        Bitmap temp = new Bitmap(bmp);

        //Set bitmap resolution based on original resolution
        temp.SetResolution(xResolution, yResolution);

        //Add Bitmap to Bitmap collection
        bitmapList.Add(temp);
    }
    return bitmapList;

}

-Craig

.NET Framework
General

Comments (0)

Permalink

Windows Worfklow: Error 1342 Activity X validation failed: Can not find the condition Y

This is just a small tip for anyone doing any WWF work:  The workflow’s name property MUST MATCH file workflow filename or rules and conditions will not be found, and the workflow will not be instantiated.

Example:

Create a sequential workflow.  Call it WorkflowA.cs.

Click the workflow in the designer mode, and change the name of the workflow in the property window to WkflwA.  Add any activity that takes conditions (i.e., if/then/else). 

Add a valid condition to this activity.

Attempt to start the workflow.

 

You will get a WorkflowValidationFailedException saying that the Workflow failed validation.  To correct this issue, rename the workflow back to “WorkflowA” and restart.  The workflow will instantiate without issue.

.NET Framework
General

Comments (0)

Permalink

Bitmap Default resolution

Recently I encountered a problem regarding default resolution for Images. An image that had been stored in a database as a multi-page tiff needed to be split into individual bitmaps for display and print on a winform using standard GDI+. While spliting the tiffs and creating the new bitmaps, the resolution was lost and was set to the default value of Bitmaps. While the display on the winform was not a problem as the viewer handled the image sizing, the printing of the image resulted in a very distorted printed image.

Upon examination of the image, the resolution was 300 x 300. Upon creation of the bitmap it defaulted to 72 x 72.

This problem was quickly resolved by setting the resolution of all of the new  bitmaps  to the original resolution contained in the image object.

Seems like a simple fix, but it created a huge problem on the project.

-Craig

General

Comments (0)

Permalink

Creating a Project Installer for a Windows Service

I recently had to create a Windows Service for a project I’m currently working on.  Rather than installing/uninstalling using InstallUtil, I decided to create a project installer to do the work for me.  It took a little bit of digging to gather all of the necessary steps, so here is what I did to get up and running.

  1. Create your Windows Service project and Windows Service.
  2. Navigate to the designer for your Windows Service. Under the properties for your service you should see (Name) and ServiceName. Fill in both of these properties with your desired names. You will need to reference these later.
  3. In the designer for your Windows Service, right-click and click Add Installer. You should now have a ProjectInstaller.cs file, along with a designer file for the installer.
  4. Navigate to the designer for your new project installer. You should see two components, a Service Process Installer and a Service Installer. Under the Service Installer properties, you will need to add a DisplayName, and provide the ServiceName of the service you will be installing. The ServiceName must match the (Name) property of the service.
  5. Build your Windows Service project. Now in the same solution, add a new Setup Project. This will provide the Wizard interface for the installation process.
  6. After adding the project, you need to add the primary output of your Windows Service to the Setup Project. Do this by right-clicking on the Setup Project -> Add -> Project Output. Select your Windows Service project from the drop down, highlight Primary Output and click OK.
  7. Up to this point the installer will install the correct files, but it doesn’t know what to do with the files. We can add custom actions to do the service installation work. Right-click on the Setup Project -> View -> Custom Actions. For a Windows Service we need to add actions for Install, Rollback, and Uninstall. Right-click each of these and click Add Action. Double click Application Folder and select the Primary Output from your Windows Service project.
  8. You can now build your Setup Project. The output of this build will be two setup files which are used to install your new Windows Service.

-Jon

.NET Framework
General

Comments (0)

Permalink

.NetTiers Component Business Layer Architecture

I posted a blog on my blog site that takes a look at the Patterns used in the .NetTier Service Layer Architecture.  Check it out at …

http://www.stanfordkennedy.com/2009/05/nettiers-architecture-design-patterns.html

~Stan Kennedy

General

Comments (0)

Permalink