<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>.NET</title>
        <link>http://jamescbender.com/bendersblog/category/4.aspx</link>
        <description>.NET</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>Dogfood II is Done!</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/11/16/dogfood-ii-is-done.aspx</link>
            <description>&lt;p&gt;Thanks to all who came to my talk on F# at the Dogfood conference last week. I had a great time presenting it and hope all who attended enjoyed it as well. The slide deck and demo are attached. If anybody has any questions about it, please feel free to &lt;a href="mailto:james@jamescbender.com"&gt;contact me&lt;/a&gt;.&lt;/p&gt; &lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-de4aebf19948423f.skydrive.live.com/embedicon.aspx/Public/DogFoodII/DogFood.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;This was my first Dogfood conference, and it was unlike any other event I’ve been to. I was able to meet a lot of people who don’t normally come to developer events or user group meetings.&lt;/p&gt;  &lt;p&gt;On a related note, &lt;a href="http://www.sophicgroup.net/Home.aspx"&gt;The Sophic Group&lt;/a&gt; will be holding an F# boot camp on December 14-15 at OCLC in Dublin OH. The cost is $1900 and includes two days of instruction, all class materials and a half-day of on-site (meaning your office) continuing F# education and assessment. If this sounds interesting, please &lt;a href="mailto:james@jamescbender.com"&gt;contact me&lt;/a&gt; for details.&lt;/p&gt;  &lt;p&gt;Next stop, PDC in Los Angeles. See you there!&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/11/16/dogfood-ii-is-done.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/11/16/dogfood-ii-is-done.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/59.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/11/16/dogfood-ii-is-done.aspx</guid>
            <pubDate>Mon, 16 Nov 2009 15:46:15 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/59.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/11/16/dogfood-ii-is-done.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/59.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>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>If I Do A Good Job, Can We Go To Dietsch Brothers for Ice Cream After The Meeting?</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/04/26/if-i-do-a-good-job-can-we-go-to.aspx</link>
            <description>&lt;p&gt;This Tuesday, April 28th, I’ll be speaking at the &lt;a href="http://fanug.org/default.aspx"&gt;Findlay Area .NET User Group&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I’ll be presenting “How I Learned To Love Dependency Injection,” which if my .NET Kicks stats are to be believed, is turning out to be quite the popular talk.  The meeting is at the Marathon Oil building in downtown Findlay. &lt;/p&gt;  &lt;p&gt;I spoke at this group a couple of years ago and had a GREAT time. I’m excited to be going back! &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/26/if-i-do-a-good-job-can-we-go-to.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://jamescbender.com/bendersblog/archive/2009/04/26/if-i-do-a-good-job-can-we-go-to.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/49.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/04/26/if-i-do-a-good-job-can-we-go-to.aspx</guid>
            <pubDate>Sun, 26 Apr 2009 23:28:20 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/49.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/04/26/if-i-do-a-good-job-can-we-go-to.aspx#feedback</comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/49.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How I Learned to Love Dependency Injection: The Slides</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/04/19/how-i-learned-to-love-dependency-inject-the-slides.aspx</link>
            <description>Thanks to everyone who attended the Central Ohio Day of .NET yesterday and made it such a success. A special thanks to all the organizers as well.&lt;br /&gt;
&lt;br /&gt;
I had a great time seeing some old friends a making some new ones. I hope to see you all at events down the road.&lt;br /&gt;
&lt;br /&gt;
I hope those who attended my session on DI enjoyed it and found it useful. As promised, I'm posting my slides.&lt;br /&gt;
&lt;br /&gt;
Right now I'm using a borrowed laptop, so I don't have access to the sample code, but I'll be putting that up as soon as possible.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe style="BORDER-RIGHT: rgb(221,229,233) 1px solid; PADDING-RIGHT: 0pt; BORDER-TOP: rgb(221,229,233) 1px solid; PADDING-LEFT: 0pt; PADDING-BOTTOM: 0pt; MARGIN: 3px; BORDER-LEFT: rgb(221,229,233) 1px solid; WIDTH: 240px; PADDING-TOP: 0pt; BORDER-BOTTOM: rgb(221,229,233) 1px solid; HEIGHT: 26px; BACKGROUND-COLOR: rgb(255,255,255)" marginwidth="0" marginheight="0" src="http://cid-de4aebf19948423f.skydrive.live.com/embedrow.aspx/Public/Presentation%20Slides/Central%20Ohio%20Day%20of%20dotNet%202009/How%20I%20learned%20to%20love%20Dependency%20Injection.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
See you all at the next event! &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fjamescbender.com%2fbendersblog%2farchive%2f2009%2f04%2f19%2fhow-i-learned-to-love-dependency-inject-the-slides.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fjamescbender.com%2fbendersblog%2farchive%2f2009%2f04%2f19%2fhow-i-learned-to-love-dependency-inject-the-slides.aspx&amp;amp;bgcolor=003399" /&gt;&lt;/a&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/46.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/04/19/how-i-learned-to-love-dependency-inject-the-slides.aspx</guid>
            <pubDate>Sun, 19 Apr 2009 18:46:27 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/46.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/04/19/how-i-learned-to-love-dependency-inject-the-slides.aspx#feedback</comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/46.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>And now, a little something for the .NET newbies&amp;hellip;..</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/03/31/and-now-a-little-something-for-the-.net-newbieshellip.aspx</link>
            <description>&lt;p&gt;Do you live within a car ride of Grand Rapids?&lt;/p&gt;  &lt;p&gt;Have you always wanted to learn about .NET but didn’t know how or where to start?&lt;/p&gt;  &lt;p&gt;Does the idea of learning some really cool stuff that you can use to shock and amaze your friends sound cool?&lt;/p&gt;  &lt;p&gt;Well then have I got good news for you!&lt;/p&gt;  &lt;p&gt;My buddy &lt;a href="http://cloudsocket.com/graffiti/"&gt;Chris Woodruff&lt;/a&gt; has organized the &lt;a href="http://dodn.org/WestMichiganDotNetU/Default.aspx"&gt;West Michigan .NET University&lt;/a&gt;, which takes place this Saturday in Grand Rapids. You’ll get the chance to learn .NET from some really smart people like &lt;a href="http://codingbandit.com/blog/"&gt;Carey Payette&lt;/a&gt; , &lt;a href="http://frazzleddad.blogspot.com/"&gt;Jim Holmes&lt;/a&gt;, &lt;a href="www.japikse.blogspot.com"&gt;Phil Japikse&lt;/a&gt;, &lt;a href="http://www.rickdoes.net/"&gt;Rick Kierner&lt;/a&gt; and &lt;a href="http://www.davidgiard.com/"&gt;David Giard&lt;/a&gt;. I’ll also be there co-presenting a .NET Bootcamp with &lt;a href="http://geekswithblogs.net/ignu/Default.aspx"&gt;Len Smith&lt;/a&gt; and presenting a session on Web Services and WCF.&lt;/p&gt;  &lt;p&gt;Registration is open, see you all there!&lt;/p&gt; &lt;a href="http://www.dayofdotnet.org/WestMichiganDotNetU/"&gt;&lt;img alt="WM .Net University April 4, 2009 - I'll be there!" src="http://www.dayofdotnet.org/WestMichiganDotNetU/images/Site-Badge-I.gif" /&gt;&lt;/a&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/40.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/03/31/and-now-a-little-something-for-the-.net-newbieshellip.aspx</guid>
            <pubDate>Tue, 31 Mar 2009 13:37:30 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/40.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/03/31/and-now-a-little-something-for-the-.net-newbieshellip.aspx#feedback</comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/40.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Are YOU going to the Microsoft Developer Conference?</title>
            <link>http://jamescbender.com/bendersblog/archive/2009/01/13/are-you-going-to-the-microsoft-developer-conference.aspx</link>
            <description>&lt;p&gt;And if not, why not?&lt;/p&gt;
&lt;p&gt;The &lt;a target="_blank" href="http://www.msdndevcon.com/Pages/start.aspx"&gt;MDC&lt;/a&gt; (Microsoft Developer Conference) makes a stop in scenic Detroit, MI next Thursday, January 22nd. If you missed the &lt;a target="_blank" href="http://www.microsoftpdc.com/"&gt;PDC&lt;/a&gt;, or even if you didn’t this is a great event and a terrific opportunity to see what’s next in the .NET development stack. &lt;/p&gt;
&lt;p&gt;In addition to getting your very own copy of the &lt;a target="_blank" href="http://www.microsoft.com/windows/windows-7/default.aspx"&gt;Windows 7&lt;/a&gt; Beta (assuming your one of the last three people who haven’t already gotten the torrent) you’ll be able to see presentations on &lt;a target="_blank" href="http://www.microsoft.com/azure/default.mspx"&gt;Azure&lt;/a&gt;, &lt;a target="_blank" href="http://silverlight.net/Default.aspx"&gt;Silverlight&lt;/a&gt;, &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/fsharp/default.aspx"&gt;F#&lt;/a&gt;, ASP.NET with &lt;a target="_blank" href="http://jquery.com/"&gt;JQuery&lt;/a&gt; and SQL Data services by some great speakers like &lt;a target="_blank" href="http://www.brianhprince.com"&gt;Brian&lt;/a&gt;, &lt;a target="_blank" href="http://blogs.msdn.com/jennifer/"&gt;Jennifer&lt;/a&gt;, &lt;a target="_blank" href="http://jrwren.wrenfam.com/blog/"&gt;Jay&lt;/a&gt;, &lt;a target="_blank" href="http://www.jeffreyhunsaker.com/"&gt;Jeff&lt;/a&gt; and Jason, other &lt;a target="_blank" href="http://jeffblankenburg.com/default.aspx"&gt;Jeff&lt;/a&gt;, &lt;a target="_blank" href="http://codingbandit.com/"&gt;Carey&lt;/a&gt;, &lt;a target="_blank" href="http://cloudsocket.com/graffiti/"&gt;Chris&lt;/a&gt; and yet another &lt;a target="_blank" href="http://www.mcwherter.net/blog/"&gt;Jeff&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Damn, that’s a lot of Jeff’s.&lt;/p&gt;
&lt;p&gt;And at $99 bucks, that’s only $33/Jeff!&lt;/p&gt;
&lt;p&gt;But wait, there’s more!&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://netcave.org/"&gt;Alan&lt;/a&gt; will be there running &lt;strike&gt;Open Spaces&lt;/strike&gt; Community Courtyard, where you’ll be able submit your own topics and talk with some way-smart people.&lt;/p&gt;
&lt;p&gt;There will also be a Women Build workshop, which despite the name is open to both women and men. Admittedly I don’t know too much about that except that Lego’s are involved, Based on that I’m guessing it’s pretty cool!&lt;/p&gt;
&lt;p&gt;So if you haven’t, go &lt;a target="_blank" href="http://www.msdndevcon.com/Pages/Detroit.aspx"&gt;register&lt;/a&gt; now and I hope to see you all there!&lt;/p&gt;
&lt;p&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fjamescbender.com%2fbendersblog%2farchive%2f2009%2f01%2f13%2fare-you-going-to-the-microsoft-developer-conference.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fjamescbender.com%2fbendersblog%2farchive%2f2009%2f01%2f13%2fare-you-going-to-the-microsoft-developer-conference.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/38.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2009/01/13/are-you-going-to-the-microsoft-developer-conference.aspx</guid>
            <pubDate>Tue, 13 Jan 2009 16:44:55 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/38.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2009/01/13/are-you-going-to-the-microsoft-developer-conference.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/38.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>