<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>WCF</title>
        <link>http://jamescbender.com/bendersblog/category/1.aspx</link>
        <description>WCF</description>
        <language>en-US</language>
        <copyright>James Bender</copyright>
        <managingEditor>james.c.bender@live.com</managingEditor>
        <generator>Subtext Version 1.9.5.177</generator>
        <item>
            <title>Working with WCF: Part One: Introduction and Your First Service</title>
            <link>http://jamescbender.com/bendersblog/archive/2010/03/06/working-with-wcf-part-one-introduction-and-your-first-service.aspx</link>
            <description>&lt;p&gt;I’ve been playing with WCF since .NET 3 came out. Sometimes I have to be reminded that not everybody is as familiar with all it’s “cob-webby corners” as I am. And that’s OK. Often (too often) I encounter someone who has NEVER used WCF and doesn’t even know where to begin.That’s not so OK. &lt;/p&gt;  &lt;p&gt;Usually I encounter these poor souls right when they need to be able to create or deal with WCF services NOW! Since it’s generally too late for them to attend my “Getting Started with WCF” talk by this time, and I can’t always drop what I’m doing to help them, I’ll be devoting several posts to the basics of WCF. While these posts are created with the new user (no previous WCF experience) in mind, even seasoned users may get something out of these posts.&lt;/p&gt;  &lt;p&gt;The first post will cover creating your first service. Future posts will demonstrate the various ways to consume services, custom messages, what behaviors are, transports, what channels are, REST vs. SOAP and how to create a REST service in WCF, deployment, what’s coming in .NET 4.0, some entry-level RIA service work and all sorts of other WCF goodness.&lt;/p&gt;  &lt;h1&gt;Every Journey Begins With yada yada yada…&lt;/h1&gt;  &lt;p&gt;As mentioned, this post will take you through creating your first service. In this series I will be using Visual Studio 2010 (currently using Beta 2) with the .NET 3.5. You do NOT need VS 2010 for this example, VS 2008 will work fine. At some point I will dedicate a post to what’s new in .NET 4, and having Visual Studio 2010 will be necessary if you want to follow along. &lt;/p&gt;  &lt;p&gt;We’ll be creating a simple service and hosting it in the test WCF Server that ships with Visual Studio. In the next post we will create a console application to host our service. Hosting in IIS is a deep topic, and will be covered in a future post. Remember, when starting Visual Studio you will need to run it as an administrator. For information on how to do this, see &lt;a href="http://jeffblankenburg.com/2010/02/19th-of-diduary-did-you-know-that-you.aspx"&gt;this post&lt;/a&gt; by Jeff Blankenburg.&lt;/p&gt;  &lt;h1&gt;Away We Go…&lt;/h1&gt;  &lt;p&gt;In our example we are going to be building a serviced based front end for an internet-based bakery called Web Bagels. &lt;/p&gt;  &lt;p&gt;Open the dialog in Visual Studio to create a new project. Open the C# node and select the WCF sub-node.You’ll see a list of available WCF projects. We are going to create a WCF Service Library and call it WebBagels. The resulting dialog should look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb.png" width="671" height="409" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Although we are going to be doing these demos in C# you can easily accomplish the same thing in VB.NET.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Click OK and wait for Visual Studio to perform its magic. When it’s done you’ll have what appears to be a normal class library with a few files in it:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_3.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_3.png" width="273" height="319" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The files IService1.cs and Service1.cs are sample WCF files. Feel free to open them up and look through them if you like, but we’re not going to use them for the demo, so delete them when you’re finished. Unlike most class libraries, this one has an app.config file. We’re going to need this, so make sure you keep it around.&lt;/p&gt;  &lt;p&gt;The next step is to create a file for our service. Create a C# class file called BagelOrderService. Your solutions should look like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_4.png" width="273" height="323" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h1&gt;Our First Actual WCF Stuff&lt;/h1&gt;  &lt;p&gt;The first service we’re going to create is a simple service to allow users to submit bagel orders. They’ll tell us how many dozen bagels they want and what flavor. &lt;/p&gt;  &lt;p&gt;WCF services are simple classes; they have public methods that generally take arguments (but don’t have to), do some work and may or may not return values. The difference between WCF services and plain objects is that we must tell WCF that the methods of this class are going to be accessed externally via a channel (Http, TCP, MSMQ, etc.) that is going to send a message to the class to execute an action.&lt;/p&gt;  &lt;p&gt;So how do we do this? Turns out with WCF it’s very easy.&lt;/p&gt;  &lt;p&gt;The first step is to create an interface that defines our bagel ordering method:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_5.png" width="555" height="274" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now I know what some of you are probably saying: “[gasp] He put the interface in the same file as the class! HERETIC!”&lt;/p&gt;  &lt;p&gt;Relax. This is a demo. They are in the same file &lt;strike&gt;because I am lazy&lt;/strike&gt; for the sake of clarity. In reality I would not put interfaces for WCF services in the same file as the service. That’s not to say I &lt;em&gt;never&lt;/em&gt; put interfaces and classes in the same file, but that’s another post.&lt;/p&gt;  &lt;p&gt;Let go ahead and implement our interface in our BagelOrderService class:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_6.png" width="555" height="311" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We now have a class that will take bagel orders and return an order number! OK, it’s not actually doing &lt;em&gt;that&lt;/em&gt; much. But it’s enough to get us going. We’ll be building this service out over the course of this series. &lt;/p&gt;  &lt;p&gt;To turn it into a WCF service we need to identify it to the .NET framework as a WCF service. This is done using the ServiceContact and OperationContract attributes:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_7.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_7.png" width="555" height="389" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Notice the new using statement at the top of the class. ServiceContract and OperationContract reside in the System.ServiceModel assembly. Visual Studio was kind enough to include a reference to this assembly for us when we told it we were creating WCF services. If we hadn’t we’d have had to add the reference manually.&lt;/p&gt;  &lt;p&gt;ServiceContract identifies the interface as being an interface for a service. When you run a hosting application (one you write or IIS) the .NET runtime knows to look at this interface and build a service mechanism around it. You can set specific attributes about your service here like namespace and session mode as arguments to the ServiceContract attribute. We’ll cover this in a later post, for now the defaults will be find.&lt;/p&gt;  &lt;p&gt;For the most part WCF operates on an “opt-in” model, meaning that just identifying a class of interface as being a WCF object (via the ServiceContact attribute) doesn’t mean that the individual methods or properties are going to be recognized and used by WCF. This can be contrasted with the .NET XML serializer which is an “opt-out” model, meaning that if you decorate a class with the Serializable attribute, all the public properties will be serialized. If you want properties to be ignored you must specify which ones to ignore. &lt;/p&gt;  &lt;p&gt;OperationContract is the attribute we use to identify which methods in our interface we want to be exposed as actions on our service. Like ServiceContract there are a variety of attributes we can specify about the action that will be exposed on the service like action name and if the call is a one-way action.&lt;/p&gt;  &lt;p&gt;One thing to note, you don’t have to use an interface here. You could add the ServiceContract and OperationContract to your class and things would work just fine. But don’t do this. Tieing your service implementation, or any “service based” class to a concrete implementation is never a good idea.&lt;/p&gt;  &lt;p&gt;Actions are basically the service equivalent of methods. More on those in a later post.&lt;/p&gt;  &lt;h1&gt;It Wouldn’t Be .NET Without a Configuration File…&lt;/h1&gt;  &lt;p&gt;… and WCF is no exception.&lt;/p&gt;  &lt;p&gt;Remember when I said we were going to hold on to that app.config file? Good, because now is when we need it. Open it in Visual Studio. It should look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_8.png" width="555" height="246" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;There is A LOT of stuff to cover in this file. Today we’re just going to worry about the bare necessities to the our service up and running. The first step is to make sure this configuration file is actually using our service. Find this line in the configuration file:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_9.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_9.png" width="553" height="14" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This is the node in our configuration that tells WCF which concrete implementation of our service we are going to be using. In our case it’s the BagelOrderService class. Change this line to look like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_10.png" width="553" height="14" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We’re almost done! All that’s left is to let WCF know where our service contact is. That’s done by change the contact attribute of our endpoint. The endpoint for our service should like something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_11.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_11.png" width="553" height="18" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We just need to change the contact attribute to point to our service contract:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_12.png" width="553" height="16" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We’re ready to test!&lt;/p&gt;  &lt;h1&gt;Let’s Light This Candle&lt;/h1&gt;  &lt;p&gt;Our WCF class library is a little different than an traditional Visual Studio class library. Normally when you try to debug a class library in Visual Studio you’re given a “gentle reminder” that you can’t actually run libraries. Our WCF library is special though. In order to ease development and testing of WCF services Microsoft has included a small testing service host (think of it as Cassini for services) and a test client. Press F5 in Visual Studio to start debugging. Your solution will compile and Visual Studio will start the test host for you:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_13.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_13.png" width="374" height="164" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This may take a few moment, especially the first time you run the service. Once the service is up and running you’ll be presented with the WCF test client:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_14.png" width="553" height="350" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;On the left side we have a tree view which represents our service. Currently we only have one method (PlaceOrder) in our service, so we only have the one node under our interface. Double click on that node and the right section of the window should present you with a data entry screen to test our service with:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_15.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_15.png" width="553" height="449" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Let’s try it go head and enter some data in the “Value” fields for both arguments and press the Invoke button. It may take several seconds the first time, but you should see a result similar to this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.jamescbender.com//BendersBlog/Images/Blog/WorkingwithWCFPartOneIntroductionandYour_B6E0/image_thumb_16.png" width="553" height="449" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;There are a few more goodies hidden in this test client which we’ll explore in a future post.&lt;/p&gt;  &lt;p&gt;Congratulations, you just created a WCF service!&lt;/p&gt;  &lt;p&gt;In the next post I’ll explain more about the configuration file and show you how to create a console application to host your new service.&lt;/p&gt;  &lt;p&gt;Code on!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://jamescbender.com/bendersblog/archive/2010/03/06/working-with-wcf-part-one-introduction-and-your-first-service.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2010/03/06/working-with-wcf-part-one-introduction-and-your-first-service.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/61.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2010/03/06/working-with-wcf-part-one-introduction-and-your-first-service.aspx</guid>
            <pubDate>Sat, 06 Mar 2010 12:52:14 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/61.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2010/03/06/working-with-wcf-part-one-introduction-and-your-first-service.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/61.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Getting Started with WCF Slides and Code Sample from CINNUG</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/09/03/getting-started-with-wcf-slides-and-code-sample-from-cinnug.aspx</link>
            <description>&lt;p&gt;Better late than never…&lt;/p&gt;  &lt;p&gt;Seriously, sorry to everyone who’s been waiting for these.&lt;/p&gt;  &lt;p&gt;I had a great time speaking in Cincinnati last week and meet a lot of great people. I hope to see you all again soon.&lt;/p&gt; &lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-de4aebf19948423f.skydrive.live.com/embedrow.aspx/Public/CINNUG" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://jamescbender.com/bendersblog/archive/2009/09/03/getting-started-with-wcf-slides-and-code-sample-from-cinnug.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/09/03/getting-started-with-wcf-slides-and-code-sample-from-cinnug.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/57.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/09/03/getting-started-with-wcf-slides-and-code-sample-from-cinnug.aspx</guid>
            <pubDate>Thu, 03 Sep 2009 12:17:50 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/57.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/09/03/getting-started-with-wcf-slides-and-code-sample-from-cinnug.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/57.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Exceptions Happen, Part 1</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/08/11/exceptions-happen-part-1.aspx</link>
            <description>&lt;p&gt;You might thing you’re special, but your not. And sooner or later it’s gonna happen to you too. Your WCF Service is going to encounter a *gasp* Exception. Do you know what to do when it does happen?&lt;/p&gt;  &lt;p&gt;Scott Hanselman wrote a terriffic &lt;a href="http://www.hanselman.com/blog/GoodExceptionManagementRulesOfThumb.aspx" target="_blank"&gt;blog post&lt;/a&gt; on exceptions. It’s a great place to start and if you haven’t read it you should. I wrote a post last year about working with the WCF Fault Contract. But there’s more than one way to skin this cat. What I’m going to be focusing on in this series of posts are the ways you can deal with exceptions in WCF and how to communicate what’s happened to your client. &lt;/p&gt;  &lt;p&gt;In the first installment we’re going to look at how exceptions get received by a WCF client and how the WCF channel reacts to exceptions. Let’s start with what happens if you just throw a normal .NET exception. For this example we’ll be looking at a mock up of a service to return prices for stocks based on a ticker symbol.&lt;/p&gt;  &lt;p&gt;The service contact:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;    [ServiceContract]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IMyWcfService&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        [OperationContract]&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;decimal&lt;/span&gt; GetStockPrice(&lt;span class="kwrd"&gt;string&lt;/span&gt; symbol);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt; &lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;And the implementation:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyWcfService : IMyWcfService&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;decimal&lt;/span&gt; GetStockPrice(&lt;span class="kwrd"&gt;string&lt;/span&gt; symbol)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            &lt;span class="kwrd"&gt;switch&lt;/span&gt; (symbol)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;"MSFT"&lt;/span&gt;:&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;decimal&lt;/span&gt;) 1.41;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;"IBM"&lt;/span&gt;:&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;decimal&lt;/span&gt;).89;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;"JAVA"&lt;/span&gt;:&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;decimal&lt;/span&gt;).10;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;                &lt;span class="kwrd"&gt;default&lt;/span&gt;:&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentOutOfRangeException(&lt;span class="str"&gt;"symbol"&lt;/span&gt;, &lt;span class="str"&gt;"bad symbol"&lt;/span&gt;);                   &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Since this is a contrived demo, we only handle three symbols and return a static value. This does however provide us with an opportunity to see how .NET exceptions work in WCF. If we receive a symbol that is not in our list, we are throwing an ArgumentOtOfRangeException. If we were using this as just a .NET object we wouldn’t have a problem; either our code would catch the exception and do something with it, or it would bubble up to the user.&lt;/p&gt;

&lt;p&gt;Our client is a winform application. The important part is the call to our service (via a proxy of course):&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Form1 : Form&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; MyWcfServiceClient _proxy;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Form1()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        InitializeComponent();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        btnCallService.Click += CallService;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        _proxy = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyWcfServiceClient();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallService(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        lblResult.Text = _proxy.GetStockPrice(txtSymbol.Text).ToString();            &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;So all we’re doing is grabbing a value (the ticker symbol) from a text box and passing it as an argument to the service. The result is used to set the value of a label control. When we run this and feed one of the three symbols that our service uses, the expected happens: a value is returned and set to the text of the label. When we provide an unsupported symbol, we get an error:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image_thumb.png" width="496" height="437" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The exception text should look familiar to anyone who has worked with ASP.NET…&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font color="#0000a0"&gt;&lt;em&gt;System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &amp;lt;serviceDebug&amp;gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Like ASP.NET, WCF will not return detailed exception information to clients as a security measure. Like ASP.NET we have the ability to change the configuration to return more detailed exception information. One line nine below, we have set the includeExceptionDetailInFaults value to “True”:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;="1.0"&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;="utf-8"&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;...&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Service1Behavior"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceMetadata&lt;/span&gt; &lt;span class="attr"&gt;httpGetEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceDebug&lt;/span&gt; &lt;span class="attr"&gt;includeExceptionDetailInFaults&lt;/span&gt;&lt;span class="kwrd"&gt;="&lt;strong&gt;True&lt;/strong&gt;"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;         &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;This results in the details of the error message being passed back to us:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image_3.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image_thumb_3.png" width="496" height="371" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Like ASP.NET, this can be OK for development, but is not a good idea for production. &lt;/p&gt;

&lt;p&gt;Let’s make a few changes to our client application:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallService(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        lblResult.Text = _proxy.GetStockPrice(txtSymbol.Text).ToString();            &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;catch&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        MessageBox.Show(&lt;span class="str"&gt;"Service call failed"&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    }            &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;By catching the exception we can let the user know that something happened and handle it gracefully. Running the application and use the symbol “ORCL” causes the exception, which is handled:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image_thumb_4.png" width="244" height="241" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So, we can just re-submit a supported symbol right…?&lt;/p&gt;

&lt;p&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://jamescbender.com/bendersblog/Images/Blog/CoolWCFClientTricks_D511/image_thumb_4.png" width="244" height="241" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Uh-oh. &lt;/p&gt;

&lt;p&gt;Turns out that when a WCF service throws a normal .NET exception, it faults the channel. Any subsequent calls to the channel results in a CommunicationObjectFaultedExcption being thrown immediately. The channel cannot be salvaged; your only option is to throw it out and recreate it. The proxy implements an interface called ICommunicatioObject that has a &lt;em&gt;Faulted&lt;/em&gt; event that we can subscribe to.A few more changes to our client…:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; MyWcfServiceClient _proxy;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; Form1()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    InitializeComponent();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    btnCallService.Click += CallService;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    _proxy = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyWcfServiceClient();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    ((ICommunicationObject)_proxy).Faulted += RecreateProxy;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; RecreateProxy(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    _proxy = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyWcfServiceClient();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;… and now our client is able to recreate the proxy if a communication fault occurs.&lt;/p&gt;

&lt;p&gt;This way of dealing with exceptions in WCF works well if you are a client of a service that you may not control or have the metadata needed to create a fault contract for. Otherwise, using the FaultException class and/or WCF fault contracts are a better way to go. I’ll be covering them more in detail in the next couple posts.&lt;/p&gt;

&lt;p&gt;Code on!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://jamescbender.com/bendersblog/archive/2009/08/11/exceptions-happen-part-1.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/08/11/exceptions-happen-part-1.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/55.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/08/11/exceptions-happen-part-1.aspx</guid>
            <pubDate>Tue, 11 Aug 2009 19:11:20 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/55.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/08/11/exceptions-happen-part-1.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/55.aspx</wfw:commentRss>
        </item>
        <item>
            <title>I&amp;rsquo;m Following Rod Paddock at Codestock?!</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/06/24/irsquom-following-rod-paddock-at-codestock.aspx</link>
            <description>&lt;p&gt;&lt;a target="_blank" href="http://codestock.org/"&gt;Codestock&lt;/a&gt; is this weekend in Knoxville. You can check out the agenda page &lt;a target="_blank" href="http://codestock.org/Agenda.aspx"&gt;here&lt;/a&gt; and see that there are some great, very smart people speaking there. With seven tracks over two days, plus open spaces, there’s something for everyone at this great event. I was honored to speak at the first Codestock event last year, and I’m thrilled to be back!&lt;/p&gt;
&lt;p&gt;I’ll be presenting “&lt;strong&gt;How to make your application awesome with JSON, REST and WCF&lt;/strong&gt;” in which I’ll explain why REST is the “new” hotness (turns out it’s not that new) and how to take advantage of it with WCF. You’ll also get to see some cool &lt;a target="_blank" href="http://jquery.com/"&gt;JQuery&lt;/a&gt; and &lt;a target="_blank" href="http://www.asp.net/mvc/"&gt;ASP.NET MVC&lt;/a&gt; stuff as part of the talk. It’s the first time I’ve given this talk, so I’m very excited!&lt;/p&gt;
&lt;p&gt;Turns out I’m following &lt;a target="_blank" href="http://blog.dashpoint.com/"&gt;Rod Paddock&lt;/a&gt;. Yeah, that Rod Paddock. Editor in Chief of &lt;a target="_blank" href="http://www.code-magazine.com/"&gt;CoDe Magazine&lt;/a&gt;, author of many books, international speaker and Microsoft MVP. By contrast, I was all excited this morning because I found a $5.00 bill in my pocket that I forgot I had. &lt;/p&gt;
&lt;p&gt;Ron Paddock followed by James Bender. Kinda like…&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="2" border="1" width="452"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td width="133" valign="top"&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/beer.jpg"&gt;&lt;img height="204" border="0" width="244" src="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/beer_thumb.jpg" alt="beer" title="beer" style="border-width: 0px; display: inline;" /&gt;&lt;/a&gt; &lt;/td&gt;
            &lt;td width="201" valign="top"&gt;&lt;strong&gt;&lt;font size="4"&gt;followed by&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
            &lt;td width="116" valign="top"&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/passedout.jpg"&gt;&lt;img height="184" border="0" width="244" src="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/passedout_thumb.jpg" alt="passed out" title="passed out" style="border-width: 0px; display: inline;" /&gt;&lt;/a&gt; &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="133" valign="top"&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/skiing.jpg"&gt;&lt;img height="164" border="0" width="244" src="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/skiing_thumb.jpg" alt="skiing" title="skiing" style="border-width: 0px; display: inline;" /&gt;&lt;/a&gt;&lt;strong&gt;&lt;font size="4"&gt; &lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
            &lt;td width="201" valign="top"&gt;&lt;strong&gt;&lt;font size="4"&gt;followed by&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
            &lt;td width="116" valign="top"&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/cast.jpg"&gt;&lt;img height="187" border="0" width="126" src="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/cast_thumb.jpg" alt="cast" title="cast" style="border-width: 0px; margin: 0px; display: inline;" /&gt;&lt;/a&gt; &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="133" valign="top"&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/the_beatles3.jpg"&gt;&lt;img height="184" border="0" width="244" src="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/the_beatles3_thumb.jpg" alt="the_beatles3" title="the_beatles3" style="border-width: 0px; display: inline;" /&gt;&lt;/a&gt; &lt;/td&gt;
            &lt;td width="201" valign="top"&gt;&lt;strong&gt;&lt;font size="4"&gt;followed by&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
            &lt;td width="116" valign="top"&gt;&lt;a href="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/Vanilla_Ice_Cool_as_Ice.jpg"&gt;&lt;img height="197" border="0" width="198" src="http://jamescbender.com/bendersblog/Images/Blog/ImFollowingRodPaddockatCodestock_14A36/Vanilla_Ice_Cool_as_Ice_thumb.jpg" alt="Vanilla_Ice_Cool_as_Ice" title="Vanilla_Ice_Cool_as_Ice" style="border-width: 0px; display: inline;" /&gt;&lt;/a&gt; &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In all seriousness, I’m really looking forward and VERY happy to be speaking at Codestock. It’s a must-attend event and if you’re not going, well, you should go!&lt;/p&gt;
&lt;div style="margin: 0px; padding: 4px; text-align: left;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://jamescbender.com/bendersblog/archive/2009/06/24/irsquom-following-rod-paddock-at-codestock.aspx"&gt;&lt;img border="0" alt="DotNetKicks Image" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/06/24/irsquom-following-rod-paddock-at-codestock.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;input type="hidden" id="gwProxy" /&gt;&lt;!--Session data--&gt;&lt;input type="hidden" id="jsProxy" onclick="jsCall();" /&gt;
&lt;div id="refHTML"&gt; &lt;/div&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/52.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/06/24/irsquom-following-rod-paddock-at-codestock.aspx</guid>
            <pubDate>Thu, 25 Jun 2009 03:46:07 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/52.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/06/24/irsquom-following-rod-paddock-at-codestock.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/52.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Indy Code Camp Recap</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/05/16/indy-code-camp-recap.aspx</link>
            <description>&lt;p&gt;Thanks to everyone who attended my talk on custom WCF behaviors at the Indy Code Camp. I hope you all found the topic interesting and the content useful.&lt;/p&gt;
&lt;p&gt;You can get the slides and code samples here:&lt;/p&gt;
&lt;iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 240px; PADDING-RIGHT: 0px; HEIGHT: 26px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight="0" src="http://cid-de4aebf19948423f.skydrive.live.com/embedrow.aspx/Public/Code%20Samples/IndyCodeCampCustomBehavior/CodeSamples.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 240px; PADDING-RIGHT: 0px; HEIGHT: 26px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight="0" src="http://cid-de4aebf19948423f.skydrive.live.com/embedrow.aspx/Public/Code%20Samples/IndyCodeCampCustomBehavior/WCF%20Behaviors.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;
&lt;p&gt;For those who might be interested, I’ll be presenting an Intro to WCF talk at &lt;a href="http://cinnug.org/"&gt;Cincinnati .NET Users Group&lt;/a&gt; in the future. More information will be posted here in the future.&lt;/p&gt;
&lt;div style="TEXT-ALIGN: left; PADDING-BOTTOM: 4px; MARGIN: 0px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px; PADDING-TOP: 4px" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://jamescbender.com/bendersblog/archive/2009/05/16/indy-code-camp-recap.aspx"&gt;&lt;img border="0" alt="DotNetKicks Image" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/05/16/indy-code-camp-recap.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;img src="http://jamescbender.com/bendersblog/aggbug/50.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/05/16/indy-code-camp-recap.aspx</guid>
            <pubDate>Sun, 17 May 2009 02:57:59 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/50.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/05/16/indy-code-camp-recap.aspx#feedback</comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/50.aspx</wfw:commentRss>
        </item>
        <item>
            <title>What&amp;rsquo;s At the Center of A Tootsie Pop &amp;ndash; Why Developers Need to Know WCF</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/04/07/whatrsquos-at-the-center-of-a-tootsie-pop-ndash-why.aspx</link>
            <description>&lt;p&gt;This past Saturday I took part in the West Michigan .NET University. In addition to the .NET Bootcamp I did with &lt;a href="http://geekswithblogs.net/ignu/Default.aspx"&gt;Len&lt;/a&gt;, I presented on Web Service concepts and WCF. At the end of the WCF session I was asked if Microsoft was really committed to WCF or if something else will be replacing it in a few years.&lt;/p&gt;  &lt;p&gt;I believe the answer is that Microsoft is committed to WCF. &lt;/p&gt;  &lt;p&gt;If you look at all of the recent cloud-based offerings by Microsoft you can see it’s commitment to WCF in the API’s. These new platforms and services all communicate via services. An Azure application uses WCF services to communicate between it’s various worker and web roles. The SDK for .NET services is largely made up of extensions to WCF in the form of new bindings. Live Mesh allows you to access your content via service REST endpoints. All built on WCF.&lt;/p&gt;  &lt;p&gt;So it’s clear to me that Microsoft is committed to WCF as the “center” of it’s on-going cloud strategy. It’s also clear to me that while deep knowledge of things such as custom behaviors and bindings can still be a “niche” skill, developers MUST have a solid working knowledge of WCF that goes beyond the standard “Hello World” sample. &lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://jamescbender.com/bendersblog/archive/2009/04/07/whatrsquos-at-the-center-of-a-tootsie-pop-ndash-why.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/04/07/whatrsquos-at-the-center-of-a-tootsie-pop-ndash-why.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/43.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/04/07/whatrsquos-at-the-center-of-a-tootsie-pop-ndash-why.aspx</guid>
            <pubDate>Tue, 07 Apr 2009 19:04:39 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/43.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/04/07/whatrsquos-at-the-center-of-a-tootsie-pop-ndash-why.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/43.aspx</wfw:commentRss>
        </item>
        <item>
            <title>The one where I talk about the MSMQ Binding</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/04/04/the-one-where-i-talk-about-the-msmq-binding.aspx</link>
            <description>&lt;p&gt;One of the most over-looked bindings available in WCF is the Microsoft Message Queue (MSMQ) binding. The virtues of HTTP and TCP are well documented. REST is the cool, “new” way to access services. MSMQ seems relegated to interfacing WCF with older “legacy” systems.&lt;/p&gt;  &lt;p&gt;This shouldn’t be the case. The MSMQ binding provides a rich set of features and functionality that make it an excellent choice for building many types of applications.&lt;/p&gt;  &lt;h1&gt;MSMQ from 1,000 ft.&lt;/h1&gt;  &lt;p&gt;MSMQ is a first-in, first-out message queue that have been available in Windows Server since NT 4. The concept is pretty simple: a sender sends a message to the queue, and a receive pulls it off when it’s ready.&lt;/p&gt;  &lt;p&gt;The big benefit of MSMQ is that it allows messages to be passed between computers across networks in a secure, reliable manner. Since the queue is not an actual component of either application, the receiver does not need to be running when the message is sent (it will sit in the queue and wait to be picked up) nor does the receiver have to be on-line when the message is processed. Individual messages and queues allow one-way delivery of messages, but a second queue can be added to allow for duplexing.&lt;/p&gt;  &lt;p&gt;Messages can sit in the queue either until a receiver grabs them or until they expire. Messages that expire are placed in a special “dead letters” queue. &lt;/p&gt;  &lt;p&gt;Windows Vista introduced an upgrade to MSMQ called the “poison queue.” If a receiver attempts to process a message but can’t due to error, and it’s retry count is reached, it is placed into the poison queue. Previous to Vista the developer had to create a mechanism to identify these messages and “handle” them or risk attempting to process the same message over and over again until human intervention stopped it.&lt;/p&gt;  &lt;p&gt;Queues can be transactional, meaning that if any part of a message fails, the entire message is rolled back. If the retry count has not been reached the receiver will attempt to process the message again until the count is reached and the message is moved to the poison queue.&lt;/p&gt;  &lt;p&gt;The rest of this post assumes you have MSMQ installed on your computer and have a private transactional queue called HelloMSMQ. Instructions on how to add MSMQ and create a private queue can be found &lt;a href="http://technet.microsoft.com/en-us/library/bb684791.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;h1&gt;Using the MSMQ Binding&lt;/h1&gt;  &lt;p&gt;OK, so now that we’ve got our private transactional queue created, the next steps are to create a message sender and message receiver. Using the netMSMQBinding binding will make this simple.&lt;/p&gt;  &lt;p&gt;Note: There are two MSMQ bindings: the netMSMQBinding, which we will use, and the MSMQIntegratedBinding. The integrated binding is designed for using MSMQ to send/receive messages from legacy mainframe systems with MSMQ. For working with WCF to WCF communication use the “net” binding. Of course, you can expose multiple endpoints on your server, and making one endpoint “integrated” and the other “net” is an option if you need to proved services to both types of clients.&lt;/p&gt;  &lt;p&gt;Since MSMQ by nature allows communication one way through a queue, you will need to make sure your service operation supports one-way calls. This is easily done by setting the IsOneWay property of the OperationContract to true:&lt;/p&gt;  &lt;div style="border-bottom: black 1px solid; border-left: black 1px solid; width: 100%; overflow: scroll; border-top: black 1px solid; border-right: black 1px solid"&gt;   &lt;div style="background-color: #e2ecf6"&gt;[ServiceContract]      &lt;br /&gt;&lt;/div&gt;    &lt;div style="background-color: #ffffff"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;interface&lt;/span&gt; IMyService       &lt;br /&gt;&lt;/div&gt;    &lt;div style="background-color: #e2ecf6"&gt;    {      &lt;br /&gt;&lt;/div&gt;    &lt;div style="background-color: #ffffff"&gt;        [OperationContract(IsOneWay=&lt;span style="color: blue"&gt;true&lt;/span&gt;)]       &lt;br /&gt;&lt;/div&gt;    &lt;div style="background-color: #e2ecf6"&gt;        &lt;span style="color: blue"&gt;void&lt;/span&gt; SayHello(&lt;span style="color: blue"&gt;string&lt;/span&gt; name);       &lt;br /&gt;&lt;/div&gt;    &lt;div style="background-color: #ffffff"&gt;    }&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The next step is to create your endpoint. Here is the configuration for the endpoint that this services is exposed on:&lt;/p&gt;  &lt;p&gt;&amp;lt;endpoint address="net.msmq://localhost/private/HelloMsmq"    &lt;br /&gt;                   binding="netMsmqBinding"     &lt;br /&gt;                   bindingConfiguration="DomainlessMsmqBinding"     &lt;br /&gt;                   contract="HelloMsmq.IMyService"/&amp;gt;   &lt;/p&gt;  &lt;p&gt;Like all endpoints, this one includes the “ABC’s” of address, binding and contract. Contract here is pretty much what you would expect. The address points to a queue residing on a server somewhere, in this case the local machine. This address specifically points to the private “HelloMsmq” queue on our local machine. The binding is the netMSMQBinding. The binding configuration specifies that we aren’t going to worry about security for messages in this queue:&lt;/p&gt;  &lt;p&gt;&amp;lt;bindings&amp;gt;    &lt;br /&gt;      &amp;lt;netMsmqBinding&amp;gt;     &lt;br /&gt;        &amp;lt;binding name="DomainlessMsmqBinding" &amp;gt;     &lt;br /&gt;          &amp;lt;security&amp;gt;     &lt;br /&gt;            &amp;lt;transport     &lt;br /&gt;              msmqAuthenticationMode="None"     &lt;br /&gt;              msmqProtectionLevel="None"/&amp;gt;     &lt;br /&gt;          &amp;lt;/security&amp;gt;     &lt;br /&gt;        &amp;lt;/binding&amp;gt;     &lt;br /&gt;      &amp;lt;/netMsmqBinding&amp;gt;     &lt;br /&gt;    &amp;lt;/bindings&amp;gt;&lt;/p&gt;  &lt;p&gt;SVCUTIL creates a proxy that works just like any other WCF proxy; the address points at the same private queue and it uses the netMSMQBinding. From that point on you use it like you would any other WCF service&lt;/p&gt;  &lt;h1&gt;Where Would You Use This?&lt;/h1&gt;  &lt;p&gt;The inherit abilities of this binding provides a lot of benefits that can be used in many common situations. Since the service does not have to be online while clients send messages, the binding works very well in batch processing situations; clients can add messages to the queue all day, with the service being turned on at night to process the messages in a batch.&lt;/p&gt;  &lt;p&gt;If you have a portion of your workforce that travels or needs to work disconnected at periods of time, MSMQ provides a way for them to work offline, with the queues syncing when the client reconnects to the network.&lt;/p&gt;  &lt;p&gt;MSMQ is also an inherently reliable binding. Since messages are stored in a queue they can be “re-played” by the service if any sort of connectivity issues exist. If the message can be written to the queue it’s guaranteed that it will be delivered, at some point, to the service.&lt;/p&gt;  &lt;p&gt;I hope this has piqued your interest in a very unappreciated and underused binding. MSMQ provides a robust and easy to use method to deliver messages to your service in a variety of enterprise scenarios. Most posts on how to utilize this binding will be coming soon…&lt;/p&gt;  &lt;p&gt;Code on!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://jamescbender.com/bendersblog/archive/2009/04/04/the-one-where-i-talk-about-the-msmq-binding.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/04/04/the-one-where-i-talk-about-the-msmq-binding.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/42.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/04/04/the-one-where-i-talk-about-the-msmq-binding.aspx</guid>
            <pubDate>Sat, 04 Apr 2009 04:22:58 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/42.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/04/04/the-one-where-i-talk-about-the-msmq-binding.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/42.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Speaking Tomorrow at MOCSDG !</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/04/01/speaking-tomorrow-at-mocsdg.aspx</link>
            <description>&lt;p&gt;So, you’ve probably heard about Microsoft Azure by now, and how awesome it is. But there’s more to developing for Microsoft's Cloud Provider than web and worker roles.&lt;/p&gt;  &lt;p&gt;I will be presenting a lap around Microsoft .NET Services, which provides some great infrastructure features that can make your Azure application development easier. &lt;/p&gt;  &lt;p&gt;What? You’re not into the whole “cloud thing?”&lt;/p&gt;  &lt;p&gt;Well then your in luck! Because with .NET Services you can still take advantage of these great features without having to build an “Azure application!”&lt;/p&gt;  &lt;p&gt;What now? Oh, you’re not a “.NET developer?”&lt;/p&gt;  &lt;p&gt;That’s cool, because .NET Services has SDK’s for Java AND Ruby! And they are available RIGHT NOW!&lt;/p&gt;  &lt;p&gt;OK, since you have no more excuses, I’ll see you all at the Microsoft office at 6:00 tomorrow night! &lt;/p&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/41.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/04/01/speaking-tomorrow-at-mocsdg.aspx</guid>
            <pubDate>Wed, 01 Apr 2009 19:01:19 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/41.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/04/01/speaking-tomorrow-at-mocsdg.aspx#feedback</comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/41.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Thoughts on the WCF REST Starter Kit</title>
            <link>http://jamescbender.com/bendersblog/archive/2008/12/22/thoughts-on-the-wcf-rest-starter-kit.aspx</link>
            <description>&lt;p&gt;One of the announcements that was kinda missed at PDC was the release of the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/netframework/cc950529.aspx"&gt;WCF REST Starter Kit&lt;/a&gt;. In brief, the REST Starter Kit provides a was for developers to “jump-start” the development of REST services in WCF. &lt;/p&gt;
&lt;h2&gt;The Premise&lt;/h2&gt;
&lt;p&gt;In .NET  3.0 WCF allowed developers to abstract the way a service communicates with the world from the way the functionality of the service was implemented. Developers designing services in a “contract first” manner were able to specify minimum requirement and rules for their services. Provided that the communication medium (transport and binding) was able to provide the service with the facilities that it needed, that service could be invoked via that medium. For example, a service could expose both HTTP based and TCP based endpoints without having to change the functionality of the service. In WCF there is not a concept of a “web service”: there are just services. Some are available via HTTP over the web.&lt;/p&gt;
&lt;p&gt;WCF also provided developers with ways to customize and extend the way the service communicated and behaved at runtime via custom channels and custom behaviors.&lt;/p&gt;
&lt;p&gt;What it didn’t do very well was provide a way for developers to easily create REST based services. But that changed with the release of .NET 3.5. Using the WebGet and WebInvoke attributes in the Service Contract gave developers a way to write REST services in WCF&lt;/p&gt;
&lt;h2&gt;The Problem&lt;/h2&gt;
&lt;p&gt;For all it’s power, configurability and extensibility WCF has always had a bit of an image problem. Most developers view it as difficult to work with, difficult to understand and tied to a obnoxiously verbose configuration model. The inclusion of REST abilities in 3.5 did nothing to help do away with this perception.&lt;/p&gt;
&lt;h2&gt;The Solution&lt;/h2&gt;
&lt;p&gt;Enter the WCF REST Starter Kit. The Starter Kit provides a set of templates for creating a variety of REST-based services including Singleton Services (exposing a single resource on the server), Collection Service (exposing a list of resources/data), POX Service and projects for ATOM feeds and ATOM publishing protocols. The starter kit also comes with a new assembly called Microsoft.ServiceModel.Web which contains an API the provides a lot of out-of-the box functionality to support REST services including customized help pages, customized caching, easier ways to return exceptions, URI templates, and the ability to use request and response headers.&lt;/p&gt;
&lt;p&gt;The long and the short of it is that you select a project template based on what kind of service you want to write and then add the appropriate functionality to a few methods and bang, you’ve got a service. &lt;/p&gt;
&lt;h2&gt;The Good&lt;/h2&gt;
&lt;p&gt;The starter kit comes with templates for most kind of REST based services you will need to write. While a basic knowledge of REST and how routing works (if you’ve done any significant MVC work you’ll be fine) you can get a REST based service up and running in a matter of minutes with data represented as both XML and JSON. Little real WCF knowledge is required to simply get a service up and running. &lt;/p&gt;
&lt;p&gt;The API extensions will offer something to those more experienced with WCF by providing a means to perform some customization without having to write a custom behavior or channel. &lt;/p&gt;
&lt;h2&gt;The Bad&lt;/h2&gt;
&lt;p&gt;It started with the install. Part of the starter kit is a bunch of Visual Studio content. The installer kept giving me a Null Reference Exception. I found a workaround &lt;a href="http://madridcentral.com/blogs/chris/archive/2008/10/30/wcf-rest-starter-kit-preview-1.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The classes created by the starter kit are designed for ease of implementation, not for extensibility. Customization involves a lot of friction. If you need to do anything beyond a basic REST implementation you will need to acquaint yourself with the object model that the starter kit uses, which can be a little overly complex. If you need to do complex routing or create a service to provide more than one data type you’ll need a level of knowledge about REST in WCF that the start kit is supposed to insulate you from.&lt;/p&gt;
&lt;p&gt;Another issue I’ve encountered is that when I try to rename the Service.svc file in the project generated by the Starter Kit I get an “… operation not completed. Unspecified error.” error.&lt;/p&gt;
&lt;h2&gt;In the End&lt;/h2&gt;
&lt;p&gt;I’m in favor of a REST Starter Kit, or ANYTHING for that matter that increases adoption of WCF. I think the Starter Kit is a good late-beta/1.0 release, but it’s got a ways to got before I consider it a major part of my tool-box.&lt;/p&gt;
&lt;p&gt;Code On!&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fjamescbender.com%2fbendersblog%2farchive%2f2008%2f12%2f22%2fthoughts-on-the-wcf-rest-starter-kit.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fjamescbender.com%2fbendersblog%2farchive%2f2008%2f12%2f22%2fthoughts-on-the-wcf-rest-starter-kit.aspx" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/37.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2008/12/22/thoughts-on-the-wcf-rest-starter-kit.aspx</guid>
            <pubDate>Tue, 23 Dec 2008 01:53:13 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/37.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2008/12/22/thoughts-on-the-wcf-rest-starter-kit.aspx#feedback</comments>
            <slash:comments>11</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/37.aspx</wfw:commentRss>
        </item>
        <item>
            <title>.NET University Recap</title>
            <link>http://jamescbender.com/bendersblog/archive/2008/11/12/.net-university-recap.aspx</link>
            <description>&lt;p&gt;I want to thank everybody who attended .NET university this past weekend in Columbus. It was the first event (that I know of at least) of it’s kind and it was great to meet a lot of new people who don’t normally participate in the .NET community. I hope this that you learned something useful and continue your exploration or .NET and the rich set of technologies that surround it.&lt;/p&gt;  &lt;p&gt;For those of you who asked, my web services slide deck can be downloaded &lt;a href="http://jamescbender.com/bendersblog/images/blog/gettingstartedwithwcfdotnetuniversity.pptx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Hope to see you all at the next event!&lt;/p&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/35.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2008/11/12/.net-university-recap.aspx</guid>
            <pubDate>Wed, 12 Nov 2008 15:33:34 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/35.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2008/11/12/.net-university-recap.aspx#feedback</comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/35.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>