<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The .NET Endpoint</title><link>http://blogs.msdn.com/b/endpoint/</link><description>Blog by the .NET and AppFabric teams about WCF and WF development, deployment, and management</description><dc:language>en-US</dc:language><generator>Telligent Community 5.6.583.14036 (Build: 5.6.583.14036)</generator><item><title>Goodbye .NET Endpoint, Hello AppFabric Team Blog</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/16/goodbye-net-endpoint-hello-appfabric-team-blog.aspx</link><pubDate>Mon, 16 May 2011 13:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10164871</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10164871</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/16/goodbye-net-endpoint-hello-appfabric-team-blog.aspx#comments</comments><description>&lt;p&gt;Over the last year you&amp;rsquo;ve heard us talking about both Windows Azure AppFabric and Windows Server AppFabric.&amp;nbsp; Today we are adding our final post to the .NET endpoint team blog and announcing the new &lt;a href="http://blogs.msdn.com/appfabric"&gt;AppFabric Team blog&lt;/a&gt;.&amp;nbsp; This blog will be the home of content about all things AppFabric from Service Bus to Caching to WCF and WF.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve been following us here on the .NET Endpoint please be sure to follow the &lt;a href="http://blogs.msdn.com/appfabric"&gt;AppFabric Team Blog&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;endpoint.tv becomes AppFabric.tv&lt;/h3&gt;
&lt;p&gt;As part of this change, endpoint.tv will now become &lt;a href="http://channel9.msdn.com/shows/AppFabric-TV"&gt;AppFabric.tv&lt;/a&gt;.&amp;nbsp; We will continue to bring you the best content about WF and WCF as well as the rest of the AppFabric world.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/4426.MS_5F00_AppFabricTV_2D00_Banner_2D00_220_5F00_46663A82.png"&gt;&lt;img height="164" width="224" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/2843.MS_5F00_AppFabricTV_2D00_Banner_2D00_220_5F00_thumb_5F00_77091C60.png" alt="MS_AppFabricTV-Banner-220" border="0" title="MS_AppFabricTV-Banner-220" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10164871" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item><item><title>Using DataContracts with WCF Web API</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/15/using-datacontracts-with-wcf-web-api.aspx</link><pubDate>Sun, 15 May 2011 02:55:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10164563</guid><dc:creator>Glenn Block MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10164563</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/15/using-datacontracts-with-wcf-web-api.aspx#comments</comments><description>&lt;p&gt;A few folks have been &lt;a href="http://wcf.codeplex.com/discussions/248365"&gt;asking&lt;/a&gt; if it is possible to serialize/deserialize using the DataContractSerializer. Rest assured, yes it is possible. Now whether or not it is the easiest/most intuitive model well that it is a different question. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/7558.wlEmoticon_2D00_winkingsmile_5F00_2.png" /&gt;&lt;/p&gt;  &lt;p&gt;If you read to the end the post you will see a bunch of extensions which have been pushed to webapicontrib and make this all MUCH easier (at least I think). If you don’t jump you’ll read below what you need to do if you do it yourself.&lt;/p&gt;  &lt;p&gt;It stars with the SetSerializer&amp;lt;T&amp;gt; method which is expose on the XmlMediaTypeFormatter. You can call this method and pass a DataContractSerializer for T. That tells the formatter use this serializer not the default. You need to give it the exact information, for example if you are returning List&amp;lt;Contact&amp;gt; then make T List&amp;lt;Contact&amp;gt; NOT T. If you want to support both, you need to register both.&lt;/p&gt;  &lt;p&gt;To allow you to get to the formatter, the MediaTypeFormatterCollection exposes an XmlFormatter property. You might now be thinking, “Oh that’s easy, but how do I get a hold of the formatter collection?”&lt;/p&gt;  &lt;p&gt;Good question. It depends on whether you are on the server or on the client.&lt;/p&gt;  &lt;h1&gt;On the Server&lt;/h1&gt;  &lt;p&gt;The easiest way to configure things on the server is to annotate your service/resource with a [DataContractFormat] attribute. Once you do then we will automatically use the DataContractSerializer. &lt;/p&gt;  &lt;p&gt;If you do not want to annotate your service, the alternative option is to do it in code. If you are using HttpHostConfiguration you can get to the formatters by accessing the OperationHandlerFactory property on the config class. If you are using the fluent API, you’ll want to cast to HttpHostConfiguration in order to access it. For example see the code below&lt;/p&gt;  &lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var config = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpHostConfiguration();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var formatter = OperationHandlerFactory.XmlFormatter;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;formatter.SetSerializer&amp;lt;Contact&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Contact)));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;formatter.SetSerializer&amp;lt;List&amp;lt;Contact&amp;gt;&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(List&amp;lt;Contact&amp;gt;)));&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The code above is setting the formatter to use the DCS for Contact and List&amp;lt;Contact&amp;gt; both for reading and writing.&lt;/p&gt;

&lt;h1&gt;On the client&lt;/h1&gt;

&lt;p&gt;On the client side how you configure depends on if you are reading or writing. In either case both steps involve calling SetSerializer&amp;lt;T&amp;gt; on the XmlMediaTypeFormatter. &lt;/p&gt;

&lt;p&gt;For reading you will create the formatter and pass it to the ReadAs&amp;lt;T&amp;gt; method of the HttpContent which is accessed off of the Content property on HttpResponseMessage.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var formatter = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlMediaTypeFormatter();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;formatter.SetSerializer&amp;lt;List&amp;lt;Contact&amp;gt;&amp;gt;&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(List&amp;lt;Contact&amp;gt;))));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var contact = response.Content.ReadAs&amp;lt;T&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;MediaTypeFormatter&amp;gt; { formatter });
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;If you are writing to the request, you will access the formatters collection on the ObjectContent&amp;lt;T&amp;gt; instance.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var content = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObjectContent&amp;lt;Contact&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;content.Formatters.SetSerializer&amp;lt;Contact&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Contact)));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;client.Post(content);&lt;/pre&gt;&lt;/pre&gt;

&lt;h1&gt;&lt;/h1&gt;

&lt;h1&gt;New extension methods in webapicontrib to make life easier&lt;/h1&gt;

&lt;p&gt;Now that we’ve seen how you can do it, we can wrap this up in a bunch of helper extension methods and life gets a whole lot easier. I did that and &lt;a href="http://webapicontrib.codeplex.com/SourceControl/changeset/view/2da8381982b9#source%2fFormatters%2fDataContractExtensions.cs"&gt;pushed&lt;/a&gt; them to webapicontrib &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/7558.wlEmoticon_2D00_winkingsmile_5F00_2.png" /&gt;&lt;/p&gt;

&lt;p&gt;Check the code below from the new DataContractExample in webapicontrib.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var config = HttpHostConfiguration.Create();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;font style="background-color: #ffff00"&gt;config.UseDataContractSerializer&amp;lt;Contact&amp;gt;();&lt;/font&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var host = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpConfigurableServiceHost&amp;lt;ContactsResource&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  config, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Uri(&amp;quot;&lt;span style="color: #8b0000"&gt;http://localhost:8080/&lt;/span&gt;&amp;quot;));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;host.Open();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var client = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpClient(&amp;quot;&lt;span style="color: #8b0000"&gt;http://localhost:8080/&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var newContact = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Contact {FirstName = &amp;quot;&lt;span style="color: #8b0000"&gt;Brad&lt;/span&gt;&amp;quot;, LastName = &amp;quot;&lt;span style="color: #8b0000"&gt;Abrams&lt;/span&gt;&amp;quot;};
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var content = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObjectContent&amp;lt;Contact&amp;gt;(newContact,
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &amp;quot;&lt;span style="color: #8b0000"&gt;application/xml&lt;/span&gt;&amp;quot;).&lt;font style="background-color: #ffff00"&gt;UseDataContractSerializer();&lt;/font&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var response = client.Post(&amp;quot;&lt;span style="color: #8b0000"&gt;contacts&lt;/span&gt;&amp;quot;, content);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;response = client.Get(&amp;quot;&lt;span style="color: #8b0000"&gt;contacts&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;var contacts = response.Content.&lt;font style="background-color: #ffff00"&gt;ReadAsDataContract&amp;lt;Contact[]&amp;gt;();&lt;/font&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var contact &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; contacts)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  Console.WriteLine(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &amp;quot;&lt;span style="color: #8b0000"&gt;Contact: FirstName={0}, LastName={1}&lt;/span&gt;&amp;quot;, 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    contact.FirstName, contact.LastName));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;Console.ReadLine();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;I’ve highlighted the important parts&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;UseDataContractSerializer&amp;lt;T&amp;gt; on the config will set the formatter to serialize T using DCS. In order to make life easier the extension method also registers for List&amp;lt;T&amp;gt; and T[]. &lt;/li&gt;

  &lt;li&gt;For reading on the client call the ReadAsDataContract&amp;lt;T&amp;gt; extension method on HttpContent. &lt;/li&gt;

  &lt;li&gt;For writing on the client create an ObjectContent&amp;lt;T&amp;gt; instance and call the UseDataContractSerializer() extension metho &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Download the bits in wcfwebapi contrib &lt;a href="http://webapicontrib.codeplex.com/SourceControl/list/changesets#"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10164563" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF+WebHttp+Services/">WCF WebHttp Services</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF+Web+APIs/">WCF Web APIs</category></item><item><title>How to eliminate tempuri.org from your service WSDL</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/12/how-to-eliminate-tempuri-org-from-your-service-wsdl.aspx</link><pubDate>Thu, 12 May 2011 19:34:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10163953</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10163953</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/12/how-to-eliminate-tempuri-org-from-your-service-wsdl.aspx#comments</comments><description>&lt;p&gt;tempuri.org is the default namespace applied to WCF Services and Workflow Services.&amp;#160; You can and should specify your service namespace.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;It is recommended that you explicitly specify a name and namespace for the service contract, and an action for each operation to avoid using &amp;quot;&lt;/em&gt;&lt;a href="http://tempuri.org&amp;quot;"&gt;&lt;em&gt;http://tempuri.org&amp;quot;&lt;/em&gt;&lt;/a&gt;&lt;em&gt; and to prevent interface and method names from being exposed in the service’s contract        &lt;br /&gt;&lt;/em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms731060.aspx"&gt;MSDN Library - Service Contract Versioning&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h1&gt;Where is tempuri.org in the WSDL?&lt;/h1&gt;  &lt;p&gt;If you browse the service WSDL you will see tempuri.org all over the place.&amp;#160; Here is a default WCF service WSDL.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:definitions&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Service1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;targetNamespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://tempuri.org/&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsdl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:soap&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:soapenc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/soap/encoding/&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsu&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:xsd&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:soap12&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap12/&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:tns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://tempuri.org/&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsa&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsp&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/ws/2004/09/policy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsap&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/ws/2004/08/addressing/policy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsaw&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://www.w3.org/2006/05/addressing/wsdl&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:msc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/ws/2005/12/wsdl/contract&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsa10&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://www.w3.org/2005/08/addressing&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsx&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/ws/2004/09/mex&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:wsam&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://www.w3.org/2007/05/addressing/metadata&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:types&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;xsd:schema&lt;/span&gt; &lt;span style="color: #ff0000"&gt;targetNamespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://tempuri.org/Imports&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;xsd:import&lt;/span&gt; &lt;span style="color: #ff0000"&gt;schemaLocation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://localhost:63720/Service1.svc?xsd=xsd0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;namespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://tempuri.org/&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;xsd:schema&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:types&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:message&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;IService1_DoWork_InputMessage&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:part&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;parameters&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;element&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;tns:DoWork&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:message&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:message&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;IService1_DoWork_OutputMessage&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:part&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;parameters&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;element&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;tns:DoWorkResponse&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:message&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:portType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;IService1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:operation&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DoWork&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:input&lt;/span&gt; &lt;span style="color: #ff0000"&gt;wsaw:Action&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://tempuri.org/IService1/DoWork&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;message&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;tns:IService1_DoWork_InputMessage&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:output&lt;/span&gt; &lt;span style="color: #ff0000"&gt;wsaw:Action&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://tempuri.org/IService1/DoWorkResponse&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;message&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;tns:IService1_DoWork_OutputMessage&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:operation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:portType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:binding&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;BasicHttpBinding_IService1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;tns:IService1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;soap:binding&lt;/span&gt; &lt;span style="color: #ff0000"&gt;transport&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:operation&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DoWork&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;soap:operation&lt;/span&gt; &lt;span style="color: #ff0000"&gt;soapAction&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://tempuri.org/IService1/DoWork&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;document&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:input&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;soap:body&lt;/span&gt; &lt;span style="color: #ff0000"&gt;use&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;literal&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:input&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:output&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;soap:body&lt;/span&gt; &lt;span style="color: #ff0000"&gt;use&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;literal&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:output&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:operation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:binding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:service&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Service1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:port&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;BasicHttpBinding_IService1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;binding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;tns:BasicHttpBinding_IService1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;soap:address&lt;/span&gt; &lt;span style="color: #ff0000"&gt;location&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://localhost:63720/Service1.svc&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:port&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wsdl:definitions&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Tip: Use a constant to ensure consistency&lt;/h1&gt;

&lt;p&gt;I like to use a constant to provide a consistent namespace across my services&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Constants&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #008000"&gt;// Ensures consistency in the namespace declarations across services&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Namespace = &lt;span style="color: #006080"&gt;&amp;quot;http://contoso.com/services/&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;How to eliminate tempuri.org from WCF Services WSDL&lt;/h1&gt;

&lt;h3&gt;Step 1: Declare a namespace on your service contract&lt;/h3&gt;

&lt;p&gt;The namespace can be anything.&amp;#160; People typically use a URI of some form but it does not have to point to an actual web page.&amp;#160; Often people will use a version identifier in the namsepace but there are no rules about what you should do.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;// Eliminate tempuri.org from the contract&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;// If you don't want to us a constant, put the URI here&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;// [ServiceContract(Namespace = &amp;quot;http://contoso.com/services&amp;quot;)]&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;[ServiceContract(Namespace = Constants.Namespace)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IService1&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    [OperationContract]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DoWork();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Step 2: Declare a namespace on your service&lt;/h3&gt;

&lt;p&gt;The service namespace is added with a ServiceBehavior attribute.&amp;#160; Using the constant ensures that the namespace is the same for the contract and the service.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;// If you don't want to us a constant, put the URI here&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;// [ServiceBehavior(Namespace = &amp;quot;http://contoso.com/services&amp;quot;)]&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;[ServiceBehavior(Namespace = Constants.Namespace)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Service1 : IService1&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DoWork()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Step 3: Set the binding namespace&lt;/h3&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;services&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;service&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;EliminateTempUri.Service1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #008000"&gt;&amp;lt;!-- Use a bindingNamespace to eliminate tempuri.org --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;endpoint&lt;/span&gt; &lt;span style="color: #ff0000"&gt;address&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;                  &lt;span style="color: #ff0000"&gt;binding&lt;/span&gt; &lt;span style="color: #0000ff"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;                  &lt;span style="color: #ff0000"&gt;bindingNamespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://contoso.com/services&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;                  &lt;span style="color: #ff0000"&gt;contract&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;EliminateTempUri.IService1&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;services&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;serviceBehaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;behavior&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;          &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;serviceMetadata&lt;/span&gt; &lt;span style="color: #ff0000"&gt;httpGetEnabled&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;          &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;serviceDebug&lt;/span&gt; &lt;span style="color: #ff0000"&gt;includeExceptionDetailInFaults&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;behavior&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;serviceBehaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;serviceHostingEnvironment&lt;/span&gt; &lt;span style="color: #ff0000"&gt;multipleSiteBindingsEnabled&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;&amp;#160;&lt;/h1&gt;

&lt;h1&gt;How to eliminate tempuri.org from Workflow Services WSDL&lt;/h1&gt;

&lt;p&gt;For workflow services the process is slightly different.&amp;#160; Workflow services do not have a contract (it is inferred from the activities) so here is the process.&lt;/p&gt;

&lt;h3&gt;Step 1: Declare a namespace on each receive activity&lt;/h3&gt;

&lt;p&gt;I wish it were possible to use a constant here but sadly it is not.&amp;#160; &lt;strong&gt;&lt;em&gt;For each receive activity&lt;/em&gt;&lt;/strong&gt; you must declare the namespace and contract name using a special syntax of &lt;strong&gt;{namespace}IContractName&lt;/strong&gt;.&amp;#160; In this example I’ve set the &lt;strong&gt;ServiceContractName&lt;/strong&gt; property to &lt;strong&gt;{http://contoso.com/services}IService&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/4682.image_5F00_263690B6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/8311.image_5F00_thumb_5F00_6600773B.png" width="525" height="406" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Step 2: Declare a namespace for the Workflow Service&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Open the Workflow Service and click in the designer outside of an activity.&amp;#160; This will allow you to set the properties of the service itself.&amp;#160; &lt;/li&gt;

  &lt;li&gt;Set the Name property to use the same namespace as you see below. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/0871.image_5F00_5EE13AC3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/6170.image_5F00_thumb_5F00_6CB380BE.png" width="525" height="156" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Step 3: Set the binding namespace&lt;/h3&gt;

&lt;p&gt;Many people do not declare a &amp;lt;service&amp;gt; tag for their Workflow Services but if you want to eliminate tempuri.org you will need to declare it.&lt;/p&gt;

&lt;p&gt;For a Workflow Service the A,B,Cs of WCF configuration are a little different.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Service Name – use the ConfigurationName property from the WorkflowService &lt;/li&gt;

  &lt;li&gt;A – Address – should be blank when hosted in IIS / AppFabric &lt;/li&gt;

  &lt;li&gt;B – Binding – use the binding of your choice.&amp;#160; Typically basicHttpBinding &lt;/li&gt;

  &lt;li&gt;C – Contract – use the interface name from the ServiceContractName property (without the namespace) &lt;/li&gt;
&lt;/ul&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;&amp;lt;!-- For Workflow Services name is the ConfigurationName property --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;service&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Service2&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #008000"&gt;&amp;lt;!-- contract must match the receive activity --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #008000"&gt;&amp;lt;!-- Use a bindingNamespace to eliminate tempuri.org --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;endpoint&lt;/span&gt; &lt;span style="color: #ff0000"&gt;address&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;            &lt;span style="color: #ff0000"&gt;binding&lt;/span&gt; &lt;span style="color: #0000ff"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;            &lt;span style="color: #ff0000"&gt;bindingNamespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://contoso.com/services&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;            &lt;span style="color: #ff0000"&gt;contract&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;IService&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Test It Out&lt;/h1&gt;

&lt;ol&gt;
  &lt;li&gt;Right click on your WCF or Workflow Service in Visual Studio and select View In Browser. &lt;/li&gt;

  &lt;li&gt;Click on the link to view the WSDL &lt;/li&gt;

  &lt;li&gt;Search in the browser for tempuri.org – there should be no matches &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/8814.image_5F00_65944446.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/1563.image_5F00_thumb_5F00_5E08D4D9.png" width="644" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;Ron Jacobs 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/rjacobs"&gt;http://blogs.msdn.com/rjacobs&lt;/a&gt; 

  &lt;br /&gt;Twitter: @ronljacobs &lt;a href="http://twitter.com/ronljacobs"&gt;http://twitter.com/ronljacobs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10163953" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF4/">WF4</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF4/">WCF4</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category></item><item><title>WCF Extensibility – Operation Selectors</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/10/wcf-extensibility-operation-selectors.aspx</link><pubDate>Tue, 10 May 2011 16:48:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10163023</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10163023</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/10/wcf-extensibility-operation-selectors.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;&lt;em&gt;index page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;We’re now entering the realm of the less used extensibility points for the WCF runtime. Operation selectors could well be left as an internal implementation detail for WCF, but for some reason the designers decided to make them public (I think the guideline back then was if anyone can come up with a scenario where a user would use it, then WCF would expose a hook for that). The server selector (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchoperationselector.aspx"&gt;IDispatchOperationSelector&lt;/a&gt;) is actually interesting to have as a public hook, as the whole UriTemplate model for REST services was built on top of it – basically, the selector knows about the HTTP method and URI templates for each service operation, and based on those properties of incoming messages it can call the appropriate operation. For “normal” (i.e., SOAP) endpoints, the operation selector implementation (which happens to be internal) is based on the addressing of the binding – in most of the cases it simply matches the Action header of the message with a map of action to the operation names.&lt;/p&gt;  &lt;p&gt;The client operation selector (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientoperationselector.aspx"&gt;IClientOperationSelector&lt;/a&gt;) is another story. The client selector receives the method invoked by the client (the &lt;a href="http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.aspx"&gt;System.Reflection.MethodBase&lt;/a&gt; object) and it must return an operation name which will be used by the WCF runtime to retrieve the actual client operation from the client runtime. I’ve tried for a while to think of any scenario where one would actually want to call one method in the proxy and have another operation be executed (besides some practical joke scenario where one would swap Add for Subtract in a calculator), but I just can’t think of any. Even searching on Bing or Google doesn’t show any real scenarios where a client selector is used. But well, WCF is extensible, so let’s let people choose their client operations as well &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/4431.wlEmoticon_2D00_smile_5F00_0C608874.png" /&gt;.&lt;/p&gt;  &lt;h3&gt;Public implementations in WCF&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.webhttpdispatchoperationselector.aspx"&gt;WebHttpDispatchOperationSelector&lt;/a&gt; (server): The dispatch implementation where the UriTemplate magic happens for WCF REST endpoints. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There are no public implementations for &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientoperationselector.aspx"&gt;IClientOperationSelector&lt;/a&gt;, only an internal one which simply returns the operation name of the method being called.&lt;/p&gt;  &lt;h3&gt;Interface declaration&lt;/h3&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:45359482-7044-4731-87cc-a3be49e0cb5b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;interface&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IDispatchOperationSelector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; SelectOperation(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;ref&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Message&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; message);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;interface&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IClientOperationSelector&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;bool&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; AreParametersRequiredForSelection { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; SelectOperation(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;MethodBase&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; method, &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;object&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;[] parameters);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The dispatch operation selector is quite simple – on &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchoperationselector.selectoperation.aspx"&gt;SelectOperation&lt;/a&gt; you get the message, you return the operation name. In most cases the operation can be selected based on information on the message header (e.g., the Action header for SOAP endpoints) or the message properties (e.g., the HTTP request property attached to the message). There are scenarios, however, where the routing to the operation needs to be done based on the message contents, so the message is passed by reference – if it needs to be consumed by the operation selector, it can recreated it to hand it back to the WCF pipeline.&lt;/p&gt;  &lt;p&gt;On the client side the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientoperationselector.areparametersrequiredforselection.aspx"&gt;AreParametersRequiredForSelection&lt;/a&gt; is used to determine whether the response to &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientoperationselector.selectoperation.aspx"&gt;SelectOperation&lt;/a&gt; can be cached or not – if the parameters are not required, the WCF runtime will only call &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientoperationselector.selectoperation.aspx"&gt;SelectOperation&lt;/a&gt; once per method in the proxy, otherwise every time a proxy call is made the selector will be invoked again.&lt;/p&gt;  &lt;h3&gt;How to add operation selectors&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;At the server side&lt;/strong&gt;: the operation selector is a property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.dispatchruntime.aspx"&gt;DispatchRuntime&lt;/a&gt; object. It’s typically accessed via the endpoint dispatcher in a call to &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applydispatchbehavior.aspx"&gt;IEndpointBehavior.ApplyDispatchBehavior&lt;/a&gt;.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1b4cc170-2428-417a-a7e8-c372d02bbb98" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyEndpointBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        endpointDispatcher.DispatchRuntime.OperationSelector = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationSelector&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationSelector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IDispatchOperationSelector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; SelectOperation(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; action = message.Headers.Action;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; action.Substring(action.LastIndexOf(&lt;span style="color:#a31515"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;) + 1);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;At the client side: the operation selector is a property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.clientruntime.aspx"&gt;ClientRuntime&lt;/a&gt; object, and is typically accessed via the implementation of &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applyclientbehavior.aspx"&gt;IEndpointBehavior.ApplyClientBehavior&lt;/a&gt;.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bd12c499-9d72-426a-9ef7-31795b3e1d1d" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyEndpointBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        clientRuntime.OperationSelector = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientOperationSelector&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientOperationSelector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IClientOperationSelector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; AreParametersRequiredForSelection&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; SelectOperation(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt; method, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; method.Name;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Real world scenario: Support for X-HTTP-Method-Override in REST endpoints&lt;/h3&gt;  &lt;p&gt;This issue came from the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1dc19d08-71b0-4f4d-9d8a-698d7af877d8"&gt;forum&lt;/a&gt;. REST services we use HTTP verbs (methods) to determine the action to be applied to the resource. For example, a GET request to /Contacts/1 would return the contact with id 1, while DELETE /Contacts/1 would remove that same contact from the repository. This is a great – and simple – model, but there are some browsers, proxies, firewalls or even some web service platforms which don’t support the full set of verbs (rejecting anything other than GET and POST). In order to overcome this problem, some platforms (such as &lt;a href="http://msdn.microsoft.com/en-ca/library/system.web.mvc.htmlhelper.httpmethodoverride"&gt;ASP.NET MVC&lt;/a&gt; and &lt;a href="http://code.google.com/apis/gdata/docs/2.0/basics.html#UpdatingEntry"&gt;Google Data&lt;/a&gt;) started supporting a new HTTP header or field, called X-HTTP-Method-Override, which contain the actual method which should be used by the service to access the resource. The WCF REST API doesn’t support this override natively, but that doesn’t preclude us from using an extensibility point to enable it.&lt;/p&gt;  &lt;p&gt;Implementing the support for X-HTTP-Method-Override is nothing but a matter of replacing the operation selector (based on methods and URI templates) used by REST endpoints with our own, which is aware of this new header. When the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchoperationselector.selectoperation.aspx"&gt;IDispatchOperationSelector.SelectOperation&lt;/a&gt; method is called, we can check if the incoming request contained the override header, and if so, we can update the incoming message properties to let the original selector chose the appropriate operation.&lt;/p&gt;  &lt;p&gt;For this example I’ll reuse the contact manager service from the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx"&gt;message inspectors post&lt;/a&gt; – it contains the different operations which differ based on the HTTP verb of the incoming request, so it’s perfect for this issue. And before I start, the usual disclaimer – this is a sample for illustrating the topic of this post, this is not production-ready code. I tested it for a few contracts and it worked, but I cannot guarantee that it will work for all scenarios (please let me know if you find a bug or something missing). Also, for simplicity sake it doesn’t have a lot of error handling which a production-level code would. Also, the contact manager is all stored in memory, a “real” one would have a backing database or something more “persistent”.&lt;/p&gt;  &lt;p&gt;One small parenthesis: the link below for the code in this post contains the version shown here in C# and also a version in VB.NET which does the same thing; if you’re a VB developer, you can check the MSDN code samples out.&lt;/p&gt;  &lt;p&gt;The contracts and service implementation are exactly the same as the one from before (I removed the version for Text, as it didn’t add any value to this topic):&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3c983fcd-9aee-48f5-93cb-bf7554b42763" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;DataContract&lt;/span&gt;]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Id { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Name { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Email { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] Telephones { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IContactManager&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebInvoke&lt;/span&gt;(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Method = &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; AddContact(&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebInvoke&lt;/span&gt;(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Method = &lt;span style="color:#a31515"&gt;&amp;quot;PUT&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/{id}&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; UpdateContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id, &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebInvoke&lt;/span&gt;(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Method = &lt;span style="color:#a31515"&gt;&amp;quot;DELETE&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/{id}&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DeleteContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebGet&lt;/span&gt;(UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; GetAllContacts();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;WebGet&lt;/span&gt;(UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/{id}&amp;quot;&lt;/span&gt;, ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; GetContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ContactManagerService&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IContactManager&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; AllContacts = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; currentId = 0;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; syncRoot = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; AddContact(&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; contactId = &lt;span style="color:#2b91af"&gt;Interlocked&lt;/span&gt;.Increment(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; currentId);&lt;/li&gt; &lt;li&gt;        contact.Id = contactId.ToString(&lt;span style="color:#2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            AllContacts.Add(contact);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;WebOperationContext&lt;/span&gt;.Current.OutgoingResponse.StatusCode = &lt;span style="color:#2b91af"&gt;HttpStatusCode&lt;/span&gt;.Created;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; contact.Id;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; UpdateContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id, &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        contact.Id = id;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; index = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.FetchContact(id);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (index &amp;gt;= 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                AllContacts[index] = contact;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DeleteContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; index = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.FetchContact(id);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (index &amp;gt;= 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                AllContacts.RemoveAt(index);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; GetAllContacts()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; result;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            result = AllContacts.ToList();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; GetContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; result;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; index = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.FetchContact(id);&lt;/li&gt; &lt;li&gt;            result = index &amp;lt; 0 ? &lt;span style="color:#0000ff"&gt;null&lt;/span&gt; : AllContacts[index];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; FetchContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; result = -1;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; AllContacts.Count; i++)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (AllContacts[i].Id == id)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                result = i;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt; 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;WebOperationContext&lt;/span&gt;.Current.OutgoingResponse.StatusCode = &lt;span style="color:#2b91af"&gt;HttpStatusCode&lt;/span&gt;.NotFound;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now for the behavior used to set up the operation selector. The behavior wraps the original operation selector from the endpoint, so it needs to be added &lt;em&gt;after&lt;/em&gt; the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/a&gt; (which will add the first selector to the runtime) – see the discussion about wrapping internal objects at the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx"&gt;post about formatters&lt;/a&gt;).&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fe94dcf2-414b-4197-a8a2-1e95ebe5e3fd" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HttpOverrideBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;const&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; HttpMethodOverrideHeaderName = &lt;span style="color:#a31515"&gt;&amp;quot;X-HTTP-Method-Override&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;const&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; OriginalHttpMethodPropertyName = &lt;span style="color:#a31515"&gt;&amp;quot;OriginalHttpMethod&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        endpointDispatcher.DispatchRuntime.OperationSelector = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HttpOverrideOperationSelector&lt;/span&gt;(endpointDispatcher.DispatchRuntime.OperationSelector);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;And the selector itself. As I mentioned before, The first thing the selector will do is to try to fetch the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httprequestmessageproperty.aspx"&gt;HttpRequestMessageProperty&lt;/a&gt; from the message properties – if the message was received using HTTP, it will contain information about the HTTP verb and headers in the request. It will then try to find the X-HTTP-Method-Override header, and if it’s present, it will update the message property with the method override. For completeness sake, this selector also adds a new property to the message with the original HTTP verb from the request (if the service needs this information somehow). Finally, the selector delegates the selection to the original selector, which will then use that information to route the incoming request to the appropriate method.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4645797e-4cd2-484d-bf95-4eb3725ac5c3" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HttpOverrideOperationSelector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IDispatchOperationSelector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IDispatchOperationSelector&lt;/span&gt; originalSelector;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; HttpOverrideOperationSelector(&lt;span style="color:#2b91af"&gt;IDispatchOperationSelector&lt;/span&gt; originalSelector)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalSelector = originalSelector;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; SelectOperation(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (message.Properties.ContainsKey(&lt;span style="color:#2b91af"&gt;HttpRequestMessageProperty&lt;/span&gt;.Name))&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;HttpRequestMessageProperty&lt;/span&gt; reqProp;&lt;/li&gt; &lt;li&gt;            reqProp = (&lt;span style="color:#2b91af"&gt;HttpRequestMessageProperty&lt;/span&gt;)message.Properties[&lt;span style="color:#2b91af"&gt;HttpRequestMessageProperty&lt;/span&gt;.Name];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; httpMethodOverride = reqProp.Headers[&lt;span style="color:#2b91af"&gt;HttpOverrideBehavior&lt;/span&gt;.HttpMethodOverrideHeaderName];&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color:#2b91af"&gt;String&lt;/span&gt;.IsNullOrEmpty(httpMethodOverride))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                message.Properties[&lt;span style="color:#2b91af"&gt;HttpOverrideBehavior&lt;/span&gt;.OriginalHttpMethodPropertyName] = reqProp.Method;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                reqProp.Method = httpMethodOverride;&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalSelector.SelectOperation(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; message);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Finally, the test code to wrap it all together. The code is very similar to the one for the message inspectors post, with a few differences: the new behavior (HttpOverrideBehavior) is added &lt;em&gt;after&lt;/em&gt; the REST ((WebHttp) behavior, and after sending requests with the “real” HTTP verb it will send some additional requests using POST, but using the HTTP override method to route it to different operations.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:23248aa9-e4b2-4b07-a779-442a25ecdd3a" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;&amp;quot;http://&amp;quot;&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;&amp;quot;:8000/Service&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ContactManagerService&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;IContactManager&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebHttpBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;    endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HttpOverrideBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    host.Open();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Host opened&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; johnId = SendRequest(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        CreateJsonContact(&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;John Doe&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;john@doe.com&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;206-555-3333&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; janeId = SendRequest(&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        CreateJsonContact(&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Jane Roe&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;jane@roe.com&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;202-555-4444 202-555-8888&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;All contacts&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Updating Jane&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    SendRequest(&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;PUT&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + janeId,&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        CreateJsonContact(janeId, &lt;span style="color:#a31515"&gt;&amp;quot;Jane Roe&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;jane@roe.org&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;202-555-4444 202-555-8888&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;All contacts&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Deleting John&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;DELETE&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + johnId, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Is John still here?&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + johnId, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Adding John again&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    johnId = SendRequest(&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        CreateJsonContact(&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;John Doe&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;john@doe.com&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;206-555-3333&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Updating John, now using X-HTTP-Method-Override&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt; overrideWithPut = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    overrideWithPut.Add(&lt;span style="color:#a31515"&gt;&amp;quot;X-HTTP-Method-Override&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;PUT&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    SendRequest(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + johnId,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        CreateJsonContact(johnId, &lt;span style="color:#a31515"&gt;&amp;quot;John Doe Updated&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;john@doe.com&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;206-555-3333&amp;quot;&lt;/span&gt;),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        overrideWithPut);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;All contacts&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Deleting Jane, using X-HTTP-Method-Override&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt; overrideWithDelete = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;    overrideWithDelete.Add(&lt;span style="color:#a31515"&gt;&amp;quot;X-HTTP-Method-Override&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;DELETE&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + janeId, &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, overrideWithDelete);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;All contacts&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Press ENTER to close&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/li&gt; &lt;li&gt;    host.Close();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;h3&gt;Coming up&lt;/h3&gt;  &lt;p&gt;Operation invokers, for both synchronous and asynchronous operations.&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://code.msdn.microsoft.com/Support-for-X-HTTP-Method-9f71ceb1"&gt;Code in this post&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;Carlos Figueira   &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;    &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figuei&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10163023" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Extensibility/">Extensibility</category></item><item><title>Constraining what activities can be dropped on a custom activity designer in Windows Workflow Foundation 4</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/09/constraining-what-activities-can-be-dropped-on-a-custom-activity-designer-in-workflow-4.aspx</link><pubDate>Mon, 09 May 2011 22:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10162722</guid><dc:creator>Patrick D. Fletcher [MSFT]</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10162722</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/09/constraining-what-activities-can-be-dropped-on-a-custom-activity-designer-in-workflow-4.aspx#comments</comments><description>&lt;p&gt;When designing a custom activity that can be used as a container for other activities, you may want to restrict the activity user to a certain set of activities.&lt;/p&gt;
&lt;p&gt;If the custom activity can only accept a single type, this can be implemented quite simply by setting the WorkflowItemPresenter.AllowedItemType or WorkflowItemsPresenter.AllowedItemType property. In this example, I allow only a WriteLine activity to be dropped:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;
&lt;pre class="scroll"&gt;&lt;code class="cplusplus"&gt;&amp;lt;sap:WorkflowItemsPresenter HintText="Drop Activities Here" &lt;br /&gt;
Margin="5" MinHeight="100"&lt;br /&gt;
Items="{Binding Path=ModelItem.Activities}"&lt;br /&gt;
AllowedItemType="{x:Type TypeName=sa:WriteLine}"&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Note that to use the above code, you'll need to add a namespace declaration to your designer:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;
&lt;pre class="scroll"&gt;&lt;code class="cplusplus"&gt;xmlns:sa="clr-namespace:System.Activities.Statements;assembly=System.Activities"&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you need to restrict to a set of allowed activity types, rather than a single type, this can be done by adding a validation error to the validation errors collection during the CacheMetadata phase. Note that this will create a runtime&amp;nbsp;error (though technically the user will experience it in the design phase), which will&amp;nbsp;cause an error icon to be displayed, rather than preventing the activity to be dropped in the first place.&amp;nbsp;In this example, I allow only a WriteLine or Assign activity to be dropped:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;
&lt;pre class="scroll"&gt;&lt;code class="cplusplus"&gt;protected override void CacheMetadata(NativeActivityMetadata metadata)&lt;br /&gt;
{&lt;br /&gt;
    base.CacheMetadata(metadata);&lt;br /&gt;
    foreach (Activity a in Activities)&lt;br /&gt;
    {&lt;br /&gt;
        if ((a.GetType() != typeof(System.Activities.Statements.WriteLine)) &amp;amp;&amp;amp; (a.GetType() != typeof(System.Activities.Statements.Assign)))&lt;br /&gt;
        {&lt;br /&gt;
            metadata.AddValidationError("Child activity is not of type WriteLine or Assign");&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10162722" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/wf4+designer+constraints/">wf4 designer constraints</category></item><item><title>Microsoft.Activities and Microsoft.Activities.UnitTesting now available via NuGet</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/09/microsoft-activities-and-microsoft-activities-unittesting-now-available-via-nuget.aspx</link><pubDate>Mon, 09 May 2011 17:31:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10162587</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10162587</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/09/microsoft-activities-and-microsoft-activities-unittesting-now-available-via-nuget.aspx#comments</comments><description>&lt;p&gt;When I first saw &lt;a href="http://nuget.org"&gt;NuGet&lt;/a&gt; I knew I had to find a way to take advantage of this great new way to deliver code to you.&amp;#160; It took a few months but finally the other day I decided to spend an afternoon working on a NuGet package for Microsoft.Activities.&amp;#160; Two and a half days later (isn’t that how it always goes) I produced packages for &lt;a href="http://nuget.org/List/Packages/Microsoft.Activities"&gt;Microsoft.Activities&lt;/a&gt; and &lt;a href="http://nuget.org/List/Packages/Microsoft.Activities.UnitTesting"&gt;Microsoft.Activities.UnitTesting&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="512" height="288"&gt;&lt;param name="minRuntimeVersion" value="4.0.50401.0" /&gt;&lt;param name="source" value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" /&gt;&lt;param name="initParams" value="mediaurl=http://files.ch9.ms/ch9/5bc8/ed310d62-f9a3-4368-b613-9edc000c5bc8/endpointWFNuGet.ism/manifest,thumbnail=http://media.ch9.ms/ch9/5bc8/ed310d62-f9a3-4368-b613-9edc000c5bc8/endpointWFNuGet_512_ch9.jpg,deliverymethod=adaptivestreaming,autoplay=false,entryid=ed310d62f9a34368b6139edc000c5bc8" /&gt;&lt;/object&gt;&lt;/p&gt;  &lt;h3&gt;How To Get Microsoft.Activities or Microsoft.Activities.UnitTesting with NuGet&lt;/h3&gt;  &lt;br /&gt;  &lt;h4&gt;Step 0: Install NuGet&lt;/h4&gt;  &lt;p&gt;If you don’t already have &lt;a href="http://nuget.org/"&gt;NuGet&lt;/a&gt;, install it &lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/27077b70-9dad-4c64-adcf-c7cf6bc9970c/file/37502/5/NuGet.Tools.signed.vsix"&gt;now&lt;/a&gt; (you will have to restart Visual Studio if it is already running)&lt;/p&gt;  &lt;h4&gt;Step 1: Create a project&lt;/h4&gt;  &lt;p&gt;Your project can be any kind of project.&amp;#160; NuGet will automatically add references that are required.&amp;#160; For this example, I’m going to create a Class Library project.&lt;/p&gt;  &lt;h4&gt;Step 2a: Install the Microsoft.Activities Package (Using the Package Manager Console)&lt;/h4&gt;  &lt;ol&gt;   &lt;li&gt;Select &lt;strong&gt;View / Other Windows / Package Manager Console&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Type &lt;strong&gt;Install-Package Microsoft.Activities&lt;/strong&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/4035.image_5F00_5D33391D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/2772.image_5F00_thumb_5F00_4AEA725B.png" width="517" height="176" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;Step 2b: Install the Microsoft.Activities Package (Using Library Package Reference)&lt;/h4&gt;  &lt;p&gt;If you would rather have a UI to browse packages, &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Right click on the references folder &lt;/li&gt;    &lt;li&gt;Select Add Library Package Reference… &lt;/li&gt;    &lt;li&gt;In the search box type &lt;strong&gt;Microsoft.Activities&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click the &lt;strong&gt;Install&lt;/strong&gt; button to add a library package reference &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/7673.SNAGHTML4b4210_5F00_0AB458E1.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML4b4210" border="0" alt="SNAGHTML4b4210" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/3056.SNAGHTML4b4210_5F00_thumb_5F00_6E376700.png" width="244" height="139" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;&lt;/h4&gt;  &lt;h2&gt;What Happens to my Project / Visual Studio when I install this?&lt;/h2&gt;  &lt;h4&gt;Your Project &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;Add reference to &lt;strong&gt;System.Activities&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Add reference to ($SolutionDir)packages\Microsoft.Activities.1.8.1.506\lib\Net40\Microsoft.Activities.dll) with copy local = true so the assembly will be in your bin directory when you build. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Visual Studio&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;Added toolbox icons for the activities in Microsoft.Activities to your toolbox pointing to the last installation location for Microsoft.Activities.dll &lt;/li&gt;    &lt;li&gt;Add a new Workflow to your project to see the two groups (Dictionary and Microsoft.Activities) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/2474.image_5F00_3BD39381.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/4848.image_5F00_thumb_5F00_298ACCBF.png" width="230" height="316" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;What if I want to use .NET 4 Platform Update 1 so I can create a State Machine workflow?&lt;/h2&gt;  &lt;p&gt;The Microsoft.Activities package includes a version built for .NET 4 Platform Update 1.&amp;#160; As you see in the folder structure there are Net40 and Net401 folders.&amp;#160; NuGet automatically detects which version of the .NET Framework your project is targeting and will add a reference to the appropriate version &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/8233.image_5F00_0250838A.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/0726.image_5F00_thumb_5F00_7B314711.png" width="204" height="110" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;What if I change my target framework to .NET 4 Platform Update 1 after installing the Microsoft.Activities Package?&lt;/h2&gt;  &lt;p&gt;If you change your target framework after installing your project will continue to reference the .NET 4 version of Microsoft.Activities.&amp;#160; You can update the reference manually by browsing the packages folder and adding a reference or you can uninstall / reinstall the package.&lt;/p&gt;  &lt;h2&gt;What if I create a new project and drag an activity from Microsoft.Activities onto a workflow without first installing Microsoft.Activities?&lt;/h2&gt;  &lt;p&gt;Toolbox activities remain in the toolbox across projects.&amp;#160; When you create a new project and open the workflow designer you will see the Microsoft.Activities and Dictionary tabs.&amp;#160; When you drag one of these activities onto the workflow designer, Visual Studio will add a reference to the assembly that the toolbox icon is associated with.&lt;/p&gt;  &lt;p&gt;If you installed the Microsoft.Activities package to a project named ClassLibary1 and then created another project named WorkflowConsoleApplication1 as soon as you start dragging an activity onto a workflow from WorkflowConsoleApplication1 you will see an assembly reference added to the Microsoft.Activities package installed under the ClassLibrary1 solution.&lt;/p&gt;  &lt;h2&gt;What if I delete the solution where Microsoft.Activities was installed?&lt;/h2&gt;  &lt;p&gt;If you try to delete it while Visual Studio is open you will get an error because Visual Studio has the assembly loaded.&amp;#160; If you close Visual Studio and delete the solution, the next time you run Visual Studio and open the Workflow Designer you will see the icons are still in the toolbox.&amp;#160; However when you try to drop an activity from the missing assembly, Visual Studio won’t allow it because it is unable to locate the assembly to add a reference.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/7266.image_5F00_53F6FDDC.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/3377.image_5F00_thumb_5F00_687C4D5A.png" width="244" height="197" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;How do I fix the toolbox icons if they refer to an assembly that no longer exists?&lt;/h2&gt;  &lt;p&gt;Each time install the Microsoft.Activities package, if the toolbox icons exist, they are removed and replaced with a toolbox icon that refers to the Microsoft.Activities assembly that is installed with the package in current project.&lt;/p&gt;  &lt;h2&gt;What if I want to store the Microsoft.Activities assembly in some other location?&amp;#160; How do I keep the NuGet package from updating my toolbox icons?&lt;/h2&gt;  &lt;p&gt;If you change the name of the Tab group from Microsoft.Activities to something else, the package installation script won’t find the activities and won’t update them.&amp;#160; However it will add a new activity group.&lt;/p&gt;  &lt;h2&gt;How do I uninstall the Microsoft.Activities package?&lt;/h2&gt;  &lt;ol&gt;   &lt;li&gt;Open the Package Manager console &lt;/li&gt;    &lt;li&gt;Type &lt;strong&gt;Uninstall-Package Microsoft.Activities&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;In the toolbox, right click on the Microsoft.Activities tab group and select Delete Tab &lt;/li&gt;    &lt;li&gt;Repeat for the Dictionary Group &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Sometimes you will get an error when trying to uninstall because Visual Studio has one of the assemblies open.&amp;#160; In this case you will have to manually delete the package.&amp;#160; &lt;/p&gt;  &lt;pre&gt;PM&amp;gt; Uninstall-Package Microsoft.Activities
Successfully removed 'Microsoft.Activities 1.8.1.506' from WorkflowConsoleApplication10. 
Access to the path 'd:\ngt\WorkflowConsoleApplication10\packages\Microsoft.Activities.1.8.1.506\lib\Net40\Microsoft.Activities.dll' is denied. 
Access to the path 'd:\ngt\WorkflowConsoleApplication10\packages\Microsoft.Activities.1.8.1.506\tools\Microsoft.Activities.NuGet.dll' is denied. 
The directory is not empty.&lt;/pre&gt;

&lt;br /&gt;

&lt;h2&gt;What if I install Microsoft.Activities.UnitTesting and I don’t have Microsoft.Activities?&lt;/h2&gt;

&lt;p&gt;Not to worry.&amp;#160; Microsoft.Activities.UnitTesting has a dependency on the Microsoft.Activities package so NuGet will automatically deploy it as well.&lt;/p&gt;

&lt;pre&gt;PM&amp;gt; Install-Package Microsoft.Activities.UnitTesting 
'Microsoft.Activities (≥ 1.8.1)' not installed. Attempting to retrieve dependency from source... 
Done. 
Successfully installed 'Microsoft.Activities 1.8.1.509'. 
Successfully installed 'Microsoft.Activities.UnitTesting 1.8.1.509'. 
Successfully added 'Microsoft.Activities 1.8.1.509' to WorkflowConsoleApplication14. 
Successfully added 'Microsoft.Activities.UnitTesting 1.8.1.509' to WorkflowConsoleApplication14.&lt;/pre&gt;

&lt;h1&gt;What if I install Microsoft.Activities.UnitTesting and then try to Uninstall Microsoft.Activities&lt;/h1&gt;

&lt;pre&gt;PM&amp;gt; Uninstall-Package Microsoft.Activities
Uninstall-Package : Unable to uninstall 'Microsoft.Activities 1.8.1.509' because 'Microsoft.Activities.UnitTesting 1.8.1.509' depends on it.
At line:1 char:18
+ Uninstall-Package &amp;lt;&amp;lt;&amp;lt;&amp;lt;  Microsoft.Activities
    + CategoryInfo          : NotSpecified: (:) [Uninstall-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.UninstallPackageCommand&lt;/pre&gt;

&lt;h1&gt;What do you think?&lt;/h1&gt;

&lt;p&gt;I’m really happy with NuGet so far.&amp;#160; I just updated the uninstall scripts so that they will remove the toolbox tabs (Microsoft.Activities, Dictionary and Unit Testing) created by the install scripts.&amp;#160; Of all the things these packages do the interaction with the toolbox is the one area that I’m not sure about.&amp;#160; Hopefully what I’ve done here will work for you.&amp;#160; If not, tell me how we can do it better.&lt;/p&gt;

&lt;p&gt;Ron Jacobs 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/rjacobs"&gt;http://blogs.msdn.com/rjacobs&lt;/a&gt; 

  &lt;br /&gt;Twitter: @ronljacobs &lt;a href="http://twitter.com/ronljacobs"&gt;http://twitter.com/ronljacobs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10162587" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category></item><item><title>WCF scales up slowly with bursts of work</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/04/wcf-scales-up-slowly-with-bursts-of-work.aspx</link><pubDate>Thu, 05 May 2011 01:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10161224</guid><dc:creator>Dustin Metzgar</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10161224</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/04/wcf-scales-up-slowly-with-bursts-of-work.aspx#comments</comments><description>&lt;p&gt;A few customers have&amp;nbsp;noticed an issue with WCF scaling up when handling a burst of requests. Fortunately, there is a very simple workaround for this problem that is covered in &lt;a href="http://support.microsoft.com/kb/2538826" title="KB2538826"&gt;KB2538826&lt;/a&gt;&amp;nbsp;(thanks to David Lamb for the investigation and write up). The KB article provides a lot of good information about when this would apply to your application and what to do to fix it. In this post, I want to explore exactly what's happening.&lt;/p&gt;
&lt;p&gt;
&lt;object height="288" type="application/x-silverlight-2" width="512" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAJAADqNAAAxB0AAAAAAAAAAAAAAAAAAAAAAAACAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAABgAAAA0AC4AMAAuADUAMAA0ADAAMQAuADAAAAAAAAAAAAAAAAAAAAAAAAAA"&gt;
&lt;param value="4.0.50401.0" name="minRuntimeVersion" /&gt;
&lt;param name="source" /&gt;
&lt;param name="initParams" /&gt;
&lt;/object&gt;
&lt;/p&gt;
&lt;p&gt;The best part is that there is an easy way to reproduce the problem. To do this, create a new WCF service application with the .NET 4 framework:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/2402.IOThreadPoolBug7.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/2402.IOThreadPoolBug7.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then trim the default service contract down to only the GetData method:&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;&lt;span class="net_key"&gt;using&lt;/span&gt; System.ServiceModel;

[ServiceContract]
&lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;interface&lt;/span&gt; IService1
{
    [OperationContract]
    &lt;span class="net_key"&gt;string&lt;/span&gt; GetData(&lt;span class="net_key"&gt;int&lt;/span&gt; value);
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;And fill out the GetData method in the service code:&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;&lt;span class="net_key"&gt;using&lt;/span&gt; System;
&lt;span class="net_key"&gt;using&lt;/span&gt; System.Threading;

&lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;class&lt;/span&gt; Service1 : IService1
{
    &lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;string&lt;/span&gt; GetData(&lt;span class="net_key"&gt;int&lt;/span&gt; value)
    {
        &lt;span class="yh"&gt;Thread.Sleep(TimeSpan.FromSeconds(2));&lt;/span&gt;
        &lt;span class="net_key"&gt;return&lt;/span&gt; &lt;span class="net_key"&gt;string&lt;/span&gt;.Format(&lt;span class="net_string"&gt;"You entered: {0}"&lt;/span&gt;, value);
    }
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The two second sleep is the most important part of this repro. We'll explore why after we create the client and observe the effects. But first, make sure to set the throttle in the web.config:&lt;/p&gt;
&lt;pre&gt;&amp;lt;configuration&amp;gt;
  &amp;lt;system.web&amp;gt;
    &amp;lt;compilation debug="true" targetFramework="4.0" /&amp;gt;
  &amp;lt;/system.web&amp;gt;
  &amp;lt;system.serviceModel&amp;gt;
    &amp;lt;behaviors&amp;gt;
      &amp;lt;serviceBehaviors&amp;gt;
        &amp;lt;behavior&amp;gt;
          &amp;lt;serviceMetadata httpGetEnabled="true"/&amp;gt;
          &amp;lt;serviceDebug includeExceptionDetailInFaults="false"/&amp;gt;
          &lt;span class="yh"&gt;&amp;lt;serviceThrottling maxConcurrentCalls="100"/&amp;gt;&lt;/span&gt;
        &amp;lt;/behavior&amp;gt;
      &amp;lt;/serviceBehaviors&amp;gt;
    &amp;lt;/behaviors&amp;gt;
    &amp;lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&amp;gt;
  &amp;lt;/system.serviceModel&amp;gt;
  &amp;lt;system.webServer&amp;gt;
    &amp;lt;modules runAllManagedModulesForAllRequests="true"/&amp;gt;
  &amp;lt;/system.webServer&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/pre&gt;
&lt;p&gt;The Visual Studio web server would probably suffice, but I changed my web project to use IIS instead. This makes it more of a realistic situation. To do this go to the project properties, select the Web tab, and switch to IIS.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8750.IOThreadPoolBug8.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8750.IOThreadPoolBug8.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Be sure to hit the Create Virtual Directory button. In my case, I have SharePoint installed and it's taking up port 80, so I put the default web server on port 8080. Once this is done, build all and browse to the service to make sure it's working correctly.&lt;/p&gt;
&lt;p&gt;To create the test client, add a new command prompt executable to the solution and add a service reference to Service1. Change the client code to the following:&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;&lt;span class="net_key"&gt;using&lt;/span&gt; System;
&lt;span class="net_key"&gt;using&lt;/span&gt; System.Threading;
&lt;span class="net_key"&gt;using&lt;/span&gt; ServiceReference1;

&lt;span class="net_key"&gt;class&lt;/span&gt; Program
{
    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;const&lt;/span&gt; &lt;span class="net_key"&gt;int&lt;/span&gt; numThreads = 100;
    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;static&lt;/span&gt; CountdownEvent countdown;
    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;static&lt;/span&gt; ManualResetEvent mre = &lt;span class="net_key"&gt;new&lt;/span&gt; ManualResetEvent(&lt;span class="net_key"&gt;false&lt;/span&gt;);

    &lt;span class="net_key"&gt;static&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; Main(&lt;span class="net_key"&gt;string&lt;/span&gt;[] args)
    {
        &lt;span class="net_key"&gt;string&lt;/span&gt; s = &lt;span class="net_key"&gt;null&lt;/span&gt;;
        Console.WriteLine(&lt;span class="net_string"&gt;"Press enter to start test."&lt;/span&gt;);
        &lt;span class="net_key"&gt;while&lt;/span&gt; ((s = Console.ReadLine()) == &lt;span class="net_key"&gt;string&lt;/span&gt;.Empty)
        {
            RunTest();
            Console.WriteLine(&lt;span class="net_string"&gt;"Allow a few seconds for threads to die."&lt;/span&gt;);
            Console.WriteLine(&lt;span class="net_string"&gt;"Press enter to run again."&lt;/span&gt;);
            Console.WriteLine();
        }
    }

    &lt;span class="net_key"&gt;static&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; RunTest()
    {
        mre.Reset();
        Console.WriteLine(&lt;span class="net_string"&gt;"Starting {0} threads."&lt;/span&gt;, numThreads);
        countdown = &lt;span class="net_key"&gt;new&lt;/span&gt; CountdownEvent(numThreads);
        &lt;span class="net_key"&gt;for&lt;/span&gt; (&lt;span class="net_key"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numThreads; i++)
        {
            Thread t = &lt;span class="net_key"&gt;new&lt;/span&gt; Thread(ThreadProc);
            t.Name = &lt;span class="net_string"&gt;"Thread_"&lt;/span&gt; + i;
            t.Start();
        }
        &lt;span class="net_comment"&gt;// Wait for all threads to signal.&lt;/span&gt;
        countdown.Wait();
        Console.Write(&lt;span class="net_string"&gt;"Press enter to release threads."&lt;/span&gt;);
        Console.ReadLine();
        Console.WriteLine(&lt;span class="net_string"&gt;"Releasing threads."&lt;/span&gt;);
        DateTime startTime = DateTime.Now;
        countdown = &lt;span class="net_key"&gt;new&lt;/span&gt; CountdownEvent(numThreads);
        &lt;span class="net_comment"&gt;// Release all the threads.&lt;/span&gt;
        mre.Set();
        &lt;span class="net_comment"&gt;// Wait for all the threads to finish.&lt;/span&gt;
        countdown.Wait();
        TimeSpan ts = DateTime.Now - startTime;
        Console.WriteLine(&lt;span class="net_string"&gt;"Total time to run threads: {0}.{1:0}s."&lt;/span&gt;,
            ts.Seconds, ts.Milliseconds / 100);
    }

    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;static&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; ThreadProc()
    {
        Service1Client client = &lt;span class="net_key"&gt;new&lt;/span&gt; Service1Client();
        client.Open();
        &lt;span class="net_comment"&gt;// Signal that this thread is ready.&lt;/span&gt;
        countdown.Signal();
        &lt;span class="net_comment"&gt;// Wait for all the other threads before making service call.&lt;/span&gt;
        mre.WaitOne();
        client.GetData(1337);
        &lt;span class="net_comment"&gt;// Signal that this thread is finished.&lt;/span&gt;
        countdown.Signal();
        client.Close();
    }
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The code above uses a combination of a ManualResetEvent and a CountdownEvent to coordinate the calls to all happen at the same time. It then waits for all the calls to finish and determines how long it took. When I run this on a dual core machine, I get the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Press enter to start test.

Starting 100 threads.
Releasing threads.
Total time to run threads: 14.0s.
Allow a few seconds for threads to die.
Press enter to run again.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If each individual request only sleeps for 2 seconds, why would it take 100 simultaneous requests&amp;nbsp;14 seconds to complete? It should only take 2 seconds if they're all executing at the same time. To understand what's happening, let's look at the thread count in perfmon. First, open Administrative Tools -&amp;gt; Performance Monitor. In the tree view on the left, pick Monitoring Tools -&amp;gt; Performance Monitor. It should have the % Processor counter in there by default. We don't need that counter so select it in the bottom and press the delete key. Now click the add button to add a new counter:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8765.IOThreadPoolBug14.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8765.IOThreadPoolBug14.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the Add Counters dialog, expand the Process node:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/7384.IOThreadPoolBug15.png"&gt;&lt;img height="333" width="414" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/7384.IOThreadPoolBug15.png" style="border: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Under this locate the Thread Count counter and then find the w3wp instance and press the&amp;nbsp;Add &amp;gt;&amp;gt; button.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/2804.IOThreadPoolBug16.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/2804.IOThreadPoolBug16.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you don't see the w3wp instance, it is most likely because it wasn't running when you opened the Add Counters dialog. To correct this, close the dialog, ping the Service1.svc service, and then click the Add button again in perfmon.&lt;/p&gt;
&lt;p&gt;Now you can run the test and you should see results similar to the following:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/3386.IOThreadPoolBug1.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/3386.IOThreadPoolBug1.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this test, I had pinged the service to get the metadata to warm everything up. When the test ran, you can see it took several seconds to add another 21 threads. The reason these threads are added is because when WCF runs your service code, it uses a thread from the IO thread pool. Your service code is then expected to do some work that is either quick or CPU intensive or takes up a database connection. But in the case of the test, the Thread.Sleep means that no work is being done and the thread is being held. A real world scenario where this pattern could occur is if you have a WCF middle tier that has to make calls into lower layers and then return the results.&lt;/p&gt;
&lt;p&gt;For the most part, server load is assumed to change slowly. This means you would have a fairly constant load and the thread pool manager would pick the appropriate size for the thread pool to keep the CPU load high but without too much context switching. However, in the case of a sudden burst of requests with long-running, non-CPU-intensive&amp;nbsp;work like this, the thread pool adapts too slowly. You can see in the graph above that the number of threads drops back down to 30 after some time. The thread pool has recognized that a thread has not been used for 15 seconds and therefore kills it because it is not needed.&lt;/p&gt;
&lt;p&gt;To understand the thread pool a bit more, you can profile this and see what's happening. To get a profile, go to the Performance Explorer, usually pinned on the left side in Visual Studio, and click the button to create a new performance session:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8182.IOThreadPoolBug9.png"&gt;&lt;img height="174" width="264" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8182.IOThreadPoolBug9.png" style="border: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Right click on the new performance session and select properties. In the properties window change the profiling type to Concurrency and uncheck the "Collect resource contention data" option.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/0830.IOThreadPoolBug10.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/0830.IOThreadPoolBug10.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Before we start profiling, let's first go to the Tools-&amp;gt;Options menu in Visual Studio. Under Debugging, enable the Microsoft public symbol server.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/0841.IOThreadPoolBug11.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/0841.IOThreadPoolBug11.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Also, turn off the Just My Code option under Performance Tools:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/3817.IOThreadPoolBug12.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/3817.IOThreadPoolBug12.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The next step is to make the test client the startup project. You may need to ping the Service1.svc service again to make sure the w3wp process is running.&amp;nbsp;Now, attach to the w3wp process with the profiler. There is an attach button at the top of the performance explorer window or you can right click on the performance session and choose attach. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/5554.IOThreadPoolBug13.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/5554.IOThreadPoolBug13.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Give the profiler a few seconds to warmup and then hit ctrl+F5 to execute the test client. After the test client finishes a single run pause and detach the profiler from the w3wp process. You can also hit the "Stop profiling" option but it will kill the process.&lt;/p&gt;
&lt;p&gt;After you've finished profiling, it will take some time to process the data. Once it's up, switch to the thread view. In the figure below, I've rearranged the threads to make it easier to see the relationships:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/6114.IOThreadPoolBug2.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/6114.IOThreadPoolBug2.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Blue represents sleep time. This matches what we expect to see, which is a lot of new threads all sleeping for 2 seconds. At the top of the sleeping threads is the gate thread. It checks every 500ms to see if the number of threads in the thread pool is appropriate to handle the outstanding work. If not, it creates a new thread. You can see in the beginning that it creates 2 threads and then 1 thread at a time in 500ms increments. This is why it takes 14 seconds to process all 100 requests. So why are there two threads that look like they're created at the same time? If you look more closely, that's actually not the case. Let's zoom in on that part:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/6507.IOThreadPoolBug3.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/6507.IOThreadPoolBug3.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here again the highlighted thread is the gate thread. Before it finishes its 500ms sleep, a new thread is created to handle one of the WCF service calls which sleeps for 2 seconds. Then when the gate thread does its check, it realizes that there is a lot of work currently backed up and creates another new thread. On a dual core machine like this, the default minimum IO thread pool setting is 2: 1 per core. One of those threads is always taken up by WCF and functions as the timer thread. You can see that there are other threads created up top. This is most likely ASP.Net creating some worker threads to handle the incoming requests. You can see that they don't sleep because they're passing off work to WCF and getting ready to handle the next batch of work.&lt;/p&gt;
&lt;p&gt;The most obvious thing to do then would be to increase the minimum number of IO threads. You can do this in two ways: use ThreadPool.SetMinThreads or use the &amp;lt;processModel&amp;gt; tag in the machine.config. Here is how to do the latter:&lt;/p&gt;
&lt;pre&gt;&amp;lt;system.web&amp;gt;
  &amp;lt;!--&amp;lt;processModel autoConfig="true"/&amp;gt;--&amp;gt;
  &amp;lt;processModel 
    autoConfig="false" 
    minIoThreads="101" 
    minWorkerThreads="2" 
    maxIoThreads="200" 
    maxWorkerThreads="40" 
    /&amp;gt;&lt;/pre&gt;
&lt;p&gt;Be sure to turn off the autoConfig setting or the other options will be ignored. If we run this test again, we get a much better result. Compare the previous snapshot of permon with this one:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/5670.IOThreadPoolBug4.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/5670.IOThreadPoolBug4.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And the resulting output of the run is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Starting 100 threads.
Press enter to release threads.
Releasing threads.
Total time to run threads: &lt;span class="yh"&gt;2.2s&lt;/span&gt;.
Allow a few seconds for threads to die.
Press enter to run again.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is an excellent result. It is exactly what you would want to happen if a sudden burst of work comes in. But customers were saying that this wasn't happening for them. David Lamb told me that if you run this for a long time, like 2 hours, it would eventually stop quickly adding threads and behave as if the min IO threads was not set.&lt;/p&gt;
&lt;p&gt;One of the things we can do is modify the test code to give enough time for the threads to have their 15 second timeout and just take out all the Console.ReadLine calls:&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;&lt;span class="net_key"&gt;using&lt;/span&gt; System;
&lt;span class="net_key"&gt;using&lt;/span&gt; System.Threading;
&lt;span class="net_key"&gt;using&lt;/span&gt; ServiceReference1;

&lt;span class="net_key"&gt;class&lt;/span&gt; Program
{
    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;const&lt;/span&gt; &lt;span class="net_key"&gt;int&lt;/span&gt; numThreads = 100;
    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;static&lt;/span&gt; CountdownEvent countdown;
    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;static&lt;/span&gt; ManualResetEvent mre = &lt;span class="net_key"&gt;new&lt;/span&gt; ManualResetEvent(&lt;span class="net_key"&gt;false&lt;/span&gt;);

    &lt;span class="net_key"&gt;static&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; Main(&lt;span class="net_key"&gt;string&lt;/span&gt;[] args)
    {
        &lt;span class="net_key"&gt;while&lt;/span&gt; (&lt;span class="net_key"&gt;true&lt;/span&gt;)
        {
            RunTest();
            Thread.Sleep(TimeSpan.FromSeconds(25));
            Console.WriteLine();
        }
    }

    &lt;span class="net_key"&gt;static&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; RunTest()
    {
        mre.Reset();
        Console.WriteLine(&lt;span class="net_string"&gt;"Starting {0} threads."&lt;/span&gt;, numThreads);
        countdown = &lt;span class="net_key"&gt;new&lt;/span&gt; CountdownEvent(numThreads);
        &lt;span class="net_key"&gt;for&lt;/span&gt; (&lt;span class="net_key"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numThreads; i++)
        {
            Thread t = &lt;span class="net_key"&gt;new&lt;/span&gt; Thread(ThreadProc);
            t.Name = &lt;span class="net_string"&gt;"Thread_"&lt;/span&gt; + i;
            t.Start();
        }
        &lt;span class="net_comment"&gt;// Wait for all threads to signal.&lt;/span&gt;
        countdown.Wait();
        Console.WriteLine(&lt;span class="net_string"&gt;"Releasing threads."&lt;/span&gt;);
        DateTime startTime = DateTime.Now;
        countdown = &lt;span class="net_key"&gt;new&lt;/span&gt; CountdownEvent(numThreads);
        &lt;span class="net_comment"&gt;// Release all the threads.&lt;/span&gt;
        mre.Set();
        &lt;span class="net_comment"&gt;// Wait for all the threads to finish.&lt;/span&gt;
        countdown.Wait();
        TimeSpan ts = DateTime.Now - startTime;
        Console.WriteLine(&lt;span class="net_string"&gt;"Total time to run threads: {0}.{1:0}s."&lt;/span&gt;,
            ts.Seconds, ts.Milliseconds / 100);
    }

    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;static&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; ThreadProc()
    {
        Service1Client client = &lt;span class="net_key"&gt;new&lt;/span&gt; Service1Client();
        client.Open();
        &lt;span class="net_comment"&gt;// Signal that this thread is ready.&lt;/span&gt;
        countdown.Signal();
        &lt;span class="net_comment"&gt;// Wait for all the other threads before making service call.&lt;/span&gt;
        mre.WaitOne();
        client.GetData(1337);
        &lt;span class="net_comment"&gt;// Signal that this thread is finished.&lt;/span&gt;
        countdown.Signal();
        client.Close();
    }
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Then just let it run for a couple hours and see what happens. Luckily, it doesn't take 2 hours and we can reproduce the weird behavior pretty quickly. Here is a perfmon graph showing several runs:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8865.IOThreadPoolBug5.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/8865.IOThreadPoolBug5.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can see that the first two bursts had quick scale up with the thread count. After that, it went back to being slow. After working with the CLR team, they determined that there is a bug in the IO thread pool. This bug causes the internal count of IO threads to get out-of-sync with reality. Some of you may be asking the question as to what min really means in terms of the thread pool. Because if you specify you want a minimum of 100 threads, why wouldn't there just always be 100 threads? For the purposes of the thread pool, the min is supposed to be the threshold that the pool can scale up to before it starts to be metered. The default working set cost for one thread is a half MB. So that is one reason to keep the thread count down.&lt;/p&gt;
&lt;p&gt;Some customers have found that Juval Lowy's thread pool doesn't have the same problem and handles these bursts of work much better. Here is a link to his article: &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163321.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/cc163321.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice that Juval has created a custom thread pool and relies on the SynchronizationContext to switch from the IO thread that WCF uses to the custom thread pool. Using a custom thread pool in your production environment is not advisable. Most developers do not have the resources to properly test a custom thread pool for their applications. Thankfully, there is an alternative and that is the recommendation made in the KB article. The alternative is to use the worker thread pool. Juval has some code for a custom attribute that you can put on your service to set the SynchronizationContext to use his custom thread pool and we can just modify that to put the work into the worker thread pool. The code for this change is all in the KB article, but I'll reiterate here along with with the changes to the service itself.&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;&lt;span class="net_key"&gt;using&lt;/span&gt; System;
&lt;span class="net_key"&gt;using&lt;/span&gt; System.Threading;
&lt;span class="net_key"&gt;using&lt;/span&gt; System.ServiceModel.Description;
&lt;span class="net_key"&gt;using&lt;/span&gt; System.ServiceModel.Channels;
&lt;span class="net_key"&gt;using&lt;/span&gt; System.ServiceModel.Dispatcher;

&lt;span class="yh"&gt;[WorkerThreadPoolBehavior]&lt;/span&gt;
&lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;class&lt;/span&gt; Service1 : IService1
{
    &lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;string&lt;/span&gt; GetData(&lt;span class="net_key"&gt;int&lt;/span&gt; value)
    {
        Thread.Sleep(TimeSpan.FromSeconds(2));
        &lt;span class="net_key"&gt;return&lt;/span&gt; &lt;span class="net_key"&gt;string&lt;/span&gt;.Format(&lt;span class="net_string"&gt;"You entered: {0}"&lt;/span&gt;, value);
    }
}

&lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;class&lt;/span&gt; WorkerThreadPoolSynchronizer : SynchronizationContext
{
    &lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;override&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; Post(SendOrPostCallback d, &lt;span class="net_key"&gt;object&lt;/span&gt; state)
    {
        &lt;span class="net_comment"&gt;// WCF almost always uses Post&lt;/span&gt;
        &lt;span class="yh"&gt;ThreadPool.QueueUserWorkItem(&lt;span class="net_key"&gt;new&lt;/span&gt; WaitCallback(d), state);&lt;/span&gt;
    }

    &lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;override&lt;/span&gt; &lt;span class="net_key"&gt;void&lt;/span&gt; Send(SendOrPostCallback d, &lt;span class="net_key"&gt;object&lt;/span&gt; state)
    {
        &lt;span class="net_comment"&gt;// Only the peer channel in WCF uses Send&lt;/span&gt;
        d(state);
    }
}

[AttributeUsage(AttributeTargets.Class)]
&lt;span class="net_key"&gt;public&lt;/span&gt; &lt;span class="net_key"&gt;class&lt;/span&gt; WorkerThreadPoolBehaviorAttribute : Attribute, IContractBehavior
{
    &lt;span class="net_key"&gt;private&lt;/span&gt; &lt;span class="net_key"&gt;static&lt;/span&gt; WorkerThreadPoolSynchronizer synchronizer = &lt;span class="net_key"&gt;new&lt;/span&gt; WorkerThreadPoolSynchronizer();

    &lt;span class="net_key"&gt;void&lt;/span&gt; IContractBehavior.AddBindingParameters(
        ContractDescription contractDescription,
        ServiceEndpoint endpoint,
        BindingParameterCollection bindingParameters)
    {
    }

    &lt;span class="net_key"&gt;void&lt;/span&gt; IContractBehavior.ApplyClientBehavior(
        ContractDescription contractDescription,
        ServiceEndpoint endpoint,
        ClientRuntime clientRuntime)
    {
    }

    &lt;span class="net_key"&gt;void&lt;/span&gt; IContractBehavior.ApplyDispatchBehavior(
        ContractDescription contractDescription,
        ServiceEndpoint endpoint,
        DispatchRuntime dispatchRuntime)
    {
        &lt;span class="yh"&gt;dispatchRuntime.SynchronizationContext = synchronizer;&lt;/span&gt;
    }

    &lt;span class="net_key"&gt;void&lt;/span&gt; IContractBehavior.Validate(
        ContractDescription contractDescription,
        ServiceEndpoint endpoint)
    {
    }
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The areas highlighted above show the most important bits for this change. There really isn't that much code to this. With this change essentially what is happening is that WCF recognizes that when it's time to execute the service code, there is an ambient SynchronizationContext. That context then pushes the work into the worker thread pool with QueueUserWorkItem. The only other change to make is to the &amp;lt;processModel&amp;gt; node in the machine.config to configure the worker thread pool for a higher min and max.&lt;/p&gt;
&lt;pre&gt;&amp;lt;system.web&amp;gt;
  &amp;lt;!--&amp;lt;processModel autoConfig="true"/&amp;gt;--&amp;gt;
  &amp;lt;processModel 
    autoConfig="false" 
    minWorkerThreads="100" 
    maxWorkerThreads="200" 
    /&amp;gt;&lt;/pre&gt;
&lt;p&gt;Running the test again, you will see a much better result:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/6237.IOThreadPoolBug6.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-84/6237.IOThreadPoolBug6.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;All of the test runs finished in under 2.5 seconds.&lt;/p&gt;
&lt;p&gt;We cannot make a recommendation on this alone though. There are other questions like how does this affect performance and does it continue to work this way for hours, days, weeks, etc. Our testing showed that for at least 72 hours, this worked without a problem. The performance runs showed some caveats though. These are also pointed out in the KB article. There is a cost for switching from one thread to another. This would be the same with the worker thread pool or a custom thread pool. That overhead can be negligible for large amounts of work. In the case that applies here with 2 seconds of blocking work, the context switch is definitely not a factor. But if you've got small messages and fast work,&amp;nbsp;then it's likely to&amp;nbsp;hurt your performance.&lt;/p&gt;
&lt;p&gt;The test project is included with this post.&lt;/p&gt;
&lt;p&gt;Originally posted on Dustin Metzgar's blog&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10161224" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-16-12-24/IOThreadPoolBug.zip" length="17799" type="application/zip" /><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Performance/">Performance</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item><item><title>WCF Extensibility – Message Formatters</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/05/03/wcf-extensibility-message-formatters.aspx</link><pubDate>Tue, 03 May 2011 17:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10160522</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10160522</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/05/03/wcf-extensibility-message-formatters.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;&lt;em&gt;index page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Message formatters are the component which do the translation between CLR operations and the WCF &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;Message&lt;/a&gt; object &amp;ndash; their role is to convert all the operation parameters and return values (possibly via serialization) into a Message on output, and deconstruct the message into parameter and return values on input. Anytime a new format is to be used (be it a new serialization format for currently supported CLR types, or supporting a new CLR type altogether), a message formatter is the interface you&amp;rsquo;d implement to enable this scenario. For example, even though the type System.IO.Stream is not serializable (it&amp;rsquo;s even abstract), WCF allows it to be used as the input or return values for methods (for example, in the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx"&gt;WCF REST Raw programming model&lt;/a&gt;) and a formatter deals with converting it into messages. Like the message inspectors, there are two versions, one for the server side (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageformatter.aspx"&gt;IDispatchMessageFormatter&lt;/a&gt;), and one for the client side (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageformatter.aspx"&gt;IClientMessageFormatter&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Among the extensibility points listed in this series, the message formatters are the first kind to be &lt;em&gt;required&lt;/em&gt; in the WCF pipeline &amp;ndash; a service does not need to have any service / endpoint / contract / operation behavior, nor any message / parameter inspector. If the user doesn&amp;rsquo;t add any of those, the client / service will just work (some behaviors are automatically added to the operations when one adds an endpoint, but that&amp;rsquo;s an implementation detail for WCF &amp;ndash; they aren&amp;rsquo;t strictly necessary). Formatters, on the other hand, are required (to bridge the gap between the message world and the operations using CLR types). If we don&amp;rsquo;t add any behaviors to the service / endpoint / contract / operation that sets a formatter, WCF will add one formatter to the operation (usually via the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.datacontractserializeroperationbehavior.aspx"&gt;DataContractSerializerOperationBehavior&lt;/a&gt;, which is added by default in all operation contracts).&lt;/p&gt;
&lt;h3&gt;Public implementations in WCF&lt;/h3&gt;
&lt;p&gt;None. As with most of the runtime extensibility points, there are no public implementations of either the dispatch or the client message formatter. There are a lot of internal implementations, though, such as a formatter which converts operation parameters into a message (both using the DataContractSerializer and the XmlSerializer), formatters which map parameters to the HTTP URI (used in REST operations with UriTemplate), among others.&lt;/p&gt;
&lt;h3&gt;Interface declaration&lt;/h3&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e68f9267-8f0b-45e3-87cc-e02d35c5450b" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;interface&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;IDispatchMessageFormatter&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;void&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; DeserializeRequest(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; message, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;object&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;[] parameters);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; SerializeReply(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;MessageVersion&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; messageVersion, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;object&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;[] parameters, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;object&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; result);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;public&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;interface&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; &lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; SerializeRequest(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;MessageVersion&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; messageVersion, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;object&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;[] parameters);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background: #ffffff; color: #000000;"&gt;&lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;object&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; DeserializeReply(&lt;/span&gt;&lt;span style="background: #ffffff; color: #2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt; message, &lt;/span&gt;&lt;span style="background: #ffffff; color: #0000ff;"&gt;object&lt;/span&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;[] parameters);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background: #ffffff; color: #000000;"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The formatter interfaces each have two methods, one to convert between input outgoing CLR objects into the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;Message&lt;/a&gt; object (serialize), and one to take the incoming message object apart and break it down into incoming CLR objects (deserialize).&lt;/p&gt;
&lt;p&gt;At the server side, after the the message was decoded, passed through the channel stack and other extensibility points and is about to be dispatched to the service operation, the method &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageformatter.deserializerequest.aspx"&gt;DeserializeRequest&lt;/a&gt; is called to deserialize the message object into an array of parameters to be passed to the operation. The object argument &amp;ldquo;parameters&amp;rdquo; will have been allocated, so the implementation of the formatter only needs to read the message and set the operation parameters in their correct order in the array passed to it. After the operation is invoked (and any parameter inspector has a chance to change the operation outputs), &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageformatter.serializereply.aspx"&gt;SerializeReply&lt;/a&gt; is called, to take the operation return, plus the final value of any out/ref parameters which the operation may have, and package them into a Message object to be sent down the WCF channel stack.&lt;/p&gt;
&lt;p&gt;At the client side the mirror happens: when the operation is called (and after the parameter inspector has a chance to change the inputs), &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageformatter.serializerequest.aspx"&gt;SerializeRequest&lt;/a&gt; is called to package all the input parameters into the outgoing message object. After the message is sent to the server and the response is decoded by the client&amp;rsquo;s encoder, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageformatter.deserializereply.aspx"&gt;DeserializeReply&lt;/a&gt; is called to open the message object and populate the return value and any possible out/ref parameters.&lt;/p&gt;
&lt;p&gt;One small parenthesis about out/ref parameters: all parameters in WCF calls are passed by value &amp;ndash; a copy of the value is sent across the wire. If an operation declares a parameter with a ref modifier (ByRef in Visual Basic), the service will receive a copy (i.e., by value) of that parameter, and then return another copy of the value of the parameter at the end of the method. This second copy will be deserialized at the client into a new instance of that type. So even if you pass an instance of your type by reference to a WCF service, and the service doesn&amp;rsquo;t change it at all, the value at the end of the call at the client side the reference will point to a different object.&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e30d41d2-fb53-4602-9d5d-f1a2ee804c32" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;[&lt;span style="color: #2b91af;"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; UpdatePerson(&lt;span style="color: #0000ff;"&gt;ref&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt; person);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; InOutRef(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; x, &lt;span style="color: #0000ff;"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; y, &lt;span style="color: #0000ff;"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; z, &lt;span style="color: #0000ff;"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; w);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Client&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Main()&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&amp;gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt; p1 = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt; p2 = p1;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;.ReferenceEquals(p1, p2)); &lt;span style="color: #008000;"&gt;// true&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;proxy.UpdatePerson(&lt;span style="color: #0000ff;"&gt;ref&lt;/span&gt; p2);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;.ReferenceEquals(p1, p2)); &lt;span style="color: #008000;"&gt;// false, even if service doesn't change reference&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Going back to the formatters, the list of &amp;ldquo;input&amp;rdquo; parameters (those in the *Request) operations are either the input (ByVal) parameters or reference (ByRef without &amp;lt;Out&amp;gt;). The list of &amp;ldquo;output&amp;rdquo; parameters are ones marked with ref (ByRef) and out (&amp;lt;Out&amp;gt; ByRef). In the operation InOutRef above, the parameters x and y are considered to be input parameters, so the parameters array in the *Request operations will have two objects). The parameters y, z and w are considered to be output parameters, so the parameters array in the *Reply operations will have three elements.&lt;/p&gt;
&lt;h3&gt;How to add message formatters&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;At the server side&lt;/strong&gt;: the formatter is a property of the operation runtime, so at the server side it&amp;rsquo;s available at the DispatchOperation object. This object is typically accessed via an operation behavior, or by traversing the operation list from an endpoint behavior. both in the ApplyDispatchBehavior method. Another way is if you&amp;rsquo;re creating a REST endpoints (i.e., one with a behavior which inherits from &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/a&gt;). WebHttpBehavior exposes two protected methods, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.getrequestdispatchformatter.aspx"&gt;GetRequestDispatchFormatter&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.getreplydispatchformatter.aspx"&gt;GetReplyDispatchFormatter&lt;/a&gt;, which can be overridden to to return the formatter to be used by the operation.&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4355aa99-a540-440a-8e6d-6d404dd83289" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyDispatchMessageFormatter&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IDispatchMessageFormatter&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operation;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; MyDispatchMessageFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operation) { ... }&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyRestBehavior&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;WebHttpBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IDispatchMessageFormatter&lt;/span&gt; GetReplyDispatchFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyDispatchMessageFormatter&lt;/span&gt;(operationDescription);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;At the client side&lt;/strong&gt;: Similarly, the operation formatter at the client side is available at the ClientOperation object, typically accessed via an operation or endpoint behavior. And for behaviors inheriting from &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/a&gt;, there are two protected methods, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.getrequestclientformatter.aspx"&gt;GetRequestClientFormatter&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.getreplyclientformatter.aspx"&gt;GetReplyClientFormatter&lt;/a&gt;, which can be used to return the operation formatter as well.&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ba56ef0-968f-4a87-912a-0f505a6fb3a9" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyClientFormatter&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyOperationBehavior&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IOperationBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;ClientOperation&lt;/span&gt; clientOperation)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;clientOperation.Formatter = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyClientFormatter&lt;/span&gt;();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A quick note about wrapping the default WCF formatter. As I mentioned before, the default formatter is usually added by the DataContractSerializerOperationBehavior when it&amp;rsquo;s executed. If we want to use that default formatter, and wrap it in our own formatter, we need to make sure that the DataContractSerializerOperationBehavior is a position in the operation behavior list which is executed &lt;em&gt;before&lt;/em&gt; our own operation behavior is. Take this seemingly problem-free example:&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:224d3c51-c154-404c-b5ed-87b915b5cef6" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;[&lt;span style="color: #2b91af;"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;MyOperationBehavior&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Add(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; x, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Service&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Add(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; x, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; y) { &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; x + y; }&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyClientFormatter&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt; inner;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; MyClientFormatter(&lt;span style="color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt; inner)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (inner == &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;) &lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"inner"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.inner = inner;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; DeserializeReply(&lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; message, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.inner.DeserializeReply(message, parameters);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; SerializeRequest(&lt;span style="color: #2b91af;"&gt;MessageVersion&lt;/span&gt; messageVersion, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.inner.SerializeRequest(messageVersion, parameters);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyOperationBehaviorAttribute&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;Attribute&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;IOperationBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;ClientOperation&lt;/span&gt; clientOperation)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;clientOperation.Formatter = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyClientFormatter&lt;/span&gt;(clientOperation.Formatter);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;DispatchOperation&lt;/span&gt; dispatchOperation)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Validate(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Program&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[] args)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color: #a31515;"&gt;"http://"&lt;/span&gt; + &lt;span style="color: #2b91af;"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color: #a31515;"&gt;":8000/Service"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;Service&lt;/span&gt;), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.AddServiceEndpoint(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color: #a31515;"&gt;""&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.Open();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&amp;gt;(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;EndpointAddress&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; opBehavior &lt;span style="color: #0000ff;"&gt;in&lt;/span&gt; factory.Endpoint.Contract.Operations[0].Behaviors)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(opBehavior);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(proxy.Add(3, 4));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The call to CreateChannel in the channel factory will fail &amp;ndash; the constructor of MyClientFormatter will throw. That&amp;rsquo;s because the order of the operation behaviors (printed in the code) is the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;System.ServiceModel.Dispatcher.OperationInvokerBehavior      &lt;br /&gt;&lt;strong&gt;MyOperationBehaviorAttribute&lt;/strong&gt;       &lt;br /&gt;System.ServiceModel.OperationBehaviorAttribute       &lt;br /&gt;System.ServiceModel.Description.DataContractSerializerOperationBehavior       &lt;br /&gt;System.ServiceModel.Description.DataContractSerializerOperationGenerator&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I have no idea why attribute-based operation behaviors are added in this position, but the fact is that this doesn&amp;rsquo;t work. So for this scenario we cannot use attribute-based behaviors, we need to add it &amp;ldquo;manually&amp;rdquo;, as shown below.&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6345efb9-a0a1-4e7b-956d-7783ecce5fe1" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;[&lt;span style="color: #2b91af;"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;//[MyOperationBehavior]&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Add(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; x, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Program&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[] args)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color: #a31515;"&gt;"http://"&lt;/span&gt; + &lt;span style="color: #2b91af;"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color: #a31515;"&gt;":8000/Service"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;Service&lt;/span&gt;), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color: #a31515;"&gt;""&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;endpoint.Contract.Operations.Find(&lt;span style="color: #a31515;"&gt;"Add"&lt;/span&gt;).Behaviors.Add(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyOperationBehaviorAttribute&lt;/span&gt;());&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.Open();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt;&amp;gt;(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;EndpointAddress&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ITest&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(proxy.Add(3, 4));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;After doing that, the code runs and works fine.&lt;/p&gt;
&lt;h3&gt;Real world scenario: supporting different data and serialization formats&lt;/h3&gt;
&lt;p&gt;The first version of WCF (.NET Framework 3.0) supported essentially SOAP endpoints &amp;ndash; an XML payload following some rules defined in the SOAP specification (you actually could do POX/REST, but it was awfully hard). On the next version (.NET Framework 3.5), the REST programming model was added and that started supporting a whole new set of formats, mostly notably POX (plain-old XML, no SOAP involved), JSON (based on the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx"&gt;DataContractJsonSerializer&lt;/a&gt;) and a special &amp;ldquo;raw&amp;rdquo; mode, where one could declare a single &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx"&gt;Stream&lt;/a&gt; parameter in an operation for &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx"&gt;receiving arbitrary data&lt;/a&gt;, or returning a Stream value for &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx"&gt;returning arbitrary data&lt;/a&gt;. The raw mode can be used to support essentially all data and serialization formats, but that comes at a price that the operation itself has to deal with serializing / deserializing the parameters. Also, there are &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/220d3cec-2ea6-42a9-b9e9-dbd78fb26b83"&gt;scenarios&lt;/a&gt; (from the forums) where the user needs to expose the same operation in non-REST endpoints (or even non-HTTP, as in the scenario described in the forum post), where the Stream trick won&amp;rsquo;t work. This example will expand on the answer to the forum question and provide formatters which will use a custom serializer (in this case, the JSON.NET one, available from codeplex at &lt;a href="http://json.codeplex.com"&gt;http://json.codeplex.com&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;And the usual disclaimer: this is a sample for illustrating the topic of this post, this is not production-ready code. I tested it for a few contracts and it worked, but I cannot guarantee that it will work for all scenarios (please let me know if you find a bug or something missing). Also, for simplicity sake it doesn&amp;rsquo;t have a lot of error handling which a production-level code would, and it isn&amp;rsquo;t fully integrated with the WCF REST pipeline (i.e., it doesn&amp;rsquo;t support UriTemplates, it doesn&amp;rsquo;t integrate with the REST help page, doesn&amp;rsquo;t support out/ref parameters,, etc.).&lt;/p&gt;
&lt;p&gt;First, some data contracts to set up the scenario. The service will process people and their pets. The data contracts are decorated both with WCF serialization attributes (&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;DataContract&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx"&gt;DataMember&lt;/a&gt;), and with the JSON.NET serialization attributes (&lt;a href="http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonObjectAttribute.htm"&gt;JsonObejct&lt;/a&gt;, &lt;a href="http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonPropertyAttribute.htm"&gt;JsonProperty&lt;/a&gt;, &lt;a href="http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonConverterAttribute.htm"&gt;JsonConverter&lt;/a&gt;) so that it can be mapped according to both formats.&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:df72f693-8bec-4d85-885f-9f03825d5186" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;[&lt;span style="color: #2b91af;"&gt;DataContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;[Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonObject&lt;/span&gt;(MemberSerialization = Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;MemberSerialization&lt;/span&gt;.OptIn)]&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 1), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; FirstName;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 2), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; LastName;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 3),&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonConverter&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(Newtonsoft.Json.Converters.&lt;span style="color: #2b91af;"&gt;IsoDateTimeConverter&lt;/span&gt;))]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt; BirthDate;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 4), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt;&amp;gt; Pets;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 5), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Id;&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;[&lt;span style="color: #2b91af;"&gt;DataContract&lt;/span&gt;, Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonObject&lt;/span&gt;(MemberSerialization = Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;MemberSerialization&lt;/span&gt;.OptIn)]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 1), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; Name;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 2), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; Color;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 3), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; Markings;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;DataMember&lt;/span&gt;(Order = 4), Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonProperty&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Id;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next the interface definition, and the service implementation. It&amp;rsquo;s not very interesting, but I added operations using both GET and POST methods, and operations with single and multiple parameters (the goal of this sample is to demonstrate the formatter, not a specific service, so I think I can slack off on the service example a little &lt;img style="border-style: none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-96-metablogapi/5810.wlEmoticon_2D00_smile_5F00_4F5C1381.png" /&gt;).&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ab7133b-4ce4-442a-8be7-190f7b2883a3" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;[&lt;span style="color: #2b91af;"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;WebGet&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt; GetPerson();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;WebInvoke&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt; EchoPet(&lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt; pet);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color: #2b91af;"&gt;WebInvoke&lt;/span&gt;(BodyStyle = &lt;span style="color: #2b91af;"&gt;WebMessageBodyStyle&lt;/span&gt;.WrappedRequest), &lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Add(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; x, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Service&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt; GetPerson()&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName = &lt;span style="color: #a31515;"&gt;"First"&lt;/span&gt;,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName = &lt;span style="color: #a31515;"&gt;"Last"&lt;/span&gt;,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BirthDate = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; DateTime(1993, 4, 17, 2, 51, 37, 47, DateTimeKind.Local),&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Id = 0,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Pets = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt;&amp;gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt; { Name= &lt;span style="color: #a31515;"&gt;"Generic Pet 1"&lt;/span&gt;, Color = &lt;span style="color: #a31515;"&gt;"Beige"&lt;/span&gt;, Id = 0, Markings = &lt;span style="color: #a31515;"&gt;"Some markings"&lt;/span&gt; },&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt; { Name= &lt;span style="color: #a31515;"&gt;"Generic Pet 2"&lt;/span&gt;, Color = &lt;span style="color: #a31515;"&gt;"Gold"&lt;/span&gt;, Id = 0, Markings = &lt;span style="color: #a31515;"&gt;"Other markings"&lt;/span&gt; },&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt; EchoPet(&lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt; pet)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; pet;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Add(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; x, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; y)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; x + y;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now the behavior which will set everything together. Since this is a REST endpoint, instead of writing a new endpoint, I&amp;rsquo;ll simply inherit from &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/a&gt;, and override the protected methods to return the client and server formatters. Notice that in some cases when there are no parameters or for GET requests (where the parameters are in the query string, not in the request body), so in those cases I&amp;rsquo;ll simply reuse the default formatter from the base class. Another logic which is implemented at the behavior is validation &amp;ndash; we know what our formatter doesn&amp;rsquo;t support, so we&amp;rsquo;ll simply throw while the service (or the client channel) is being opened, giving the user a clear message explaining why the behavior failed the validation (some of the validation code is not in the snippet below, but it can be found in the source code for this post).&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:888eb198-1581-425c-854e-848882962da6" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonBehavior&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;WebHttpBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Validate(&lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.Validate(endpoint);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;BindingElementCollection&lt;/span&gt; elements = endpoint.Binding.CreateBindingElements();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;WebMessageEncodingBindingElement&lt;/span&gt; webEncoder = elements.Find&amp;lt;&lt;span style="color: #2b91af;"&gt;WebMessageEncodingBindingElement&lt;/span&gt;&amp;gt;();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (webEncoder == &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"This behavior must be used in an endpoint with the WebHttpBinding (or a custom binding with the WebMessageEncodingBindingElement)."&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operation &lt;span style="color: #0000ff;"&gt;in&lt;/span&gt; endpoint.Contract.Operations)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.ValidateOperation(operation);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IDispatchMessageFormatter&lt;/span&gt; GetRequestDispatchFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.IsGetOperation(operationDescription))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// no change for GET operations&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.GetRequestDispatchFormatter(operationDescription, endpoint);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (operationDescription.Messages[0].Body.Parts.Count == 0)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// nothing in the body, still use the default&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.GetRequestDispatchFormatter(operationDescription, endpoint);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonDispatchFormatter&lt;/span&gt;(operationDescription, &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IDispatchMessageFormatter&lt;/span&gt; GetReplyDispatchFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (operationDescription.Messages.Count == 1 || operationDescription.Messages[1].Body.ReturnValue.Type == &lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;void&lt;/span&gt;))&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.GetReplyDispatchFormatter(operationDescription, endpoint);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonDispatchFormatter&lt;/span&gt;(operationDescription, &lt;span style="color: #0000ff;"&gt;false&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt; GetRequestClientFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (operationDescription.Behaviors.Find&amp;lt;&lt;span style="color: #2b91af;"&gt;WebGetAttribute&lt;/span&gt;&amp;gt;() != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// no change for GET operations&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.GetRequestClientFormatter(operationDescription, endpoint);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;WebInvokeAttribute&lt;/span&gt; wia = operationDescription.Behaviors.Find&amp;lt;&lt;span style="color: #2b91af;"&gt;WebInvokeAttribute&lt;/span&gt;&amp;gt;();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (wia != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (wia.Method == &lt;span style="color: #a31515;"&gt;"HEAD"&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// essentially a GET operation&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.GetRequestClientFormatter(operationDescription, endpoint);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (operationDescription.Messages[0].Body.Parts.Count == 0)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// nothing in the body, still use the default&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.GetRequestClientFormatter(operationDescription, endpoint);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonClientFormatter&lt;/span&gt;(operationDescription, endpoint);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt; GetReplyClientFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (operationDescription.Messages.Count == 1 || operationDescription.Messages[1].Body.ReturnValue.Type == &lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;void&lt;/span&gt;))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.GetReplyClientFormatter(operationDescription, endpoint);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonClientFormatter&lt;/span&gt;(operationDescription, endpoint);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;On to the formatters. I&amp;rsquo;ll start with the dispatch formatter. As the new formatter was only added for POST operations with at least one parameter, we can safely assume that the messages will not be empty, and the request will be stored in the message body. But the message body is always represented in XML, so in order to support a custom format, we need to either define a mapping between that format and XML (which is what was done internally for supporting JSON in 3.5) &amp;ndash; and implement XML readers and writers to support this mapping &amp;ndash; or reuse one of the existing formats for which we already have a mapping for. And as in the raw programming model, the raw format (described in the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx"&gt;post about message inspectors&lt;/a&gt;) is a great candidate for it &amp;ndash; we can get the raw bytes from the request (and write raw bytes in the response) and parse them using our custom format. We must ensure, however, that the incoming message actually was read with the raw encoder (by default messages with JSON content type are read with the JSON encoder, we need a custom content type mapper to ensure that they are read as raw messages).&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c2c6fb1f-ae0b-421e-927d-0bd6b3e61f93" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonDispatchFormatter&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IDispatchMessageFormatter&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operation;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt;&amp;gt; parameterNames;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; NewtonsoftJsonDispatchFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operation, &lt;span style="color: #0000ff;"&gt;bool&lt;/span&gt; isRequest)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.operation = operation;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (isRequest)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; operationParameterCount = operation.Messages[0].Body.Parts.Count;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (operationParameterCount &amp;gt; 1)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.parameterNames = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt;&amp;gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; operationParameterCount; i++)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.parameterNames.Add(operation.Messages[0].Body.Parts[i].Name, i);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; DeserializeRequest(&lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; message, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; bodyFormatProperty;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (!message.Properties.TryGetValue(&lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;.Name, &lt;span style="color: #0000ff;"&gt;out&lt;/span&gt; bodyFormatProperty) ||&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(bodyFormatProperty &lt;span style="color: #0000ff;"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;).Format != &lt;span style="color: #2b91af;"&gt;WebContentFormat&lt;/span&gt;.Raw)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"Incoming messages must have a body format of Raw. Is a ContentTypeMapper set on the WebHttpBinding?"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;XmlDictionaryReader&lt;/span&gt; bodyReader = message.GetReaderAtBodyContents();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bodyReader.ReadStartElement(&lt;span style="color: #a31515;"&gt;"Binary"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[] rawBody = bodyReader.ReadContentAsBase64();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt;(rawBody);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;StreamReader&lt;/span&gt; sr = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;StreamReader&lt;/span&gt;(ms);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt; serializer = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (parameters.Length == 1)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// single parameter, assuming bare&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parameters[0] = serializer.Deserialize(sr, operation.Messages[0].Body.Parts[0].Type);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// multiple parameter, needs to be wrapped&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonReader&lt;/span&gt; reader = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonTextReader&lt;/span&gt;(sr);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Read();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (reader.TokenType != Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonToken&lt;/span&gt;.StartObject)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"Input needs to be wrapped in an object"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Read();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;while&lt;/span&gt; (reader.TokenType == Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonToken&lt;/span&gt;.PropertyName)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; parameterName = reader.Value &lt;span style="color: #0000ff;"&gt;as&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Read();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.parameterNames.ContainsKey(parameterName))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; parameterIndex = &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.parameterNames[parameterName];&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parameters[parameterIndex] = serializer.Deserialize(reader, &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.operation.Messages[0].Body.Parts[parameterIndex].Type);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Skip();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Read();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Close();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr.Close();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ms.Close();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; SerializeReply(&lt;span style="color: #2b91af;"&gt;MessageVersion&lt;/span&gt; messageVersion, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] parameters, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; result)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[] body;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt; serializer = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt;())&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;StreamWriter&lt;/span&gt; sw = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;StreamWriter&lt;/span&gt;(ms, &lt;span style="color: #2b91af;"&gt;Encoding&lt;/span&gt;.UTF8))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonWriter&lt;/span&gt; writer = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonTextWriter&lt;/span&gt;(sw))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Formatting = Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;Formatting&lt;/span&gt;.Indented;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;serializer.Serialize(writer, result);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sw.Flush();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;body = ms.ToArray();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; replyMessage = &lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt;.CreateMessage(messageVersion, operation.Messages[1].Action, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;RawBodyWriter&lt;/span&gt;(body));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replyMessage.Properties.Add(&lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;.Name, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;WebContentFormat&lt;/span&gt;.Raw));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;HttpResponseMessageProperty&lt;/span&gt; respProp = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;HttpResponseMessageProperty&lt;/span&gt;();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;respProp.Headers[&lt;span style="color: #2b91af;"&gt;HttpResponseHeader&lt;/span&gt;.ContentType] = &lt;span style="color: #a31515;"&gt;"application/json"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replyMessage.Properties.Add(&lt;span style="color: #2b91af;"&gt;HttpResponseMessageProperty&lt;/span&gt;.Name, respProp);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; replyMessage;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When the formatter is serializing the reply of the message , it will create a new message using a &amp;ldquo;raw&amp;rdquo; body writer, which is a simple implementation of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.bodywriter.aspx"&gt;BodyWriter&lt;/a&gt; class. It will then set the body format property to ensure that the raw encoder will be used when converting that message into bytes on the wire.&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ebb335bf-af5a-4f43-8803-f4d0b73c179f" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;RawBodyWriter&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;BodyWriter&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[] content;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; RawBodyWriter(&lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[] content)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.content = content;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; OnWriteBodyContents(&lt;span style="color: #2b91af;"&gt;XmlDictionaryWriter&lt;/span&gt; writer)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteStartElement(&lt;span style="color: #a31515;"&gt;"Binary"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteBase64(content, 0, content.Length);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteEndElement();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The client formatter is similar to the service one. On reply, since it doesn&amp;rsquo;t support multiple return values (no out/ref support implemented), it simply gets the bytes from the message and feeds them to the JSON.NET deserializer. When serializing the request, the formatter will either simply serialize a single parameter if it&amp;rsquo;s the only one, or it will wrap it in a JSON object with properties named by the operation parameter name. The last thing it does on serialization is to again set the body format property (to ensure that the raw encoder will be used for that message) and also set the &amp;ldquo;To&amp;rdquo; header of the message (which is required for REST messages, since it uses manual addressing on the transport).&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ec20db00-3bf9-48ee-9fee-f6cda2daf24f" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonClientFormatter&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IClientMessageFormatter&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operation;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Uri&lt;/span&gt; operationUri;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; NewtonsoftJsonClientFormatter(&lt;span style="color: #2b91af;"&gt;OperationDescription&lt;/span&gt; operation, &lt;span style="color: #2b91af;"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.operation = operation;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; endpointAddress = endpoint.Address.Uri.ToString();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (!endpointAddress.EndsWith(&lt;span style="color: #a31515;"&gt;"/"&lt;/span&gt;))&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;endpointAddress = endpointAddress + &lt;span style="color: #a31515;"&gt;"/"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.operationUri = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Uri&lt;/span&gt;(endpointAddress + operation.Name);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; DeserializeReply(&lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; message, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; bodyFormatProperty;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (!message.Properties.TryGetValue(&lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;.Name, &lt;span style="color: #0000ff;"&gt;out&lt;/span&gt; bodyFormatProperty) ||&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(bodyFormatProperty &lt;span style="color: #0000ff;"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;).Format != &lt;span style="color: #2b91af;"&gt;WebContentFormat&lt;/span&gt;.Raw)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"Incoming messages must have a body format of Raw. Is a ContentTypeMapper set on the WebHttpBinding?"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;XmlDictionaryReader&lt;/span&gt; bodyReader = message.GetReaderAtBodyContents();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt; serializer = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bodyReader.ReadStartElement(&lt;span style="color: #a31515;"&gt;"Binary"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[] body = bodyReader.ReadContentAsBase64();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt;(body))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;StreamReader&lt;/span&gt; sr = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;StreamReader&lt;/span&gt;(ms))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Type&lt;/span&gt; returnType = &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.operation.Messages[1].Body.ReturnValue.Type;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; serializer.Deserialize(sr, returnType);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; SerializeRequest(&lt;span style="color: #2b91af;"&gt;MessageVersion&lt;/span&gt; messageVersion, &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;byte&lt;/span&gt;[] body;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt; serializer = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonSerializer&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MemoryStream&lt;/span&gt;())&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;StreamWriter&lt;/span&gt; sw = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;StreamWriter&lt;/span&gt;(ms, &lt;span style="color: #2b91af;"&gt;Encoding&lt;/span&gt;.UTF8))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; (Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonWriter&lt;/span&gt; writer = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;JsonTextWriter&lt;/span&gt;(sw))&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Formatting = Newtonsoft.Json.&lt;span style="color: #2b91af;"&gt;Formatting&lt;/span&gt;.Indented;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (parameters.Length == 1)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #008000;"&gt;// Single parameter, assuming bare&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;serializer.Serialize(sw, parameters[0]);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteStartObject();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.operation.Messages[0].Body.Parts.Count; i++)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WritePropertyName(&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;.operation.Messages[0].Body.Parts[i].Name);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;serializer.Serialize(writer, parameters[0]);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteEndObject();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Flush();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sw.Flush();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;body = ms.ToArray();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; requestMessage = &lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt;.CreateMessage(messageVersion, operation.Messages[0].Action, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;RawBodyWriter&lt;/span&gt;(body));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;requestMessage.Headers.To = operationUri;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;requestMessage.Properties.Add(&lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;.Name, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebBodyFormatMessageProperty&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;WebContentFormat&lt;/span&gt;.Raw));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;HttpRequestMessageProperty&lt;/span&gt; reqProp = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;HttpRequestMessageProperty&lt;/span&gt;();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reqProp.Headers[&lt;span style="color: #2b91af;"&gt;HttpRequestHeader&lt;/span&gt;.ContentType] = &lt;span style="color: #a31515;"&gt;"application/json"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;requestMessage.Properties.Add(&lt;span style="color: #2b91af;"&gt;HttpRequestMessageProperty&lt;/span&gt;.Name, reqProp);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; requestMessage;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now for testing the formatters. The first thing we need is the content type mapper, to ensure that all incoming requests will be read by the raw encoder. Its implementation is quite simple.&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:63c5bb2b-0f20-42e0-9d50-7a255936e564" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyRawMapper&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;WebContentTypeMapper&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebContentFormat&lt;/span&gt; GetMessageFormatForContentType(&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; contentType)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebContentFormat&lt;/span&gt;.Raw;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now for the test itself. I&amp;rsquo;m using a helper method (SendRequest) to send arbitrary HTTP requests to the server, but I&amp;rsquo;ll skip it here (it&amp;rsquo;s just setting up HttpWebRequest and displaying the results from HttpWebResponse). The test code sets up a service and adds two endpoints, one &amp;ldquo;normal&amp;rdquo; (SOAP) and one JSON.NET enabled&lt;/p&gt;
&lt;div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7d13e0b3-3ba3-4030-b113-056e68c3cc68" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 300px; overflow: auto;"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;[] args)&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color: #a31515;"&gt;"http://"&lt;/span&gt; + &lt;span style="color: #2b91af;"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color: #a31515;"&gt;":8000/Service"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;Service&lt;/span&gt;), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.AddServiceEndpoint(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color: #a31515;"&gt;"soap"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;WebHttpBinding&lt;/span&gt; webBinding = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebHttpBinding&lt;/span&gt;();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;webBinding.ContentTypeMapper = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyRawMapper&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.AddServiceEndpoint(&lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;), webBinding, &lt;span style="color: #a31515;"&gt;"json"&lt;/span&gt;).Behaviors.Add(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonBehavior&lt;/span&gt;());&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515;"&gt;"Opening the host"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.Open();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;&amp;gt; factory = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;&amp;gt;(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;EndpointAddress&lt;/span&gt;(baseAddress + &lt;span style="color: #a31515;"&gt;"/soap"&lt;/span&gt;));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(proxy.GetPerson());&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SendRequest(baseAddress + &lt;span style="color: #a31515;"&gt;"/json/GetPerson"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"GET"&lt;/span&gt;, &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SendRequest(baseAddress + &lt;span style="color: #a31515;"&gt;"/json/EchoPet"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"POST"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"application/json"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"{\"Name\":\"Fido\",\"Color\":\"Black and white\",\"Markings\":\"None\",\"Id\":1}"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SendRequest(baseAddress + &lt;span style="color: #a31515;"&gt;"/json/Add"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"POST"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"application/json"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"{\"x\":111,\"z\":null,\"w\":[1,2],\"v\":{\"a\":1},\"y\":222}"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515;"&gt;"Now using the client formatter"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;&amp;gt; newFactory = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt;&amp;gt;(webBinding, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;EndpointAddress&lt;/span&gt;(baseAddress + &lt;span style="color: #a31515;"&gt;"/json"&lt;/span&gt;));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newFactory.Endpoint.Behaviors.Add(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NewtonsoftJsonBehavior&lt;/span&gt;());&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ITestService&lt;/span&gt; newProxy = newFactory.CreateChannel();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(newProxy.Add(444, 555));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(newProxy.EchoPet(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Pet&lt;/span&gt; { Color = &lt;span style="color: #a31515;"&gt;"gold"&lt;/span&gt;, Id = 2, Markings = &lt;span style="color: #a31515;"&gt;"Collie"&lt;/span&gt;, Name = &lt;span style="color: #a31515;"&gt;"Lassie"&lt;/span&gt; }));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(newProxy.GetPerson());&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515;"&gt;"Press ENTER to close"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.ReadLine();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.Close();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515;"&gt;"Host closed"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And that&amp;rsquo;s it for the formatter example!&lt;/p&gt;
&lt;h3&gt;New WCF Web API&lt;/h3&gt;
&lt;p&gt;One note that I want to leave here is that it&amp;rsquo;s not too easy to integrate any new formats in the existing WCF REST pipeline. In the example above I had to deal with formatters, Message objects, take a dependency on a content type mapper, just to be able to use this different serializer. And even after all of this, it&amp;rsquo;s not completely integrated with the pipeline &amp;ndash; UriTemplates aren&amp;rsquo;t supported, for example. In an upcoming release, however, the WCF team is working hard to make WCF really a great platform for hosting HTTP services, and that includes a new platform (built on top of the current one) for HTTP services specifically. In the new WCF Web API (you can preview the bits on the &lt;a href="http://wcf.codeplex.com/wikipage?title=WCF HTTP"&gt;Codeplex site&lt;/a&gt;) implementing such a scenario is a lot simpler, and other features (such as UriTemplate) will just continue to work after the new formatter is plugged in.&amp;nbsp;&lt;a href="http://twitter.com/gblock"&gt;Glenn Block&lt;/a&gt; has posted a formatter that does exactly that on the thread&amp;nbsp;&lt;a href="http://wcf.codeplex.com/discussions/255873"&gt;http://wcf.codeplex.com/discussions/255873&lt;/a&gt;, you decide which one is easier :)&lt;/p&gt;
&lt;h3&gt;Coming up&lt;/h3&gt;
&lt;p&gt;Operation selectors.&lt;/p&gt;
&lt;p&gt;[&lt;a href="http://code.msdn.microsoft.com/Supporting-different-data-b0351c9a"&gt;Code for this post&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;Carlos Figueira    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;    &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figueira&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10160522" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Extensibility/">Extensibility</category></item><item><title>How to detect if the .NET Framework Platform Update 1 is installed</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/29/how-to-detect-if-the-net-framework-platform-update-1-is-installed.aspx</link><pubDate>Fri, 29 Apr 2011 20:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10159624</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10159624</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/29/how-to-detect-if-the-net-framework-platform-update-1-is-installed.aspx#comments</comments><description>&lt;h1&gt;Humans&lt;/h1&gt;
&lt;p&gt;Go to Control Panel / Programs / Programs and Features / View Installed Updates&lt;/p&gt;
&lt;p&gt;Use the Search Box to search the updates for &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://support.microsoft.com/kb/2495593"&gt;KB2495593&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://support.microsoft.com/kb/2478063"&gt;KB2478063&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/8424.SNAGHTML16a27c2_5F00_59E3C500.png"&gt;&lt;img height="277" width="504" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/3247.SNAGHTML16a27c2_5F00_thumb_5F00_6749D806.png" alt="SNAGHTML16a27c2" border="0" title="SNAGHTML16a27c2" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Or if you prefer, search the list your self&lt;/p&gt;
&lt;h3&gt;Microsoft .NET Framework 4 Platform Update 1 - Runtime Update &lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Look for .NET Framework 4 Extended &lt;/li&gt;
&lt;li&gt;Look for &lt;strong&gt;Update for Microsoft .NET Framework 4 Extended (KB2478063)&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;Click on the &lt;a href="http://support.microsoft.com/kb/2478063"&gt;Help Link&lt;/a&gt; to see what you get with this update &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/3250.SNAGHTML1612b2b_5F00_068C7EDA.png"&gt;&lt;img height="277" width="504" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-03-60-metablogapi/6371.SNAGHTML1612b2b_5F00_thumb_5F00_2C822F30.png" alt="SNAGHTML1612b2b" border="0" title="SNAGHTML1612b2b" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Microsoft .NET Framework 4 Platform Update 1 &amp;ndash; Design-time Package for Visual Studio 2010 SP1 (&lt;a href="http://support.microsoft.com/kb/2495593"&gt;KB2495593&lt;/a&gt;)&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Look for Microsoft Visual Studio 2010 (&amp;lt;Your Edition) &amp;ndash; (&amp;lt;Language&amp;gt;) (&lt;a href="http://support.microsoft.com/kb/2495593"&gt;KB2495593&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;Click on the &lt;a href="http://support.microsoft.com/kb/2495593"&gt;Help Link&lt;/a&gt; to see what this update contains &lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;Programs&lt;/h1&gt;
&lt;p&gt;Look in the registry for the following keys&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NET Framework\v4.0.30319\SKUs\&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;.NETFramework, Version=v4.0.1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;.NETFramework, Version-v4.0.1, Profile=Client&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Ron Jacobs &lt;br /&gt;&lt;a href="http://blogs.msdn.com/rjacobs"&gt;http://blogs.msdn.com/rjacobs&lt;/a&gt; &lt;br /&gt;Twitter: @ronljacobs &lt;a href="http://twitter.com/ronljacobs"&gt;http://twitter.com/ronljacobs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10159624" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF4/">WF4</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Platform+Update+1/">Platform Update 1</category></item><item><title>WCF Extensibility – IParameterInspector</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/28/wcf-extensibility-iparameterinspector.aspx</link><pubDate>Thu, 28 Apr 2011 15:05:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10159152</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10159152</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/28/wcf-extensibility-iparameterinspector.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;&lt;em&gt;index page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The message inspectors, described in the previous post of this series, allows you complete control over the message going through the WCF stack. They’re very powerful, but you have to know how to deal with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;Message&lt;/a&gt; object, which is not the most desirable way of programming. If the service model in WCF hides all the messaging framework by allowing us to define our services in terms of strongly-typed operations (i.e., using nice primitive and user defined types), there should be a way of intercepting requests / responses after all the processing to extract those parameters from incoming messages (or before they’re packaged in outgoing messages) is done. The &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.aspx"&gt;IParameterInspector&lt;/a&gt; is exactly that – before and after each call, the inspector gets a chance to inspect the operation inputs, outputs and return value, in the same types as defined by the operation contract, no conversion needed (the only thing needed is a cast, since the parameters are passed as objects).&lt;/p&gt;  &lt;h3&gt;Public implementations in WCF&lt;/h3&gt;  &lt;p&gt;None. There aren’t also any internal implementations of this interface in WCF, this is really a user (as opposed to system) extensibility point.&lt;/p&gt;  &lt;h3&gt;Interface declaration&lt;/h3&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:94d1623a-9262-40d7-9110-4a5ab1eb2d1e" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IParameterInspector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; returnValue, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Unlike the message inspector, the parameter inspector interface is the same for both client and server side. At the server side, right before the call is dispatched to the user code, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.beforecall.aspx"&gt;BeforeCall&lt;/a&gt; is invoked, where the inspector can look at the inputs to the operation. When the operation returns, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.aftercall.aspx"&gt;AfterCall&lt;/a&gt; is invoked to let the inspector look at the return value of the operation, and any out/ref parameters which the operation may have set. At the client side, right after the call on the proxy is made, and before it’s handed down to the WCF stack, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.beforecall.aspx"&gt;BeforeCall&lt;/a&gt; is invoked to let the inspector look at the outgoing parameters before they’re packaged into a message object. Finally, when the call returns from the server and the result is about to be returned to the client (either by returning the synchronous invocation or in an asynchronous callback), &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.aftercall.aspx"&gt;AfterCall&lt;/a&gt; is called at the client side.&lt;/p&gt;  &lt;p&gt;Like in the message inspector case, if the operation contract being called by the client is marked with IsOneWay=true, the call to AfterCall on a client inspector does not happen (it does happen at the server, though). And unlike the message inspector case, if an exception is thrown during the processing of the call (e.g., the server returned a fault), AfterCall will also not be called on the client – it makes sense, since there is no guarantees that the return value or any out/ref parameters have valid values at that point.&lt;/p&gt;  &lt;h3&gt;How to add parameter inspectors&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;At the server side&lt;/strong&gt;: the list of parameter inspectors is available at the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.dispatchoperation.aspx"&gt;DispatchOperation&lt;/a&gt; object – each operation has its own list of parameter inspectors. It is typically accessed via an operation behavior in a call to &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.applydispatchbehavior.aspx"&gt;ApplyDispatchBehavior&lt;/a&gt;:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4fce33ed-e3d7-42cd-86a6-7b8a1d0627ff" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Attribute&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;DispatchOperation&lt;/span&gt; dispatchOperation)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        dispatchOperation.ParameterInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyParameterInspector&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;At the client side&lt;/strong&gt;: the list of client parameter inspectors is available at the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.clientoperation.aspx"&gt;ClientOperation&lt;/a&gt; object, and typically accessed via an operation behavior’s &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.applyclientbehavior.aspx"&gt;ApplyClientBehavior&lt;/a&gt; method.. &lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f1e3d4a1-ebde-4f62-bf95-813551496420" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IOperationBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;ClientOperation&lt;/span&gt; clientOperation)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        clientOperation.ParameterInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyParameterInspector&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Real world scenario: simple profiler&lt;/h3&gt;  &lt;p&gt;One usage which I’ve seen a couple of times for the parameter inspector is to create a simple profiler / statistics page for WCF services. The parameter inspector interface methods are called really close to the actual method invocation (as can be seen in the example of the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/18/wcf-extensibility-runtime.aspx"&gt;WCF Runtime post&lt;/a&gt;), both on the client and on the server, so they can fairly accurately record starting and ending times of arbitrary method calls. The example below is implemented as an endpoint behavior which adds the statistic collection logic for all the operations in the endpoint. In this example, we need to call a method on a class to show the statistics, but a more realistic scenario would save the profiling information in a file or database for further analysis.&lt;/p&gt;  &lt;p&gt;And here comes the usual disclaimer: this is a sample for illustrating the topic of this post, this is not production-ready code. I tested it for a few contracts and it worked, but I cannot guarantee that it will work for all scenarios (please let me know if you find a bug or something missing). Also, for simplicity sake it doesn’t have a lot of error handling which a production-level code would. Also, as I mentioned before, the statistics are all stored in memory, a better profiler would save the profiling information in a file or database, and possibly even expose it as a service itself.&lt;/p&gt;  &lt;p&gt;As with all of the runtime examples, it starts with a behavior. I’ll use an endpoint behavior here, but a contract (or even service) behavior would do.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:03bd0a52-c4ea-420a-b58e-ad33c671bc36" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerEndpointBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerManager&lt;/span&gt; manager;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; OperationProfilerEndpointBehavior(&lt;span style="color:#2b91af"&gt;OperationProfilerManager&lt;/span&gt; manager)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.manager = manager;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;ClientOperation&lt;/span&gt; operation &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; clientRuntime.Operations)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            operation.ParameterInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerParameterInspector&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.manager, operation.IsOneWay));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;DispatchOperation&lt;/span&gt; operation &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; endpointDispatcher.DispatchRuntime.Operations)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            operation.ParameterInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerParameterInspector&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.manager, operation.IsOneWay));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The behavior takes a “manager” as a parameter. The manager is the entity which will, in this example, store the call information for all the operations in the contract. It can then be invoked to display a summary of the statistics for the calls (I’ll omit most of the formatting methods here, you can find them in the code for this post, linked below).&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:765ea4ce-1db2-44ee-8109-77debda3f62b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerManager&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&amp;gt;&amp;gt; callsPerOperation;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; OperationProfilerManager()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.callsPerOperation = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&amp;gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddOneWayCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&amp;gt; callTimes;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.callsPerOperation.ContainsKey(operationName))&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            callTimes = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.callsPerOperation[operationName];&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            callTimes = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.callsPerOperation.Add(operationName, callTimes);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        callTimes.Add(-1);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;double&lt;/span&gt; duration)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&amp;gt; callTimes;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.callsPerOperation.ContainsKey(operationName))&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            callTimes = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.callsPerOperation[operationName];&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            callTimes = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.callsPerOperation.Add(operationName, callTimes);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        callTimes.Add(duration);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Notice that there are two methods to add information about an operation call. For “normal” operations, we provide the duration of the call, but for one-way operations, this information cannot be retrieved (esp. at the client side, since the control will return to the caller almost as if the call was made asynchronously). Next we’ll get to the inspector itself. It’s implementation is actually fairly simple, as it registers the time in which BeforeCall was invoked, and returns it as the correlation state to be passed to the AfterCall method (unless the operation is one-way, in which case we simply register such a call in the manager). There, we again register the time and take the difference between the two times to calculate the duration of the method, then store it in the manager.&lt;/p&gt;  &lt;p&gt;And that’s it – this nothing else needed. Now for testing I’ll define a service with some operations which take a certain amount of time (simulated using a random generator), and some “fast” ones (again I’ll skip the definition of the data contracts used in the service, as they’re not relevant to the topic, but they can be found in the code for this post, linked below).&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:52f47f42-1a4b-438b-a45e-73b6296f62ab" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; ProcessOrder(&lt;span style="color:#2b91af"&gt;Order&lt;/span&gt; order);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;(IsOneWay = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ProcessOneWay(&lt;span style="color:#2b91af"&gt;Order&lt;/span&gt; order);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Service&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Random&lt;/span&gt; rndGen = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Random&lt;/span&gt;(1);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; x + y;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; ProcessOrder(&lt;span style="color:#2b91af"&gt;Order&lt;/span&gt; order)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Thread&lt;/span&gt;.Sleep(rndGen.Next(1, 100));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; order.Id;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ProcessOneWay(&lt;span style="color:#2b91af"&gt;Order&lt;/span&gt; order)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Thread&lt;/span&gt;.Sleep(rndGen.Next(1, 100));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;And finally, hosting the program to see the simple profiler in action:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3b46a651-8766-42ec-bf42-10ac84b4ba2e" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;&amp;quot;http://&amp;quot;&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;&amp;quot;:8000/Service&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Service&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;OperationProfilerManager&lt;/span&gt; serverProfilerManager = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerManager&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;    endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerEndpointBehavior&lt;/span&gt;(serverProfilerManager));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Opening the host&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    host.Open();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt;(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(baseAddress));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;OperationProfilerManager&lt;/span&gt; clientProfilerManager = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerManager&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;    factory.Endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OperationProfilerEndpointBehavior&lt;/span&gt;(clientProfilerManager));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Order&lt;/span&gt; oneOrder = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Order&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Id = 1,&lt;/li&gt; &lt;li&gt;        Client = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Person&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            Name = &lt;span style="color:#a31515"&gt;&amp;quot;John Doe&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            Address = &lt;span style="color:#a31515"&gt;&amp;quot;111 223th Ave&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        },&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Items = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;OrderItem&lt;/span&gt;&amp;gt;&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OrderItem&lt;/span&gt; { Name = &lt;span style="color:#a31515"&gt;&amp;quot;bread&amp;quot;&lt;/span&gt;, Unit = &lt;span style="color:#a31515"&gt;&amp;quot;un&amp;quot;&lt;/span&gt;, UnitPrice = 0.56, Amount = 3 },&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OrderItem&lt;/span&gt; { Name = &lt;span style="color:#a31515"&gt;&amp;quot;milk&amp;quot;&lt;/span&gt;, Unit = &lt;span style="color:#a31515"&gt;&amp;quot;gal&amp;quot;&lt;/span&gt;, UnitPrice = 2.79, Amount = 1 },&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;OrderItem&lt;/span&gt; { Name = &lt;span style="color:#a31515"&gt;&amp;quot;eggs&amp;quot;&lt;/span&gt;, Unit = &lt;span style="color:#a31515"&gt;&amp;quot;doz&amp;quot;&lt;/span&gt;, UnitPrice = 2.23, Amount = 1 },&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    };&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Calling some operations...&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 200; i++)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        proxy.Add(i, i * i);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; ((i % 3) == 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            proxy.ProcessOneWay(oneOrder);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            proxy.ProcessOrder(oneOrder);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Now printing statistics (server)&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    serverProfilerManager.PrintSummary();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Now printing statistics (client)&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    clientProfilerManager.PrintSummary();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Press ENTER to close&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/li&gt; &lt;li&gt;    host.Close();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Host closed&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;h3&gt;Coming up&lt;/h3&gt;  &lt;p&gt;Client and server (dispatch) message formatters, with an example showing how to send / receive arbitrary data without using the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx"&gt;WCF REST Raw programming model&lt;/a&gt; – this issue came up at the forums a few weeks back.&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://code.msdn.microsoft.com/Simple-WCF-operation-e8d52375"&gt;Code for this post&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;Carlos Figueira    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;    &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figueira&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10159152" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Extensibility/">Extensibility</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item><item><title>Programmatically calling validation in a rehosted Workflow 4 designer</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/27/programmatically-calling-validation-in-a-rehosted-workflow-4-designer.aspx</link><pubDate>Wed, 27 Apr 2011 21:11:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10158814</guid><dc:creator>Patrick D. Fletcher [MSFT]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10158814</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/27/programmatically-calling-validation-in-a-rehosted-workflow-4-designer.aspx#comments</comments><description>&lt;p&gt;The workflow designer has a rich programming model that supports communication with the host. A rehosted workflow designer will automatically validate a workflow when it is changed; in order to programmatically call validation on demand on a rehosted designer, use the following method:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;designer.Context.Services.GetService&amp;lt;ValidationService&amp;gt;().ValidateWorkflow();&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To handle resulting validation errors, publish an implementation of IValidationErrorService, which will expose the set of errors through ValidationService.NavigateTo(). For information on how to do this, see the following topic:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff521568.aspx"&gt;How to: Display Validation Errors in a Rehosted Designer&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10158814" width="1" height="1"&gt;</description></item><item><title>How to create a WF4 WorkflowServiceHostFactory for AppFabric Auto-Start</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/27/how-to-create-a-wf4-workflowservicehostfactory-for-appfabric-auto-start.aspx</link><pubDate>Wed, 27 Apr 2011 20:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10158783</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10158783</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/27/how-to-create-a-wf4-workflowservicehostfactory-for-appfabric-auto-start.aspx#comments</comments><description>&lt;p&gt;Sometimes when using Windows Workflow Foundation (WF4) you need to create a custom WorkflowServiceHostFactory.&amp;nbsp; There are a couple of main reasons why you would want to do this.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To configure the WorklfowServiceHost in some way like adding an extension &lt;/li&gt;
&lt;li&gt;To do some other type of initialization work when auto starting a service &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This morning I was working on the WF4 Batch Processing Example (now &lt;a href="http://code.msdn.microsoft.com/Windows-Workflow-6b4ffbe8"&gt;Workflow Services and Auto-Start&lt;/a&gt; sample) to update it with things I&amp;rsquo;ve learned in the past few months.&amp;nbsp; I decided to create a custom WorkflowServiceHostFactory in order to take advantage of the Windows Server AppFabric Auto-Start capability.&lt;/p&gt;
&lt;p&gt;
&lt;object height="288" type="application/x-silverlight-2" width="512" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAJAADqNAAAxB0AAAAAAAAAAAAAAAAAAAAAAAACAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAABgAAAA0AC4AMAAuADUAMAA0ADAAMQAuADAAAAAAAAAAAAAAAAAAAAAAAAAA"&gt;
&lt;param value="4.0.50401.0" name="minRuntimeVersion" /&gt;
&lt;param name="source" /&gt;
&lt;param name="initParams" /&gt;
&lt;/object&gt;
&lt;/p&gt;
&lt;h3&gt;Step 1: Create a class that inherits from WorkflowServiceHostFactory&lt;/h3&gt;
&lt;p&gt;This sounds like a simple step right?&amp;nbsp; The question is&amp;hellip; which WorkflowServiceHostFactory?&amp;nbsp; That&amp;rsquo;s right&amp;hellip; beware because there is more than one in the .NET Framework&lt;/p&gt;
&lt;p&gt;I use Resharper because it is an amazing time saving tool but in this case it led me down the path to disaster because it works so well.&amp;nbsp; When Resharper sees a class it doesn&amp;rsquo;t understand it quite helpfully gives you some options.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/2816.image_5F00_6467CC43.png"&gt;&lt;img height="149" width="708" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/4786.image_5F00_thumb_5F00_75D82D1B.png" alt="image" border="0" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Because I was in a hurry I quickly selected the first option and then spent the next 2 hours struggling to understand why it didn&amp;rsquo;t work.&amp;nbsp; Had I looked carefully I would have noticed the problem right away.&amp;nbsp; System.WorkflowServices.WorkflowServiceHostFactory is from WF 3.5.&amp;nbsp; What I should be using is System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory from WF4.&lt;/p&gt;
&lt;p&gt;Typically when you get confused about things between WF3 and WF4 you will find that they simply won&amp;rsquo;t compile but in this case the WF3 WorkflowServiceHost factory will happily compile even in the very strange case where you &amp;ldquo;use&amp;rdquo; the namespace from WF4 and reference the assembly from WF3.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Why does this work?&amp;nbsp; Because the two classes do the same thing.&amp;nbsp; They both inherit from ServiceHostBase and override the CreateServiceHost method.&lt;/p&gt;
&lt;p&gt;However, if you use the wrong one you will get this exception &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The service '/BatchWeb/BWS2.xamlx' cannot be activated due to an exception during compilation.&amp;nbsp; The exception message is: The file '/BatchWeb/BWS2.xamlx' does not exist..&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Make sure you reference &lt;strong&gt;System.ServiceModel.Activation&lt;/strong&gt; and use &lt;strong&gt;System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Then you can implement your factory class.&amp;nbsp; In my case I needed to update the WF4 Batch Job example because it relied on code in the Application_Start method to read the config file and start a batch job.&amp;nbsp; At the time I thought this would be invoked when the system booted and automatically start a job.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;When I tested the app it appeared to work but only because there were already persisted jobs with durable timers pending.&amp;nbsp; At boot time the Workflow Management Service would activate the app by sending a message to activate the jobs because of the timer.&amp;nbsp; So it had the illusion of working but actually if there were no jobs with persisted timers the AppPool would never start the app. &lt;/p&gt;
&lt;p&gt;When I dug deep into how AutoStart actually works I wrote &lt;a href="http://blogs.msdn.com/b/rjacobs/archive/2010/12/09/wcf-and-appfabric-autostart.aspx"&gt;WCF and AppFabric Auto-Start&lt;/a&gt; and said that the only way you can run code that is triggered by the AppFabric Service Auto-Start function is to use a custom service host factory.&lt;/p&gt;
&lt;p&gt;In my code what I want to do is on the first start read the configuration file and send a request to submit a new batch job.&amp;nbsp; This is done every time a new instance of the AppPool starts up.&amp;nbsp; This means at boot time but also any time the AppPool recycles.&amp;nbsp; This ensures that there is always at least one of the workflows running and for short periods of time more than one during a recycle.&lt;/p&gt;
&lt;p&gt;In my factory I need to send a message to the service that will be hosted.&amp;nbsp; Obviously I can&amp;rsquo;t send the message before returning the host so I&amp;rsquo;m using Task.Factory.StartNew to dispatch the work to a different thread.&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;"&gt;
&lt;div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum1" style="color: #606060;"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;override&lt;/span&gt; ServiceHostBase CreateServiceHost(&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; constructorString, Uri[] baseAddresses)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum2" style="color: #606060;"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum3" style="color: #606060;"&gt;   3:&lt;/span&gt;     &lt;span style="color: #008000;"&gt;// Run the auto start check on another thread.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum4" style="color: #606060;"&gt;   4:&lt;/span&gt;     Task.Factory.StartNew(CheckAutoStartJobs);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum5" style="color: #606060;"&gt;   5:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum6" style="color: #606060;"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;base&lt;/span&gt;.CreateServiceHost(constructorString, baseAddresses);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum7" style="color: #606060;"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then on the other thread, I wait a few seconds, read the config entries and then send a message to the service over a named pipe&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;"&gt;
&lt;div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum1" style="color: #606060;"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; CheckAutoStartJobs()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum2" style="color: #606060;"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum3" style="color: #606060;"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (autoStarted)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum4" style="color: #606060;"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum5" style="color: #606060;"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum6" style="color: #606060;"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum7" style="color: #606060;"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum8" style="color: #606060;"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum9" style="color: #606060;"&gt;   9:&lt;/span&gt;         autoStarted = &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum10" style="color: #606060;"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum11" style="color: #606060;"&gt;  11:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum12" style="color: #606060;"&gt;  12:&lt;/span&gt;     &lt;span style="color: #008000;"&gt;// Wait a few seconds for the host to spin up&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum13" style="color: #606060;"&gt;  13:&lt;/span&gt;     Thread.Sleep(TimeSpan.FromSeconds(5));&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum14" style="color: #606060;"&gt;  14:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum15" style="color: #606060;"&gt;  15:&lt;/span&gt;     &lt;span style="color: #008000;"&gt;// Check for autostart&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum16" style="color: #606060;"&gt;  16:&lt;/span&gt;     var autoCount = ConfigurationManager.AppSettings[&lt;span style="color: #006080;"&gt;"AutoCount"&lt;/span&gt;];&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum17" style="color: #606060;"&gt;  17:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum18" style="color: #606060;"&gt;  18:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(autoCount))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum19" style="color: #606060;"&gt;  19:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum20" style="color: #606060;"&gt;  20:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum21" style="color: #606060;"&gt;  21:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum22" style="color: #606060;"&gt;  22:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum23" style="color: #606060;"&gt;  23:&lt;/span&gt;     var values = autoCount.Split(&lt;span style="color: #006080;"&gt;'|'&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum24" style="color: #606060;"&gt;  24:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum25" style="color: #606060;"&gt;  25:&lt;/span&gt;     &lt;span style="color: #008000;"&gt;// Check for valid value&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum26" style="color: #606060;"&gt;  26:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (values.Length != 2)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum27" style="color: #606060;"&gt;  27:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum28" style="color: #606060;"&gt;  28:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum29" style="color: #606060;"&gt;  29:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum30" style="color: #606060;"&gt;  30:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum31" style="color: #606060;"&gt;  31:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; count;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum32" style="color: #606060;"&gt;  32:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (!Int32.TryParse(values[0], &lt;span style="color: #0000ff;"&gt;out&lt;/span&gt; count))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum33" style="color: #606060;"&gt;  33:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum34" style="color: #606060;"&gt;  34:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum35" style="color: #606060;"&gt;  35:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum36" style="color: #606060;"&gt;  36:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum37" style="color: #606060;"&gt;  37:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; delay;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum38" style="color: #606060;"&gt;  38:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (!Int32.TryParse(values[1], &lt;span style="color: #0000ff;"&gt;out&lt;/span&gt; delay))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum39" style="color: #606060;"&gt;  39:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum40" style="color: #606060;"&gt;  40:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum41" style="color: #606060;"&gt;  41:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum42" style="color: #606060;"&gt;  42:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum43" style="color: #606060;"&gt;  43:&lt;/span&gt;     var request = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; BatchRequest&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum44" style="color: #606060;"&gt;  44:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum45" style="color: #606060;"&gt;  45:&lt;/span&gt;             CountTo = count, &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum46" style="color: #606060;"&gt;  46:&lt;/span&gt;             Delay = TimeSpan.FromSeconds(delay), &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum47" style="color: #606060;"&gt;  47:&lt;/span&gt;             StartAt = DateTime.Now, &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum48" style="color: #606060;"&gt;  48:&lt;/span&gt;             AutoStart = &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum49" style="color: #606060;"&gt;  49:&lt;/span&gt;         };&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum50" style="color: #606060;"&gt;  50:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum51" style="color: #606060;"&gt;  51:&lt;/span&gt;     var proxy = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; BatchWorkerClient(&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum52" style="color: #606060;"&gt;  52:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; NetNamedPipeBinding(), &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum53" style="color: #606060;"&gt;  53:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; EndpointAddress(&lt;span style="color: #006080;"&gt;"net.pipe://localhost/BatchWeb/BatchWorker.xamlx"&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum54" style="color: #606060;"&gt;  54:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum55" style="color: #606060;"&gt;  55:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum56" style="color: #606060;"&gt;  56:&lt;/span&gt;         var response = proxy.SubmitJob(request);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum57" style="color: #606060;"&gt;  57:&lt;/span&gt;         proxy.Close();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum58" style="color: #606060;"&gt;  58:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum59" style="color: #606060;"&gt;  59:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;catch&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum60" style="color: #606060;"&gt;  60:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum61" style="color: #606060;"&gt;  61:&lt;/span&gt;         proxy.Abort();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum62" style="color: #606060;"&gt;  62:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum63" style="color: #606060;"&gt;  63:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum64" style="color: #606060;"&gt;  64:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Step 2: Add ServiceActivation in web.config&lt;/h3&gt;
&lt;p&gt;With a WCF Service you can add a ServiceHostFactory entry in the .SVC file.&amp;nbsp; Workflow Services don&amp;rsquo;t have an SVC file so you will need to edit your web.config to add support for a factory&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;"&gt;
&lt;div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum1" style="color: #606060;"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum2" style="color: #606060;"&gt;   2:&lt;/span&gt; &lt;span style="color: #008000;"&gt;&amp;lt;!-- Other stuff deleted --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum3" style="color: #606060;"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;serviceHostingEnvironment&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum4" style="color: #606060;"&gt;   4:&lt;/span&gt;       &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;serviceActivations&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum5" style="color: #606060;"&gt;   5:&lt;/span&gt;         &lt;span style="color: #008000;"&gt;&amp;lt;!-- Use a Custom WorkflowServiceHostFactory to automatically start the batch jobs--&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum6" style="color: #606060;"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;relativeAddress&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="BatchWorker.xamlx"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="BatchWorker.xamlx"&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;factory&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="BatchWeb.BatchAutoStartFactory"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum7" style="color: #606060;"&gt;   7:&lt;/span&gt;       &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;serviceActivations&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum8" style="color: #606060;"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;serviceHostingEnvironment&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum9" style="color: #606060;"&gt;   9:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"&gt;&lt;span id="lnum10" style="color: #606060;"&gt;  10:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Step 3: Configure Auto-Start&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Open IIS Manager and right click on your web app. &lt;/li&gt;
&lt;li&gt;Select Manage WCF and WF Services / Configure &lt;/li&gt;
&lt;li&gt;Select the Auto-Start tab and choose Enabled &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/0245.SNAGHTML25c5ce_5F00_5C7029E1.png"&gt;&lt;img height="190" width="644" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/3225.SNAGHTML25c5ce_5F00_thumb_5F00_22ED19EA.png" alt="SNAGHTML25c5ce" border="0" title="SNAGHTML25c5ce" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Step 4: Test It&lt;/h3&gt;
&lt;p&gt;To test your service, I recommend you get my &lt;a href="http://archive.msdn.microsoft.com/afdbreset"&gt;AppFabricDBReset&lt;/a&gt; script.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Stop the AppPool that your web site is hosted in &lt;/li&gt;
&lt;li&gt;Run the AppFabricDBReset Script to eliminate any persisted instances &lt;/li&gt;
&lt;li&gt;Start the AppPool &lt;/li&gt;
&lt;li&gt;In a few seconds browse to the site and you will see that an instance of the batch job has been auto started &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Step 5: Get It&lt;/h3&gt;
&lt;p&gt;Download the &lt;a href="http://code.msdn.microsoft.com/Windows-Workflow-6b4ffbe8"&gt;Windows Workflow Foundation (WF4) - Workflow Services and Auto-Start Sample&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Ron Jacobs &lt;br /&gt;&lt;a href="http://blogs.msdn.com/rjacobs"&gt;http://blogs.msdn.com/rjacobs&lt;/a&gt; &lt;br /&gt;Twitter: @ronljacobs &lt;a href="http://twitter.com/ronljacobs"&gt;http://twitter.com/ronljacobs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10158783" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category></item><item><title>WebSockets, RIA/JS and WCF Web API at MIX, a whole lotta love for the web</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/24/websockets-ria-js-and-wcf-web-api-at-mix-a-whole-lotta-love-for-the-web.aspx</link><pubDate>Sun, 24 Apr 2011 11:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10157484</guid><dc:creator>Glenn Block MSFT</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10157484</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/24/websockets-ria-js-and-wcf-web-api-at-mix-a-whole-lotta-love-for-the-web.aspx#comments</comments><description>&lt;p&gt;&lt;img src="http://farm3.static.flickr.com/2634/3867034897_32f913f353_z.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;MIX was &lt;em&gt;indeed&lt;/em&gt; a busy time for the WCF Team. We delivered several talks, and released several shiny new toys to the community for folks that are building web-based systems.&lt;/p&gt;
&lt;h1&gt;WebSockets&lt;/h1&gt;
&lt;p&gt;&lt;a href="http://twitter.com/#!/craigkitterman"&gt;Craig Kitterman&lt;/a&gt; of our Interoperability group, and &lt;a href="http://twitter.com/#!/paulbatum"&gt;Paul Batum&lt;/a&gt;, whom you might &lt;a href="http://www.paulbatum.com/"&gt;know of&lt;/a&gt; from his work on Fluent NHibernate gave a talk: &lt;a href="http://channel9.msdn.com/events/mix/mix11/HTM10"&gt;Hot from the Labs: HTML5 WebSockets&lt;/a&gt;&lt;/p&gt;
&lt;div&gt;
&lt;object height="288" type="application/x-silverlight-2" width="512" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAJAADqNAAAxB0AAAAAAAAAAAAAAAAAAAAAAABoAAAAaAB0AHQAcAA6AC8ALwBjAGgAYQBuAG4AZQBsADkALgBtAHMAZABuAC4AYwBvAG0ALwBzAGMAcgBpAHAAdABzAC8AQwBoAGEAbgBuAGUAbAA5AC4AeABhAHAAPwB2AD0AMQAuADUAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AEAAG0AZQBkAGkAYQB1AHIAbAA9AGgAdAB0AHAAOgAvAC8AcwBtAG8AbwB0AGgALgBjAGgAOQAuAG0AcwAvAGMAaAA5AC8ARABGADAAMAAvADMARQA1ADAANQBFADAAOAAtADMANQA2ADQALQA0ADUAQQAzAC0AOAA2ADYARAAtADkARQBCADYAMAAwADgAMgBEAEYAMAAwAC8ATQBJAFgAMQAxAEgAVABNADEAMAAuAGkAcwBtAC8AbQBhAG4AaQBmAGUAcwB0ACwAdABoAHUAbQBiAG4AYQBpAGwAPQBoAHQAdABwADoALwAvAGYAaQBsAGUAcwAuAGMAaAA5AC4AbQBzAC8AbQBpAHgALwAyADAAMQAxAC8AdABoAHUAbQBiAHMALwBIAFQATQAxADAAXwBsAGcALgBqAHAAZwAsAGQAZQBsAGkAdgBlAHIAeQBtAGUAdABoAG8AZAA9AGEAZABhAHAAdABpAHYAZQBzAHQAcgBlAGEAbQBpAG4AZwAsAGEAdQB0AG8AcABsAGEAeQA9AGYAYQBsAHMAZQAsAGUAbgB0AHIAeQBpAGQAPQAzAGUANQAwADUAZQAwADgAMwA1ADYANAA0ADUAYQAzADgANgA2AGQAOQBlAGIANgAwADAAOAAyAGQAZgAwADAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAGAAAADQALgAwAC4ANQAwADQAMAAxAC4AMAAAAAAAAAAAAAAAAAAAAAAAAAA="&gt;
&lt;param value="4.0.50401.0" name="minRuntimeVersion" /&gt;
&lt;param value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" name="source" /&gt;
&lt;param value="mediaurl=http://smooth.ch9.ms/ch9/DF00/3E505E08-3564-45A3-866D-9EB60082DF00/MIX11HTM10.ism/manifest,thumbnail=http://files.ch9.ms/mix/2011/thumbs/HTM10_lg.jpg,deliverymethod=adaptivestreaming,autoplay=false,entryid=3e505e08356445a3866d9eb60082df00" name="initParams" /&gt;
&lt;/object&gt;
&lt;/div&gt;
&lt;p&gt;In the talk they spoke about new explorations we are doing into supporting WebSockets in the Microsoft Stack. WebSockets is basically sockets for the web, i.e. a way to have a much more responsive in-browser experience. In the talk you&amp;rsquo;ll learn about the work going on in the W3C/IETF around WebSockets and you&amp;rsquo;ll see the exploratory work we&amp;rsquo;ve been doing both at the browser level and on the server to enable a WebSockets experience. I highly recommend this talk, as you&amp;rsquo;ll see is a pattern for the other talks I mention below.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a sneak peak of what the coding experience looks like, which I hope you agree is pretty clean.&lt;/p&gt;
&lt;p&gt;On the client you have code such as the following:&lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;conn.onopen = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; () {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  state.className = 'success';
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  state.innerHTML = 'Socket &lt;span style="color: #0000ff"&gt;open&lt;/span&gt;';
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;};
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;conn.onmessage = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; (event) {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; message = JSON.parse(event.data);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; message == 'string') {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    log.innerHTML = '&amp;lt;li &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;="&lt;span style="color: #8b0000"&gt;them&lt;/span&gt;"&amp;gt;' + 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    message.replace(/[&amp;lt;&amp;gt;&amp;amp;]/g, &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; (m) 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; entities[m]; }) + '&amp;lt;/li&amp;gt;' + log.innerHTML; 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  } &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    connected.innerHTML = message;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;};
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;conn.onclose = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; (event) {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  state.className = 'fail';
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  state.innerHTML = 'Socket &lt;span style="color: #0000ff"&gt;closed&lt;/span&gt;';
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;};&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;The on the server you have a WebSocket service:&lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  ConcurrencyMode = ConcurrencyMode.Multiple)]
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ChatService : WebSocketsService
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  ...
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnMessage(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    ChatService.sessions.RelayMessage(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; GetHashCode()
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.id; 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnClose(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    ChatService.sessions.Remove(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;h1&gt;&lt;span style="font-family: Segoe UI; color: #333333; font-size: small;"&gt;You can download the latest bits of the WebSockets work at &lt;a href="http://html5labs.interoperabilitybridges.com/html5labs/prototypes/websockets/websockets/info/"&gt;the HTML 5 labs WebSockets page&lt;/a&gt;.&lt;/span&gt;&lt;/h1&gt;
&lt;h1&gt;RIA/JS&lt;/h1&gt;
&lt;p&gt;&lt;a href="http://twitter.com/#!/brado_23"&gt;Brad Olenick&lt;/a&gt; of the RIA team delivered a talk: &lt;a href="http://channel9.msdn.com/events/MIX/MIX11/FRM05" title="Building Data-centric N-tier Applications with jQuery"&gt;Building Data-centric N-tier Applications with jQuery&lt;/a&gt;. &lt;/p&gt;
&lt;div&gt;
&lt;object height="288" type="application/x-silverlight-2" width="512" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAJAADqNAAAxB0AAAAAAAAAAAAAAAAAAAAAAABoAAAAaAB0AHQAcAA6AC8ALwBjAGgAYQBuAG4AZQBsADkALgBtAHMAZABuAC4AYwBvAG0ALwBzAGMAcgBpAHAAdABzAC8AQwBoAGEAbgBuAGUAbAA5AC4AeABhAHAAPwB2AD0AMQAuADUAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlAEAAG0AZQBkAGkAYQB1AHIAbAA9AGgAdAB0AHAAOgAvAC8AZgBpAGwAZQBzAC4AYwBoADkALgBtAHMALwBtAGkAeAAvADIAMAAxADEALwB3AG0AdgAvAEYAUgBNADAANQAuAHcAbQB2ACwAdABoAHUAbQBiAG4AYQBpAGwAPQBoAHQAdABwADoALwAvAGYAaQBsAGUAcwAuAGMAaAA5AC4AbQBzAC8AbQBpAHgALwAyADAAMQAxAC8AdABoAHUAbQBiAHMALwBGAFIATQAwADUAXwBsAGcALgBqAHAAZwAsAGQAZQBsAGkAdgBlAHIAeQBtAGUAdABoAG8AZAA9AHAAcgBvAGcAcgBlAHMAcwBpAHYAZQBkAG8AdwBuAGwAbwBhAGQALABhAHUAdABvAHAAbABhAHkAPQBmAGEAbABzAGUALABlAG4AdAByAHkAaQBkAD0AYwA0ADEAZQBjAGQAOQBhAGEAOQA4ADYANAA4ADYAYwA5ADkANAA2ADkAZQBhAGYAMAAwADkAMgBmADgAZQBlAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAABgAAAA0AC4AMAAuADUAMAA0ADAAMQAuADAAAAAAAAAAAAAAAAAAAAAAAAAA"&gt;
&lt;param value="4.0.50401.0" name="minRuntimeVersion" /&gt;
&lt;param value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" name="source" /&gt;
&lt;param value="mediaurl=http://files.ch9.ms/mix/2011/wmv/FRM05.wmv,thumbnail=http://files.ch9.ms/mix/2011/thumbs/FRM05_lg.jpg,deliverymethod=progressivedownload,autoplay=false,entryid=c41ecd9aa986486c99469eaf0092f8ee" name="initParams" /&gt;
&lt;/object&gt;
&lt;/div&gt;
&lt;p&gt;In the talk he unveiled new work the RIA team is doing is to allow consuming RIA services in jQuery! Watch the talk. Brad demonstrates how you can build a rich jQuery front end that dynamically pulls down all of it&amp;rsquo;s data to the client using RIA. RIA/JS then integrates all the state-tracking/validation richness and such using jQuery validators.&amp;nbsp; If you are building data-centric jQuery based applications then RIA can take care of a lot of the dirty work for you making your job easier*. This also highlights the value of RIA in that I can reuse my existing domain services now both across Silverlight and Javascript! I know my previous boss (who is deeply missed)&amp;nbsp; &lt;a href="http://bradabrams.com/2010/05/going-google/"&gt;Brad Abrams&lt;/a&gt; must be very happy seeing that this is being developed! &lt;/p&gt;
&lt;p&gt;*We&amp;rsquo;re not saying RIA/JS is the panacea for all evils, but it certainly is for some :-)&lt;/p&gt;
&lt;p&gt;Here are some of the key scenarios being supported in the first preview.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Query support with sorting, paging, filtering &lt;/li&gt;
&lt;li&gt;Changeset submission with two edit modes: &lt;ol&gt;
&lt;li&gt;&amp;ldquo;Implicit Commit&amp;rdquo; or &amp;ldquo;write-thru edits&amp;rdquo; where updates to field values are automatically submitted to your DomainService. This can enable a Netflix.com or Mint.com experience where field changes are submitted to the server as soon as the user tabs out of the field. &lt;/li&gt;
&lt;li&gt;&amp;ldquo;Buffered Changes&amp;rdquo; mode, where your code must call commitChanges() to submit your changeset to the DomainService. Those that have used the Silverlight client will be most familiar with this mode - a submit button is often used to trigger the commit. &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Data change events including collection changes &lt;/li&gt;
&lt;li&gt;Client-side change tracking with an entity state API for determining what entities and properties have been edited &lt;/li&gt;
&lt;li&gt;Entity data model support that allows you to navigate through associated entity properties and collections &lt;/li&gt;
&lt;li&gt;Client-side validation by exposing your server-side validation metadata in jQuery validation format &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;And here is a snippet of the new RIA/JS syntax. This is a great example of how we are looking to take advantage of awesome OSS solutions for delivering value. It&amp;rsquo;s about time!&lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&amp;lt;script type="&lt;span style="color: #8b0000"&gt;text/javascript&lt;/span&gt;"&amp;gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  $(&lt;span style="color: #0000ff"&gt;function&lt;/span&gt; () {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; serviceUrl = "&lt;span style="color: #8b0000"&gt;/CustomerApp-CustomerService.svc&lt;/span&gt;";
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; customers = [];
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; render = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; (loadedCustomers) {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	  $("&lt;span style="color: #8b0000"&gt;#customerForm input[name='CustomerName']&lt;/span&gt;").
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	    val(loadedCustomers[0].CustomerName);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	  $("&lt;span style="color: #8b0000"&gt;#customerForm&lt;/span&gt;").link(loadedCustomers[0]);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	};
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	$([customers]).dataSource({
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	  serviceUrl: serviceUrl,
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	  queryName: "&lt;span style="color: #8b0000"&gt;GetCustomers&lt;/span&gt;",
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	  refresh: render
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;	}).refresh();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  });
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&amp;lt;div id="&lt;span style="color: #8b0000"&gt;customerForm&lt;/span&gt;"&amp;gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    Name: &amp;lt;input type="&lt;span style="color: #8b0000"&gt;text&lt;/span&gt;" &lt;span style="color: #0000ff"&gt;name&lt;/span&gt;="&lt;span style="color: #8b0000"&gt;CustomerName&lt;/span&gt;" /&amp;gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;After the talk, the RIA team shipped new bits (as in js files) to Codeplex and a new &lt;a href="http://nuget.org/list/packages/RIAServices.jQuery"&gt;RIA Service jQuery Nuget&lt;/a&gt; package! allowing you to start to play with the RIA/JS stuff now.&amp;nbsp; Go get-em &lt;a href="http://bit.ly/wcfjquery"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;WCF Web API and Preview 4&lt;/h1&gt;
&lt;p&gt;Continuing along the path web goodness, I delivered a talk: &lt;a href="http://channel9.msdn.com/Events/MIX/MIX11/FRM14"&gt;WCF Web APIs: There&amp;rsquo;s a URI for that&lt;/a&gt;. &lt;/p&gt;
&lt;div&gt;
&lt;object height="288" type="application/x-silverlight-2" width="512" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAJAADqNAAAxB0AAAAAAAAAAAAAAAAAAAAAAABoAAAAaAB0AHQAcAA6AC8ALwBjAGgAYQBuAG4AZQBsADkALgBtAHMAZABuAC4AYwBvAG0ALwBzAGMAcgBpAHAAdABzAC8AQwBoAGEAbgBuAGUAbAA5AC4AeABhAHAAPwB2AD0AMQAuADUAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAEAAG0AZQBkAGkAYQB1AHIAbAA9AGgAdAB0AHAAOgAvAC8AZgBpAGwAZQBzAC4AYwBoADkALgBtAHMALwBtAGkAeAAvADIAMAAxADEALwB3AG0AdgAtAGgAcQAvAEYAUgBNADEANAAtAEgARAAuAHcAbQB2ACwAdABoAHUAbQBiAG4AYQBpAGwAPQBoAHQAdABwADoALwAvAGYAaQBsAGUAcwAuAGMAaAA5AC4AbQBzAC8AbQBpAHgALwAyADAAMQAxAC8AdABoAHUAbQBiAHMALwBGAFIATQAxADQAXwBsAGcALgBqAHAAZwAsAGQAZQBsAGkAdgBlAHIAeQBtAGUAdABoAG8AZAA9AHAAcgBvAGcAcgBlAHMAcwBpAHYAZQBkAG8AdwBuAGwAbwBhAGQALABhAHUAdABvAHAAbABhAHkAPQBmAGEAbABzAGUALABlAG4AdAByAHkAaQBkAD0AMgBhAGUAYgAwAGUAOQBhAGEAYgBmAGYANABlADcAZABhADUAYgBlADkAZQBhAGYAMAAwADkAMgBmAGEAYgA4AAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAABgAAAA0AC4AMAAuADUAMAA0ADAAMQAuADAAAAAAAAAAAAAAAAAAAAAAAAAA"&gt;
&lt;param value="4.0.50401.0" name="minRuntimeVersion" /&gt;
&lt;param value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" name="source" /&gt;
&lt;param value="mediaurl=http://files.ch9.ms/mix/2011/wmv-hq/FRM14-HD.wmv,thumbnail=http://files.ch9.ms/mix/2011/thumbs/FRM14_lg.jpg,deliverymethod=progressivedownload,autoplay=false,entryid=2aeb0e9aabff4e7da5be9eaf0092fab8" name="initParams" /&gt;
&lt;/object&gt;
&lt;/div&gt;
&lt;p&gt;In the talk I covered the evolution of systems that are now making their capabilities directly available over HTTP including social sites and line of business / enterprise apps. I showed progress we&amp;rsquo;ve made since PDC on our new WCF addition. The advances have been significant including greatly improving the out of the box experience, enhancing the fidelity you can have when working with HTTP,&amp;nbsp; improving the configuration story and improving testability. &lt;/p&gt;
&lt;p&gt;For example I demonstrated how using our new nuget package, you&amp;nbsp; quickly you can build a simple service that can return and consume xml, json as well as consume form url encoding content. I then throw an existing jQuery front end on top without having to touch the server side configuration. I then demonstrated how I could easily take my existing service and quickly refactor it to use an IoC container, in this case Autofac, by taking advantage of a new fluent api (which is still a work in progress).&lt;/p&gt;
&lt;p&gt;In the second part of my talk, I demonstrated how having rich control of formats/media types can benefit you. This includes showing my resource returning OData, as well a vcard implementation which I use to import contacts directly into gmail. Try that with SOAP, or plain-old XML/JSON, I dare you!&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a snippet of some of the HTTP fidelity I am talking about. Below my service takes advantage of our new HttpResponseMessage&amp;lt;T&amp;gt; and HttpResponseException to return a model AND work with HTTP at the same time. &lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;[WebGet(UriTemplate = "&lt;span style="color: #8b0000"&gt;{id}&lt;/span&gt;")]
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; HttpResponseMessage&amp;lt;Contact&amp;gt; Get(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  var contact = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.repository.Get(id);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (contact == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  {
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    var response = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpResponseMessage();
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    response.StatusCode = HttpStatusCode.NotFound;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    response.Content = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringContent("&lt;span style="color: #8b0000"&gt;Contact not found&lt;/span&gt;");
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpResponseException(response);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;   }
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;   var contactResponse = 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;     &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpResponseMessage&amp;lt;Contact&amp;gt;(contact);
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;   &lt;span style="color: #008000"&gt;//set it to expire in 5 minutes&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;   contactResponse.Content.Headers.Expires = 
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;     &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DateTimeOffset(DateTime.Now.AddSeconds(30));
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;   &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; contactResponse;
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;The Get method returns a contact and sets caching headers. If the contact is not found however it throws an HttpResponseException passing in an HttpResponseMessage. In this case I am just returning a string, but you have full access to set the response headers/content to whatever you want. Also you might not have caught it, but the id parameter is now passed in as integer. In previous drops as well as in WCF HTTP you had to use a string. Well now we do automatic type conversion. You asked for it, and you got it!&lt;/p&gt;
&lt;h1&gt;Nuget and Preview 4&lt;/h1&gt;
&lt;p&gt;After my talk, I am happy to announce that we pushed our next release of WCF Web API (yes drop the s) to &lt;a href="http://wcf.codeplex.com/releases/view/64449"&gt;Codeplex&lt;/a&gt; along with a new set of &lt;a href="http://nuget.org/List/Search?packageType=Packages&amp;amp;searchCategory=All+Categories&amp;amp;searchTerm=webapi+httpclient+jsonvalue&amp;amp;sortOrder=package-download-count&amp;amp;pageSize=10"&gt;Nuget packages&lt;/a&gt; (webapi.all will get all of ours). You&amp;rsquo;ll notice a 6th package, &lt;a href="http://nuget.org/List/Packages/WebApi.CrudHttpSample"&gt;WebApi.CrudHttpSample&lt;/a&gt; from &lt;a href="http://geekswithblogs.net/michelotti/Default.aspx"&gt;Steve Michelotti&lt;/a&gt;. Rock on Steve! Here&amp;rsquo;s a &lt;a href="http://geekswithblogs.net/michelotti/archive/2011/04/21/wcf-web-api-is-pure-simplicity-with-nuget.aspx"&gt;link&lt;/a&gt; to more on that package.&lt;/p&gt;
&lt;p&gt;Preview 4 is &lt;em&gt;&lt;span style="text-decoration: underline;"&gt;loaded &lt;/span&gt;&lt;/em&gt;with new features much of which is based on your feedback! We&amp;rsquo;ve been developing them for a while and finally are able to get them out there. All of our apis have been significantly evolved in this release.&lt;/p&gt;
&lt;p&gt;Here is a summary of the major things you will find:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;New message classes HttpResponseMessage&amp;lt;T&amp;gt; / HttpRequestMessage&amp;lt;T&amp;gt; allows accessing headers and using a strongly typed model.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Uri parameters can now autocast to primtiive types, i.e. a uri template of "{id}" can map to an integer parameter of id.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Matching of parameters is now by type if there is no match on name, ie. HttpRequestMessage req will work.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;New Operation Handlers which replace processors and dramatically improve the authoring&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;New Formatters for plugging in custom media types&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;New Message Handlers for low level control over HTTP&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Newer HttpClient&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Support for Form Url Encoding / Json and Xml out of the box.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Support for HTTPs&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;IQueryable support with IQueryable&amp;lt;T&amp;gt; and without requiring attributes&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Overhauled&lt;strong&gt; fluent API for configuration !!!!&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Unit tests&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;New samples&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ContactManager is now a fully client based AJAX / JQuery application&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;New ContactManager_Simple illustrates the bare basics.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;new HelloResource sample&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Acceptance and Unit tests for some of the samples &lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I am planning to do some follow up posting detailing all these changes, but this should be enough to keep you guys happy for a while &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/8244.wlEmoticon_2D00_smile_5F00_2.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" /&gt;&lt;/p&gt;
&lt;p&gt;Go road test this stuff and give us your feedback. &lt;strong&gt;We want it&lt;/strong&gt;, we&amp;rsquo;re not done yet! &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10157484" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF+WebHttp+Services/">WCF WebHttp Services</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF+RIA+Services/">WCF RIA Services</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF+REST/">WCF REST</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF+Web+APIs/">WCF Web APIs</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/websockets/">websockets</category></item><item><title>WCF Extensibility – Message Inspectors</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/23/wcf-extensibility-message-inspectors.aspx</link><pubDate>Sat, 23 Apr 2011 16:08:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10157384</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10157384</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/23/wcf-extensibility-message-inspectors.aspx#comments</comments><description>&lt;p&gt;&lt;span&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;&lt;em&gt;index page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;The message inspectors are probably the most used extensibility points of the WCF runtime. Anytime you need to log, inspect, modify or completely replace a message, the two inspector interfaces (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.aspx"&gt;IClientMessageInspector&lt;/a&gt; for the client side; &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspx"&gt;IDispatchMessageInspector&lt;/a&gt; for the server side) are likely to be perfect candidates for the solution. &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/bc07fa75-84d7-4fd2-b56a-9192372aefb1"&gt;There&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4be9c7e0-67d8-4ab6-9e0f-7dd3fb31bd2a"&gt;are&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1d9d73d0-240c-46a8-853f-d7c3dfc85c6c"&gt;so&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/31a6dc8b-91a2-4aab-94b1-bfd93565236d"&gt;many&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/65778aea-f872-45a8-85c9-d2bbc2838baf"&gt;examples&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f01a7120-0351-4be2-b45f-b7fb382c8a1f"&gt;of&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/ecafdc19-5e95-4286-aef1-6cd3937c2363"&gt;the&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/forums/en-US/wcf/thread/05ad8f77-33b7-4793-81b7-df0a54183fd9"&gt;dispatch&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/6f14b940-28e2-464a-800d-99f190a22867"&gt;inspector&lt;/a&gt; (&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/9fc5c26f-e2ee-410f-8490-a046e6d35770"&gt;and&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/19500d14-78b7-4356-b817-fcc9abc2afcf"&gt;also&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/3396ffba-4e33-40f2-b8e6-9fcb7f0b3a88"&gt;many&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-CA/wcf/thread/fa3f4c55-5835-43f2-892f-737b4bccb598"&gt;more&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-GB/wcf/thread/a6460e19-42d7-4ae0-8fdb-ca7bafd4f460"&gt;examples&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/621e9b29-a220-420e-9ea7-a8bf0adaf363"&gt;using&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/6ed8d927-cf74-4ddc-96cb-d774af799081"&gt;client&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/55d9c995-c857-4ae4-b1d2-55cd1039bc35"&gt;inspectors&lt;/a&gt;) being used as solution for problems in the forums that it’s actually hard to pick one scenario to show in this post. I’ll then show one full scenario and briefly mention others.&lt;/p&gt;  &lt;h3&gt;Public implementations in WCF&lt;/h3&gt;  &lt;p&gt;None. Most of the runtime extensibility points don’t have any public implementations, although there are a few internal ones for the message inspectors.&lt;/p&gt;  &lt;h3&gt;Interface declarations&lt;/h3&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8ac8bb26-fd47-45a0-bd5e-01711467ec46" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IDispatchMessageInspector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; request, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel, &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; BeforeSendReply(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; reply, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IClientMessageInspector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterReceiveReply(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; reply, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeSendRequest(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; request, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The inspector interfaces have two methods: one after the incoming message is received on the wire and before it’s dispatched to the application (AfterReceive), and one after the outgoing message is received from the application and before it’s encoded to be sent on the wire (BeforeSend). Let’s talk about them individually.&lt;/p&gt;  &lt;p&gt;At the server side, implementations of IDispatchMessageInspector get a chance to inspect the incoming message right after the request is received via the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.afterreceiverequest.aspx"&gt;AfterReceiveRequest&lt;/a&gt; method. Besides the message, the method is also passed the channel through which the message arrived (which contains information about any current sessions, local and remote address, and so on), and the instance context associated with the service (with references to the host, and any extensions associated with it). After the user code on the service operation processed the request, and the reply is created into a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;Message&lt;/a&gt; object, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.beforesendreply.aspx"&gt;BeforeSendReply&lt;/a&gt; is called on the inspector code, with the message object and the &lt;em&gt;correlation state&lt;/em&gt;, which is whatever AfterReceiveRequest returned – this way the code can correlate the two parts of the message inspection for a single client request.&lt;/p&gt;  &lt;p&gt;One thing that deserves mention is that the Message object to both methods is passed by reference. WCF Message objects can only be “consumed” once – and “consumed” can mean read, written or copied. The message body is essentially a read-once stream, so once it’s consumed it cannot be used again. So if, in the inspector code, one were to read the message, the WCF runtime wouldn’t be able to reuse that message in the rest of its pipeline (i.e., to encode it to send as a reply or to parse it into operation parameters). So if the inspector code needs to read the message, it’s the &lt;em&gt;responsibility of the inspector to recreate&lt;/em&gt; the message. The code below shows one way of recreating the message object.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:74e7996a-1e2e-4d02-8c56-75dbb6adcc59" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; request, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel, &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Message:&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(request);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;XmlWriter&lt;/span&gt; writer = &lt;span style="color:#2b91af"&gt;XmlWriter&lt;/span&gt;.Create(ms);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    request.WriteMessage(writer); &lt;span style="color:#008000"&gt;// the message was consumed here&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    writer.Flush();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    ms.Position = 0;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;XmlDocument&lt;/span&gt; xmlDoc = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;XmlDocument&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    xmlDoc.Load(ms);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ChangeMessage(xmlDoc);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#008000"&gt;//Now recreating the message&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    ms = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;    xmlDoc.Save(ms);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    ms.Position = 0;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;XmlReader&lt;/span&gt; reader = &lt;span style="color:#2b91af"&gt;XmlReader&lt;/span&gt;.Create(ms);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; newMessage = &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt;.CreateMessage(reader, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt;.MaxValue, request.Version);&lt;/li&gt; &lt;li&gt;    newMessage.Properties.CopyProperties(request.Properties);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    request = newMessage;&lt;/li&gt; &lt;li&gt;    &lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The list of method calls which would cause a message to be consumed are the following: &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.createbufferedcopy.aspx"&gt;CreateBufferedCopy&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.getbody.aspx"&gt;GetBody&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.getreaderatbodycontents.aspx"&gt;GetReaderAtBodyContents&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.writebody.aspx"&gt;WriteBody&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.writebodycontents.aspx"&gt;WriteBodyContents&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.writemessage.aspx"&gt;WriteMessage&lt;/a&gt;. All others are fine: accessing the message headers is ok, since they’re always buffered, so that doesn’t “invalidate” the message. Accessing the message properties is also safe, as they’re just a named dictionary (buffered). Finally, calling &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.tostring.aspx"&gt;Message.ToString&lt;/a&gt; in the message is also safe – if the message body is indeed a read-once stream, it will be represented simply as “... stream ...”. If the message is buffered it’s actually possible that the value returned by ToString will display the whole message body.&lt;/p&gt;  &lt;p&gt;At the client side, IClientMessageInspector implementations get a chance to inspect the message after it’s been created based on the operation call, and right before it’s encoded. &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.beforesendrequest.aspx"&gt;BeforeSendRequest&lt;/a&gt; receives the message (again, passed by reference) and the channel through which the message is being sent. When the response from the server arrives and is decoded (by the message encoder) into a Message object, it’s passed to the client inspector in its &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.afterreceivereply.aspx"&gt;AfterReceiveReply&lt;/a&gt; method. Like in the server version, the method receives the message object (again, by reference) and the correlation state returned by the BeforeSendRequest method. Notice that if the operation contract is defined as &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isoneway.aspx"&gt;one way&lt;/a&gt;, the call to AfterReceiveReply is not made at the client inspector, which makes sense, since one way operations do not have a reply message. Weirdly enough, for dispatch message inspectors, BeforeSendReply is actually called for HTTP, but the reply message passed to it is null.&lt;/p&gt;  &lt;h3&gt;How to add message inspectors&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;At the server side&lt;/strong&gt;: the list of dispatch message inspectors is available at the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.dispatchruntime.aspx"&gt;DispatchRuntime&lt;/a&gt; object. The object is typically accessed via the endpoint dispatcher in a call to &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applydispatchbehavior.aspx"&gt;IEndpointBehavior.ApplyDispatchBehavior&lt;/a&gt;, or directly passed to an implementation of &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehavior.applydispatchbehavior.aspx"&gt;IContractBehavior.ApplyDispatchBehavior&lt;/a&gt;.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:23446bc6-55a9-42dd-8ab7-4f08ee525eca" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 500px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyContractBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IContractBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;DispatchRuntime&lt;/span&gt; dispatchRuntime)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        dispatchRuntime.MessageInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInspector&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyEndpointBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        endpointDispatcher.DispatchRuntime.MessageInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInspector&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;At the client side&lt;/strong&gt;: the list of client message inspectors is available at the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.clientruntime.aspx"&gt;ClientRuntime&lt;/a&gt; object.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:86f2ee81-2c6b-432d-8351-8ada99f81e87" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyContractBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IContractBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        clientRuntime.MessageInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientInspector&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyEndpointBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        clientRuntime.MessageInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientInspector&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Real world scenario: Inspecting non-XML messages&lt;/h3&gt;  &lt;p&gt;As I mentioned before, all WCF messages are XML-based – the message envelope is an XML Infoset represented in memory, with the (optional) header and the body as child XML elements of the envelope. A message can be directly written to a XML writer, and created based on a XML reader. This works quite well in the XML (including SOAP and POX) world. However, with the introduction of the WCF HTTP programming model in .NET Framework 3.5, WCF started accepting out-of-the-box more types of content (most notably JSON and binary content). But since the whole WCF stack is XML-based, sometimes the behavior of the messages can be counter-intuitive.&lt;/p&gt;  &lt;p&gt;Take, for example, a simple message logger, which is typically implemented using the message inspectors described in this post. Let’s say that we have a contact manager, which is implemented as a bunch of operations used primarily by web pages (thus using JSON as the primary message format):&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:885cd1a6-cb87-4cbd-9c37-176c6da76ff2" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;DataContract&lt;/span&gt;]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Id { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Name { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Email { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;DataMember&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] Telephones { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IContactManager&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebInvoke&lt;/span&gt;(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Method = &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; AddContact(&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebInvoke&lt;/span&gt;(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Method = &lt;span style="color:#a31515"&gt;&amp;quot;PUT&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/{id}&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; UpdateContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id, &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebInvoke&lt;/span&gt;(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        Method = &lt;span style="color:#a31515"&gt;&amp;quot;DELETE&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/{id}&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DeleteContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebGet&lt;/span&gt;(UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; GetAllContacts();&lt;/li&gt; &lt;li&gt;    &lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;WebGet&lt;/span&gt;(UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/{id}&amp;quot;&lt;/span&gt;, ResponseFormat = &lt;span style="color:#2b91af"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; GetContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;WebGet&lt;/span&gt;(UriTemplate = &lt;span style="color:#a31515"&gt;&amp;quot;/ContactsAsText&amp;quot;&lt;/span&gt;)]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; GetContactsAsText();&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now let’s say we send the following request to the service:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;span style="font-family: consolas; font-size: x-small"&gt;POST /Contacts HTTP/1.1        &lt;br /&gt;Content-Type: application/json         &lt;br /&gt;Host: my.host.name.com         &lt;br /&gt;Content-Length: 90         &lt;br /&gt;Expect: 100-continue&lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&lt;span style="font-family: consolas; font-size: x-small"&gt;{&amp;quot;Name&amp;quot;:&amp;quot;Jane Roe&amp;quot;, &amp;quot;Email&amp;quot;:&amp;quot;jane@roe.com&amp;quot;, &amp;quot;Telephones&amp;quot;:[&amp;quot;202-555-4444&amp;quot;, &amp;quot;202-555-8888&amp;quot;]}&lt;/span&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Inside the message inspector, we have a simple implementation which prints the message content:&lt;/p&gt;  &lt;div&gt;   &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:550d2b15-5dfd-46b8-b30f-4a58addb90c8" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; request, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel, &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!request.IsEmpty)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ForegroundColor = &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Green;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Incoming message:&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(request);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ResetColor();&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;    &lt;p&gt;Easy, right? However, we’re in the Message world, and that means XML, so instead of seeing the nice JSON request which was sent to the server, what ends up being printed is the message below:&lt;/p&gt;    &lt;blockquote&gt;     &lt;p&gt;&lt;span style="font-family: consolas; font-size: x-small"&gt;&amp;lt;root type=&amp;quot;object&amp;quot;&amp;gt;          &lt;br /&gt;&amp;#160; &amp;lt;Name type=&amp;quot;string&amp;quot;&amp;gt;Jane Roe&amp;lt;/Name&amp;gt;           &lt;br /&gt;&amp;#160; &amp;lt;Email type=&amp;quot;string&amp;quot;&amp;gt;jane@roe.com&amp;lt;/Email&amp;gt;           &lt;br /&gt;&amp;#160; &amp;lt;Telephones type=&amp;quot;array&amp;quot;&amp;gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;item type=&amp;quot;string&amp;quot;&amp;gt;202-555-4444&amp;lt;/item&amp;gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;item type=&amp;quot;string&amp;quot;&amp;gt;202-555-8888&amp;lt;/item&amp;gt;           &lt;br /&gt;&amp;#160; &amp;lt;/Telephones&amp;gt;           &lt;br /&gt;&amp;lt;/root&amp;gt;&lt;/span&gt;&lt;/p&gt;   &lt;/blockquote&gt;    &lt;p&gt;This throws quite a few people off-balance. What is being printed out is actually equivalent to the incoming JSON, by following the &lt;a href="http://msdn.microsoft.com/en-us/library/bb924435.aspx"&gt;mapping between JSON and XML&lt;/a&gt; used in WCF. But that doesn’t help for all the scenarios where one needs to log incoming messages, or even change the JSON in the message. The same would happen if the message was a “raw” message, for operations in which the return type or the operation parameter was of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx"&gt;Stream&lt;/a&gt; – see more information on the WCF raw programming model for &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx"&gt;returning&lt;/a&gt; or &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx"&gt;receiving&lt;/a&gt; raw data – what would be printed would be the XML mapping of raw data (the base64binary data wrapped around a &amp;lt;Binary&amp;gt; XML element).&lt;/p&gt;    &lt;p&gt;This example will show then how to read such content in a way that can be easily manipulated (the example simply logs it to a file, but it can easily be modified to change the message on the fly as well). And before I go further, the usual disclaimer – this is a sample for illustrating the topic of this post, this is not production-ready code. I tested it for a few contracts and it worked, but I cannot guarantee that it will work for all scenarios (please let me know if you find a bug or something missing). Also, for simplicity sake it doesn’t have a lot of error handling which a production-level code would. Also, the contact manager is all stored in memory, a “real” one would have a backing database or something more “persistent”.&lt;/p&gt;    &lt;p&gt;First, for completeness sake, the service which implements the contract shown before, which is shown below. The implementation is simple (all in memory), with a lock around operations with the “repository”.&lt;/p&gt; &lt;/div&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:187df72b-0bad-48eb-9843-a62a8f2f26ca" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ContactManagerService&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IContactManager&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; AllContacts = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; currentId = 0;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; syncRoot = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; AddContact(&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; contactId = &lt;span style="color:#2b91af"&gt;Interlocked&lt;/span&gt;.Increment(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; currentId);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        contact.Id = contactId.ToString(&lt;span style="color:#2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            AllContacts.Add(contact);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;WebOperationContext&lt;/span&gt;.Current.OutgoingResponse.StatusCode = &lt;span style="color:#2b91af"&gt;HttpStatusCode&lt;/span&gt;.Created;&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; contact.Id;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; UpdateContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id, &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; contact)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        contact.Id = id;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; index = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.FetchContact(id);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (index &amp;gt;= 0)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                AllContacts[index] = contact;&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DeleteContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; index = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.FetchContact(id);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (index &amp;gt;= 0)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                AllContacts.RemoveAt(index);&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; GetAllContacts()&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt;&amp;gt; result;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            result = AllContacts.ToList();&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; GetContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Contact&lt;/span&gt; result;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; index = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.FetchContact(id);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            result = index &amp;lt; 0 ? &lt;span style="color:#0000ff"&gt;null&lt;/span&gt; : AllContacts[index];&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; GetContactsAsText()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt; sb = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;WebOperationContext&lt;/span&gt;.Current.OutgoingResponse.ContentType = &lt;span style="color:#a31515"&gt;&amp;quot;text/plain&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; contact &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; AllContacts)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                sb.AppendLine(&lt;span style="color:#a31515"&gt;&amp;quot;Contact &amp;quot;&lt;/span&gt; + contact.Id + &lt;span style="color:#a31515"&gt;&amp;quot;:&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;                sb.AppendLine(&lt;span style="color:#a31515"&gt;&amp;quot;  Name: &amp;quot;&lt;/span&gt; + contact.Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                sb.AppendLine(&lt;span style="color:#a31515"&gt;&amp;quot;  Email: &amp;quot;&lt;/span&gt; + contact.Email);&lt;/li&gt; &lt;li&gt;                sb.AppendLine(&lt;span style="color:#a31515"&gt;&amp;quot;  Telephones:&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; phone &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; contact.Telephones)&lt;/li&gt; &lt;li&gt;                {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    sb.AppendLine(&lt;span style="color:#a31515"&gt;&amp;quot;    &amp;quot;&lt;/span&gt; + phone);&lt;/li&gt; &lt;li&gt;                }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;WebOperationContext&lt;/span&gt;.Current.OutgoingResponse.ContentType = &lt;span style="color:#a31515"&gt;&amp;quot;text/plain; charset=utf-8&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Encoding&lt;/span&gt;.UTF8.GetBytes(sb.ToString()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; ms;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; FetchContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; result = -1;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; AllContacts.Count; i++)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (AllContacts[i].Id == id)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                result = i;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt; 0)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;WebOperationContext&lt;/span&gt;.Current.OutgoingResponse.StatusCode = &lt;span style="color:#2b91af"&gt;HttpStatusCode&lt;/span&gt;.NotFound;&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now for the inspector itself. I’ll implement it as both an &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspx"&gt;IDispatchMessageInspector&lt;/a&gt; and an &lt;a href="http://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/"&gt;IEndpointBehavior&lt;/a&gt; to make it easier for adding it to the endpoint I’m interested in logging the messages for. It will contain a folder where to log the messages, plus a counter to create the file name where the messages will be logged. The IEndpointBehavior implementation is simple, only using the ApplyDispatchBehavior method to add that instance to the list of message inspectors in the dispatch runtime.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9037dad5-7cbb-43d6-8bd8-f1277cb7975b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IncomingMessageLogger&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IDispatchMessageInspector&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;const&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; MessageLogFolder = &lt;span style="color:#a31515"&gt;@&amp;quot;c:&amp;#92;temp&amp;#92;&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; messageLogFileIndex = 0;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        endpointDispatcher.DispatchRuntime.MessageInspectors.Add(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now for the message inspector implementation. For every incoming or outgoing message, we’ll create a new file in the folder defined in the const field for the class.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f2236c09-e6cd-480c-93e0-9601133642ac" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; request, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel, &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; messageFileName = &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515"&gt;&amp;quot;{0}Log{1:000}_Incoming.txt&amp;quot;&lt;/span&gt;, MessageLogFolder, &lt;span style="color:#2b91af"&gt;Interlocked&lt;/span&gt;.Increment(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; messageLogFileIndex));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt; requestUri = request.Headers.To;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;StreamWriter&lt;/span&gt; sw = &lt;span style="color:#2b91af"&gt;File&lt;/span&gt;.CreateText(messageFileName))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;HttpRequestMessageProperty&lt;/span&gt; httpReq = (&lt;span style="color:#2b91af"&gt;HttpRequestMessageProperty&lt;/span&gt;)request.Properties[&lt;span style="color:#2b91af"&gt;HttpRequestMessageProperty&lt;/span&gt;.Name];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        sw.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;{0} {1}&amp;quot;&lt;/span&gt;, httpReq.Method, requestUri);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; header &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; httpReq.Headers.AllKeys)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sw.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;{0}: {1}&amp;quot;&lt;/span&gt;, header, httpReq.Headers[header]);&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!request.IsEmpty)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            sw.WriteLine();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sw.WriteLine(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.MessageToString(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; request));&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; requestUri;&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; BeforeSendReply(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; reply, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; messageFileName = &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515"&gt;&amp;quot;{0}Log{1:000}_Outgoing.txt&amp;quot;&lt;/span&gt;, MessageLogFolder, &lt;span style="color:#2b91af"&gt;Interlocked&lt;/span&gt;.Increment(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; messageLogFileIndex));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;StreamWriter&lt;/span&gt; sw = &lt;span style="color:#2b91af"&gt;File&lt;/span&gt;.CreateText(messageFileName))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        sw.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Response to request to {0}:&amp;quot;&lt;/span&gt;, (&lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;)correlationState);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;HttpResponseMessageProperty&lt;/span&gt; httpResp = (&lt;span style="color:#2b91af"&gt;HttpResponseMessageProperty&lt;/span&gt;)reply.Properties[&lt;span style="color:#2b91af"&gt;HttpResponseMessageProperty&lt;/span&gt;.Name];&lt;/li&gt; &lt;li&gt;        sw.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;{0} {1}&amp;quot;&lt;/span&gt;, (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;)httpResp.StatusCode, httpResp.StatusCode);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!reply.IsEmpty)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            sw.WriteLine();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sw.WriteLine(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.MessageToString(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; reply));&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now for the interesting part – the implementation of MessageToString. Incoming messages from the encoder used in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx"&gt;WebHttpBinding&lt;/a&gt; are tagged with a property of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.webbodyformatmessageproperty.aspx"&gt;WebBodyFormatMessageProperty&lt;/a&gt;, which defines which of the inner encoders was used to decode the message (the encoder from that binding is actually composed of three encoders: one for XML content, one for JSON, and one for everything else). That property is also used on outgoing messages to tell the web encoder which of the inner encoders should be used to write the message to the wire. So we’ll define a small helper method to retrieve the format from the message object.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:58def131-f6c7-4670-bfff-281ce71b7710" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt; GetMessageContentFormat(&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt; format = &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt;.Default;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (message.Properties.ContainsKey(&lt;span style="color:#2b91af"&gt;WebBodyFormatMessageProperty&lt;/span&gt;.Name))&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;WebBodyFormatMessageProperty&lt;/span&gt; bodyFormat;&lt;/li&gt; &lt;li&gt;        bodyFormat = (&lt;span style="color:#2b91af"&gt;WebBodyFormatMessageProperty&lt;/span&gt;)message.Properties[&lt;span style="color:#2b91af"&gt;WebBodyFormatMessageProperty&lt;/span&gt;.Name];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        format = bodyFormat.Format;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; format;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;And now for MessageToString (really this time). For XML and JSON messages, the implementation will write the message into a XmlWriter of the appropriate type. The writer created by the class &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.jsonreaderwriterfactory.aspx"&gt;JsonReaderWriterFactory&lt;/a&gt; implements the mapping between JSON and XML I mentioned before, so we’ll use it for JSON messages; for XML messages (or for messages which don’t have the body format property) we’ll use the “normal” XML writer from WCF; for raw messages we’ll deal with them specifically in a separate method. After the message is written, it has been consumed, so we need to recreate it to pass it along the channel stack. Using a reader of the same type and creating a new message using the &lt;a href="http://msdn.microsoft.com/en-us/library/ms586762.aspx"&gt;Message.CreateMessage(XmlDictionaryReader, int, MessageVersion)&lt;/a&gt; overload and copying the original message properties (which are not serialized when the message is written out).&lt;/p&gt;  &lt;p&gt;For the raw messages, since the format is relatively simple (the binary data, written as base64Binary data, wrapped in a single &amp;lt;Binary&amp;gt; element), we can consume it directly – read the message body, skip the wrapping element then read the whole body at once. In this case I’m always converting the binary data to text, in the general case that may not work (if the binary data is an image, for example), but that’s beyond the scope for this post.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:990e6f90-3d2a-404e-8505-2b02551483e4" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; MessageToString(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt; messageFormat = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetMessageContentFormat(message);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;switch&lt;/span&gt; (messageFormat)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;case&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt;.Default:&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;case&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt;.Xml:&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            writer = &lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt;.CreateTextWriter(ms);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;case&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt;.Json:&lt;/li&gt; &lt;li&gt;            writer = &lt;span style="color:#2b91af"&gt;JsonReaderWriterFactory&lt;/span&gt;.CreateJsonWriter(ms);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;case&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt;.Raw:&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#008000"&gt;// special case for raw, easier implemented separately&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ReadRawBody(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; message);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    message.WriteMessage(writer);&lt;/li&gt; &lt;li&gt;    writer.Flush();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; messageBody = &lt;span style="color:#2b91af"&gt;Encoding&lt;/span&gt;.UTF8.GetString(ms.ToArray());&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#008000"&gt;// Here would be a good place to change the message body, if so desired.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#008000"&gt;// now that the message was read, it needs to be recreated.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    ms.Position = 0;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#008000"&gt;// if the message body was modified, needs to reencode it, as show below&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#008000"&gt;// ms = new MemoryStream(Encoding.UTF8.GetBytes(messageBody));&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;XmlDictionaryReader&lt;/span&gt; reader;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (messageFormat == &lt;span style="color:#2b91af"&gt;WebContentFormat&lt;/span&gt;.Json)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        reader = &lt;span style="color:#2b91af"&gt;JsonReaderWriterFactory&lt;/span&gt;.CreateJsonReader(ms, &lt;span style="color:#2b91af"&gt;XmlDictionaryReaderQuotas&lt;/span&gt;.Max);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        reader = &lt;span style="color:#2b91af"&gt;XmlDictionaryReader&lt;/span&gt;.CreateTextReader(ms, &lt;span style="color:#2b91af"&gt;XmlDictionaryReaderQuotas&lt;/span&gt;.Max);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; newMessage = &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt;.CreateMessage(reader, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt;.MaxValue, message.Version);&lt;/li&gt; &lt;li&gt;    newMessage.Properties.CopyProperties(message.Properties);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    message = newMessage;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; messageBody;&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; ReadRawBody(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;XmlDictionaryReader&lt;/span&gt; bodyReader = message.GetReaderAtBodyContents();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    bodyReader.ReadStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;Binary&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;[] bodyBytes = bodyReader.ReadContentAsBase64();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; messageBody = &lt;span style="color:#2b91af"&gt;Encoding&lt;/span&gt;.UTF8.GetString(bodyBytes);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#008000"&gt;// Now to recreate the message&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer = &lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt;.CreateBinaryWriter(ms);&lt;/li&gt; &lt;li&gt;    writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;Binary&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    writer.WriteBase64(bodyBytes, 0, bodyBytes.Length);&lt;/li&gt; &lt;li&gt;    writer.WriteEndElement();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    writer.Flush();&lt;/li&gt; &lt;li&gt;    ms.Position = 0;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;XmlDictionaryReader&lt;/span&gt; reader = &lt;span style="color:#2b91af"&gt;XmlDictionaryReader&lt;/span&gt;.CreateBinaryReader(ms, &lt;span style="color:#2b91af"&gt;XmlDictionaryReaderQuotas&lt;/span&gt;.Max);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; newMessage = &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt;.CreateMessage(reader, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt;.MaxValue, message.Version);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    newMessage.Properties.CopyProperties(message.Properties);&lt;/li&gt; &lt;li&gt;    message = newMessage;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; messageBody;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;That’s it. With this inspector we can log messages of all types for REST services, in their original format. Another way to implement it would be in a custom message encoder (coming up in this series), in which you can have access to the raw bytes coming from the wire, as well as the content-type of the HTTP request.&lt;/p&gt;  &lt;p&gt;Now for some test code which sets up the service with that inspector, and sends some messages to it.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:779a5282-e1e8-4034-8691-dfcf490459be" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Program&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;&amp;quot;http://&amp;quot;&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;&amp;quot;:8000/Service&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ContactManagerService&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;IContactManager&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebHttpBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;            endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IncomingMessageLogger&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            host.Open();&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Host opened&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; johnId = SendRequest(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;                baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;                CreateJsonContact(&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;John Doe&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;john@doe.com&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;206-555-3333&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; janeId = SendRequest(&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                CreateJsonContact(&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Jane Roe&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;jane@roe.com&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;202-555-4444 202-555-8888&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;All contacts&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Updating Jane&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            SendRequest(&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;PUT&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + janeId,&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                CreateJsonContact(janeId, &lt;span style="color:#a31515"&gt;&amp;quot;Jane Roe&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;jane@roe.org&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;202-555-4444 202-555-8888&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;All contacts, text format&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/ContactsAsText&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Deleting John&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;DELETE&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + johnId, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Is John still here?&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts/&amp;quot;&lt;/span&gt; + johnId, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;It also works with XML payloads:&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; xmlPayload = &lt;span style="color:#a31515"&gt;@&amp;quot;&amp;lt;Contact&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="color:#a31515"&gt;&amp;lt;Email&amp;gt;johnjr@doe.com&amp;lt;/Email&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#a31515"&gt;&amp;lt;Name&amp;gt;John Doe Jr&amp;lt;/Name&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="color:#a31515"&gt;&amp;lt;Telephones xmlns:a=&amp;quot;&amp;quot;http://schemas.microsoft.com/2003/10/Serialization/Arrays&amp;quot;&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#a31515"&gt;&amp;lt;a:string&amp;gt;333-333-3333&amp;lt;/a:string&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="color:#a31515"&gt;&amp;lt;/Telephones&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#a31515"&gt;&amp;lt;/Contact&amp;gt;&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;            SendRequest(&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;                baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#a31515"&gt;&amp;quot;text/xml&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;                xmlPayload);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;All contacts:&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            SendRequest(&lt;span style="color:#a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;, baseAddress + &lt;span style="color:#a31515"&gt;&amp;quot;/Contacts&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; SendRequest(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; method, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; uri, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; contentType, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; body)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;HttpWebRequest&lt;/span&gt; req = (&lt;span style="color:#2b91af"&gt;HttpWebRequest&lt;/span&gt;)&lt;span style="color:#2b91af"&gt;HttpWebRequest&lt;/span&gt;.Create(uri);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            req.Method = method;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (contentType != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                req.ContentType = contentType;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (body != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;[] bodyBytes = &lt;span style="color:#2b91af"&gt;Encoding&lt;/span&gt;.UTF8.GetBytes(body);&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; reqStream = req.GetRequestStream();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                reqStream.Write(bodyBytes, 0, bodyBytes.Length);&lt;/li&gt; &lt;li&gt;                reqStream.Close();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;HttpWebResponse&lt;/span&gt; resp;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;try&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                resp = (&lt;span style="color:#2b91af"&gt;HttpWebResponse&lt;/span&gt;)req.GetResponse();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;catch&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;WebException&lt;/span&gt; e)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                resp = (&lt;span style="color:#2b91af"&gt;HttpWebResponse&lt;/span&gt;)e.Response;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ForegroundColor = &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Response to request to {0} - {1}&amp;quot;&lt;/span&gt;, method, uri);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;HTTP/{0} {1} {2}&amp;quot;&lt;/span&gt;, resp.ProtocolVersion, (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;)resp.StatusCode, resp.StatusDescription);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; headerName &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; resp.Headers.AllKeys)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;{0}: {1}&amp;quot;&lt;/span&gt;, headerName, resp.Headers[headerName]);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; respStream = resp.GetResponseStream();&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; result = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (respStream != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                result = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;StreamReader&lt;/span&gt;(respStream).ReadToEnd();&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(result);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine();&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;  -*-*-*-*-*-*-*-*&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ResetColor();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#008000"&gt;// Removing the string markers from results (for contact ids)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result.StartsWith(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;#92;&amp;quot;&amp;quot;&lt;/span&gt;) &amp;amp;&amp;amp; result.EndsWith(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;#92;&amp;quot;&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                result = result.Substring(1, result.Length - 2);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; CreateJsonContact(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; id, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; name, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; email, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; telephones)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] phoneNumbers = telephones.Split(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;char&lt;/span&gt;[] { &lt;span style="color:#a31515"&gt;&amp;#39; &amp;#39;&lt;/span&gt; }, &lt;span style="color:#2b91af"&gt;StringSplitOptions&lt;/span&gt;.RemoveEmptyEntries);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt; sb = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;            sb.Append(&lt;span style="color:#a31515"&gt;&amp;#39;{&amp;#39;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (id != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                sb.AppendFormat(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;#92;&amp;quot;Id&amp;#92;&amp;quot;:&amp;#92;&amp;quot;{0}&amp;#92;&amp;quot;, &amp;quot;&lt;/span&gt;, id);&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            sb.AppendFormat(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;#92;&amp;quot;Name&amp;#92;&amp;quot;:&amp;#92;&amp;quot;{0}&amp;#92;&amp;quot;, &amp;quot;&lt;/span&gt;, name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sb.AppendFormat(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;#92;&amp;quot;Email&amp;#92;&amp;quot;:&amp;#92;&amp;quot;{0}&amp;#92;&amp;quot;, &amp;quot;&lt;/span&gt;, email);&lt;/li&gt; &lt;li&gt;            sb.Append(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;#92;&amp;quot;Telephones&amp;#92;&amp;quot;:[&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; phoneNumbers.Length; i++)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (i &amp;gt; 0) sb.Append(&lt;span style="color:#a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;                sb.AppendFormat(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;#92;&amp;quot;{0}&amp;#92;&amp;quot;&amp;quot;&lt;/span&gt;, phoneNumbers[i]);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sb.Append(&lt;span style="color:#a31515"&gt;&amp;#39;]&amp;#39;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            sb.Append(&lt;span style="color:#a31515"&gt;&amp;#39;}&amp;#39;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; sb.ToString();&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;One more thing: we had to deal with lots of different formats and translation between a “XML” message into its own format, which is not something very natural. Some good news is that among the new features coming in an upcoming version of WCF is a new HTTP pipeline, which will make it easier to implement a scenario such as this. And you can actually start using them right now, as there is a preview of the feature in the WCF Codeplex site at &lt;a href="http://wcf.codeplex.com"&gt;http://wcf.codeplex.com&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;Coming up&lt;/h3&gt;  &lt;p&gt;The other inspector interface: &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.aspx"&gt;IParameterInspector&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://code.msdn.microsoft.com/WCF-REST-Message-Inspector-c4b6790b"&gt;Code in this post&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;Carlos Figueira    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;     &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figueira&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10157384" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Extensibility/">Extensibility</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item><item><title>WF4 State Machine User Experience</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/20/wf4-state-machine-user-experience.aspx</link><pubDate>Wed, 20 Apr 2011 07:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10156118</guid><dc:creator>.NET Connected Framework Team</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10156118</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/20/wf4-state-machine-user-experience.aspx#comments</comments><description>&lt;p&gt;State machine is a well-known model for event-driven workflows and a highly requested feature from our WF4 users, especially those looking to move their WF3 State Machine workflows to WF4. We are very pleased to provide a new, fully-supported, WF4 State Machine including runtime and designer in the .Net Framework Platform Update 1 release (&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4863f88f-5519-4b66-a195-752746b4389a"&gt;KB2495593&lt;/a&gt;). This release enables customers to model their event-driven processes as a state machine using a simplified API and designer experience. Thanks to all who evaluated the CodePlex preview of the WF4 State Machine. We incorporated much of your feedback in this final release. &lt;/p&gt;
&lt;h4&gt;State Machine User experience Overview&lt;/h4&gt;
&lt;p&gt;State Machine Activity in WF4 is the encapsulating entity for a state machine execution model.&lt;a name="_Scenario"&gt;&lt;/a&gt; The basic elements of a state machine are:&lt;/p&gt;
&lt;p&gt;&amp;middot; &lt;b&gt;States&lt;/b&gt; &amp;ndash; A finite list of the possible states the state machine can be in&lt;/p&gt;
&lt;p&gt;&amp;middot; &lt;b&gt;Transitions&lt;/b&gt; &amp;ndash; A list of a possible state changes&lt;/p&gt;
&lt;p&gt;&amp;middot; &lt;b&gt;Final State&lt;/b&gt; &amp;ndash; A State which upon reaching it will terminate the StateMachine &lt;/p&gt;
&lt;p&gt;A state machine can have multiple states. It must have only one initial state but can have zero to multiple final states. &lt;/p&gt;
&lt;p&gt;A very basic scenario that can demonstrate a state machine is a stop watch, as described in the WF4 StateMachine modeled in the State Machine Activity Designer below:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/4762.clip_5F00_image003_5F00_384DE9F2.jpg"&gt;&lt;img height="188" width="350" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/2211.clip_5F00_image003_5F00_thumb_5F00_285EA52E.jpg" alt="clip_image003" border="0" title="clip_image003" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This state machine has four possible states:&lt;/p&gt;
&lt;p&gt;&lt;i&gt;On- &lt;/i&gt;initial state of the stopwatch, no data is displayed&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Started -&lt;/i&gt; the stopwatch internal clock is started and the display is updated every 10 milliseconds.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Stopped &lt;/i&gt;- the stopwatch internal clock is stopped and the display shows its last value.&lt;/p&gt;
&lt;p&gt;Off - the stopwatch is powered off. It is a final state in this stop watch model. &lt;/p&gt;
&lt;h4&gt;State &lt;/h4&gt;
&lt;p&gt;Each State supports execution of Activities modeled as Entry and Exit actions which allow Activities to be scheduled upon entering or exiting the state. It should be noted that, State itself in WF4 is not an Activity. &lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at the State designer for &amp;ldquo;On&amp;rdquo; State. &lt;/p&gt;
&lt;table cellpadding="0" cellspacing="0" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="247" valign="top"&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/1651.clip_5F00_image005_5F00_3FA9A99F.jpg"&gt;&lt;img height="277" width="193" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/7411.clip_5F00_image005_5F00_thumb_5F00_04E200C9.jpg" alt="clip_image005" border="0" title="clip_image005" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="391" valign="top"&gt;
&lt;p&gt;The user can drag and drop any activity into the Entry and/or Exit action. &lt;/p&gt;
&lt;p&gt;To improve navigation, the State designer also provides an aggregated view of all the Transitions originating from the State as well as the destination State for that Transition. &lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4&gt;Transition&lt;/h4&gt;
&lt;p&gt;States include a collection of Transitions. A Transition defines the movement from a source State to a destination State. Each Transition is configured with a Trigger Activity, typically an event driven Activity such as Receive Message or Delay. A user can also specify an expression as the condition of a transition. Additionally, an optional Transition Activity may be included. The Transition designer below shows the &amp;ldquo;Start Clock&amp;rdquo; Transition. &lt;/p&gt;
&lt;table cellpadding="0" cellspacing="0" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5850.clip_5F00_image007_5F00_1C2D053A.jpg"&gt;&lt;img height="280" width="245" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/7024.clip_5F00_image007_5F00_thumb_5F00_7656DED6.jpg" alt="clip_image007" border="0" title="clip_image007" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;In the example here, the Transition event is &amp;ldquo;StartTheWatch&amp;rdquo; Activity. The Stop Watch will only transition to &amp;ldquo;Started&amp;rdquo; State after &amp;ldquo;StartTheWatch&amp;rdquo; Activity completes representing the Transition Trigger event reflecting the watch has started successfully.&lt;/p&gt;
&lt;p&gt;Upon the StartTheWatch event, the StartedSuccessful condition is evaluated. If false, the Transition won&amp;rsquo;t be executed and the Trigger Activity will be rescheduled. &lt;/p&gt;
&lt;p&gt;A transition can contain a Transition Action which will be executed after exiting the source State and before entering the destination State.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4&gt;&lt;b&gt;Null and Shared Trigger &lt;/b&gt;&lt;/h4&gt;
&lt;p&gt;Many States simply need to automatically transition after the Entry Action is completed. In WF4, we support a default Trigger using a &amp;ldquo;&lt;b&gt;Null&lt;/b&gt;&amp;rdquo; Trigger Action. A Trigger configured without a Trigger Activity will be fired by default upon entering the State, after the State&amp;rsquo;s Entry Action has been completed. Transition Conditions will still be evaluated.&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;You can also have multiple Transitions share the same Trigger. This type Trigger is called &lt;b&gt;Shared Trigger&lt;/b&gt;. In the case of a shared Trigger, all the Transitions must have a condition specified. &lt;/p&gt;
&lt;p&gt;In the Stop Watch example, when the user presses the &amp;ldquo;start&amp;rdquo; button, the stopwatch first checks the status of the battery. If there is power remaining, the state machine will transition to the Started State. If there&amp;rsquo;s insufficient power, then the State Machine will transition to the Off State. Now let us modify the Stop Watch to add a Shared Trigger Transition &amp;ldquo;OutofBattery&amp;rdquo;. &lt;/p&gt;
&lt;table cellpadding="0" cellspacing="0" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="415" valign="top"&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5367.clip_5F00_image008_5F00_3B8F3600.png"&gt;&lt;img height="168" width="293" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/0676.clip_5F00_image008_5F00_thumb_5F00_449BC181.png" alt="clip_image008" border="0" title="clip_image008" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="223" valign="top"&gt;
&lt;p&gt;To create a Shared Trigger Transition &amp;ldquo;OutOfBattery&amp;rdquo;, we drag a Transition line from the same source State connector used by the &amp;ldquo;Start clock&amp;rdquo; Transition.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Here is the Transition designer view of &amp;ldquo;OutOfBattery&amp;rdquo; Shared Trigger Transition. &lt;/p&gt;
&lt;table cellpadding="0" cellspacing="0" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/4621.clip_5F00_image010_5F00_778B51E8.jpg"&gt;&lt;img height="288" width="242" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5775.clip_5F00_image010_5F00_thumb_5F00_79E4D3E6.jpg" alt="clip_image010" border="0" title="clip_image010" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="319" valign="top"&gt;
&lt;p&gt;These two Transitions, &amp;ldquo;Start clock&amp;rdquo; and &amp;ldquo;OutOfBattery&amp;rdquo;, are sharing the same Trigger event &amp;ldquo;StartTheWatch&amp;rdquo; Activity.&lt;/p&gt;
&lt;p&gt;A Shared Trigger allows for the conditional progression to a next state based on the evaluation of expressions configured for multiple Transitions which share a common Trigger event.&lt;/p&gt;
&lt;p&gt;In this example here, if Stop Watch isn&amp;rsquo;t started successfully, it will proceed down the &amp;ldquo;OutOfBattery&amp;rdquo; Transition and then move to state &amp;ldquo;Off&amp;rdquo;. &lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4&gt;&lt;b&gt;Additional WF4 State Machine features&lt;/b&gt;&lt;/h4&gt;
&lt;p&gt;&lt;b&gt;Auto Insert and connect &lt;/b&gt;In WF3, it takes several steps to insert a new state and a transition. The user will need to manually create transitions when introducing a new State. Adding a new State to existing StateMachine in WF4 becomes much easier with &amp;ldquo;auto insert&amp;rdquo; and &amp;ldquo;auto connect&amp;rdquo; designer enhancements. &lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Tracking &lt;/b&gt;WF4 provides the State level tracking ability to enable tracking when a WF instance enters each state. In StateMachine library, there is a public member &amp;ldquo;StateMachineStateRecord&amp;rdquo;, which is built on top of CustomTrackingRecord. Users can write a custom TrackingParticipant to track StateMachine events to get the history of States. &lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Debugging &lt;/b&gt;Users can set breakpoints on any Activity in a State or Transition. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;State Variable &lt;/b&gt;Users can specify variables in the scope of a StateMachine or a State in WF4. &lt;/p&gt;
&lt;h4&gt;&lt;b&gt;Additional references&lt;/b&gt;&lt;/h4&gt;
&lt;p&gt;To learn more about the object model for WF4 State Machine and its usage, please refer to the following MSDN documents: &lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/gg983472.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Getting Started Tutorial: How to Create a State Machine Workflow&lt;/span&gt;&lt;/a&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh180857.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;State Machine Activity Designers&lt;/span&gt;&lt;/a&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee264171.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;State Machine Workflows&lt;/span&gt;&lt;/a&gt;. &lt;/span&gt;&lt;/span&gt;Also, please check out our great new &lt;a href="http://go.microsoft.com/?linkid=9768290"&gt;Hands on Lab for State Machine&lt;/a&gt;. It should be very helpful to get you started on using WF4 State Machine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10156118" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category></item><item><title>WCF Extensibility – Runtime</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/19/wcf-extensibility-runtime.aspx</link><pubDate>Tue, 19 Apr 2011 18:29:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10155887</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10155887</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/19/wcf-extensibility-runtime.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;&lt;em&gt;index page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Before starting on the actual extensibility points for the WCF runtime (first post should be online tomorrow), I decided to write this quick introduction to the runtime itself. Unlike the behaviors, which are invoked when the WCF stack is being created, the runtime extensions are invoked when actual messages are being sent / received by WCF. As could be seen in the usage examples for the behaviors, they were merely used to set up some extension points in the runtime, and those are the ones which did the “real work”.&lt;/p&gt;  &lt;p&gt;The majority of the next posts in this series will talk about these runtime extensions. Their interfaces are defined under the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.aspx"&gt;System.ServiceModel.Dispatcher namespace&lt;/a&gt;, and unlike the behaviors they don’t follow any common pattern – they’re tailored for their specific task. Some of those interfaces apply to both client and server side of communication (parameter inspector, channel initializer, etc.), some apply to the server only (instance provider, dispatch message inspector, etc.), and some to the client only (client message inspector, interactive context initializer, etc.). The interfaces section of the namespace page has a brief description of each one of the interfaces, and their blog entries will have a more detailed description for them.&lt;/p&gt;  &lt;h3&gt;Adding runtime extensions to WCF&lt;/h3&gt;  &lt;p&gt;In many cases (again, as seen in the examples for the behaviors), more than one of those extensions are needed to accomplish a task for a specific scenario. One thing that I didn’t know until a couple of days ago was exactly the order in which each of these extensibility points are called, so I decided to write a simple program, adding hooks to &lt;em&gt;all of the runtime extensibility points&lt;/em&gt; to see what would come out. This actually helped me to understand their role in the whole message stack, and it can be used as a simple one-stop place if you’re ever wondering where to add a hook to one of the extensibility points listed in here.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0afab1d9-5b5f-4636-be5e-4969a1898d62" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyDispatchMessageInspector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IDispatchMessageInspector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyDispatchMessageInspector()&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; request, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel, &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; BeforeSendReply(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; reply, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyDispatchMessageFormatter&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IDispatchMessageFormatter&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;IDispatchMessageFormatter&lt;/span&gt; inner;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyDispatchMessageFormatter(&lt;span style="color:#2b91af"&gt;IDispatchMessageFormatter&lt;/span&gt; inner)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner = inner;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DeserializeRequest(&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.DeserializeRequest(message, parameters);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; SerializeReply(&lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt; messageVersion, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; result)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.SerializeReply(messageVersion, parameters, result);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientMessageInspector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IClientMessageInspector&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyClientMessageInspector()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterReceiveReply(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; reply, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeSendRequest(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; request, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientMessageFormatter&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IClientMessageFormatter&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;IClientMessageFormatter&lt;/span&gt; inner;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyClientMessageFormatter(&lt;span style="color:#2b91af"&gt;IClientMessageFormatter&lt;/span&gt; inner)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner = inner;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; DeserializeReply(&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.DeserializeReply(message, parameters);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; SerializeRequest(&lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt; messageVersion, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.SerializeRequest(messageVersion, parameters);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyDispatchOperationSelector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IDispatchOperationSelector&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; SelectOperation(&lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; action = message.Headers.Action;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; method = action.Substring(action.LastIndexOf(&lt;span style="color:#a31515"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;) + 1);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; method;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyParameterInspector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IParameterInspector&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt; consoleColor;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; isServer;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyParameterInspector(&lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; isServer)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.isServer = isServer;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.consoleColor = isServer ? &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan : &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; returnValue, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.consoleColor, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.consoleColor, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyCallContextInitializer&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ICallContextInitializer&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterInvoke(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeInvoke(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel, &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationInvoker&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IOperationInvoker&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;IOperationInvoker&lt;/span&gt; inner;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyOperationInvoker(&lt;span style="color:#2b91af"&gt;IOperationInvoker&lt;/span&gt; inner)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner = inner;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] AllocateInputs()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.AllocateInputs();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; Invoke(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.Invoke(instance, inputs, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; outputs);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; InvokeBegin(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs, &lt;span style="color:#2b91af"&gt;AsyncCallback&lt;/span&gt; callback, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; state)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.InvokeBegin(instance, inputs, callback, state);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; InvokeEnd(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, &lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; result)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.InvokeEnd(instance, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; outputs, result);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsSynchronous&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.IsSynchronous;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInstanceProvider&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IInstanceProvider&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;Type&lt;/span&gt; serviceType;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyInstanceProvider(&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt; serviceType)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.serviceType = serviceType;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; GetInstance(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Activator&lt;/span&gt;.CreateInstance(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.serviceType);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; GetInstance(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Activator&lt;/span&gt;.CreateInstance(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.serviceType);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ReleaseInstance(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInstanceContextProvider&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IInstanceContextProvider&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;IInstanceContextProvider&lt;/span&gt; inner;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyInstanceContextProvider(&lt;span style="color:#2b91af"&gt;IInstanceContextProvider&lt;/span&gt; inner)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner = inner;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; GetExistingInstanceContext(&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message, &lt;span style="color:#2b91af"&gt;IContextChannel&lt;/span&gt; channel)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.GetExistingInstanceContext(message, channel);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; InitializeInstanceContext(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message, &lt;span style="color:#2b91af"&gt;IContextChannel&lt;/span&gt; channel)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.InitializeInstanceContext(instanceContext, message, channel);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsIdle(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.IsIdle(instanceContext);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; NotifyIdle(&lt;span style="color:#2b91af"&gt;InstanceContextIdleCallback&lt;/span&gt; callback, &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inner.NotifyIdle(callback, instanceContext);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInstanceContextInitializer&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IInstanceContextInitializer&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Initialize(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyChannelInitializer&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IChannelInitializer&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt; consoleColor;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyChannelInitializer(&lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; isServer)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.consoleColor = isServer ? &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan : &lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Initialize(&lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.consoleColor, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientOperationSelector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IClientOperationSelector&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; AreParametersRequiredForSelection&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; SelectOperation(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt; method, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; method.Name;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInteractiveChannelInitializer&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IInteractiveChannelInitializer&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; BeginDisplayInitializationUI(&lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt; channel, &lt;span style="color:#2b91af"&gt;AsyncCallback&lt;/span&gt; callback, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; state)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt; act = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.DoNothing);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; act.BeginInvoke(callback, state);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; EndDisplayInitializationUI(&lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; result)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Yellow, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DoNothing() { }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyErrorHandler&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IErrorHandler&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; HandleError(&lt;span style="color:#2b91af"&gt;Exception&lt;/span&gt; error)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; error &lt;span style="color:#0000ff"&gt;is&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ArgumentException&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ProvideFault(&lt;span style="color:#2b91af"&gt;Exception&lt;/span&gt; error, &lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt; version, &lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; fault)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Cyan, &lt;span style="color:#a31515"&gt;&amp;quot;{0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;.GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod()));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;MessageFault&lt;/span&gt; messageFault = &lt;span style="color:#2b91af"&gt;MessageFault&lt;/span&gt;.CreateFault(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;FaultCode&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;FaultCode&amp;quot;&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;FaultReason&lt;/span&gt;(error.Message));&lt;/li&gt; &lt;li&gt;        fault = &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt;.CreateMessage(version, messageFault, &lt;span style="color:#a31515"&gt;&amp;quot;FaultAction&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;(IsOneWay = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Process(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;[&lt;span style="color:#2b91af"&gt;ServiceBehavior&lt;/span&gt;(IncludeExceptionDetailInFaults = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;)]&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Service&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Green, &lt;span style="color:#a31515"&gt;&amp;quot;In service operation &amp;#39;{0}&amp;#39;&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (x == 0 &amp;amp;&amp;amp; y == 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;This will cause IErrorHandler to be called&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; x + y;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Process(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Green, &lt;span style="color:#a31515"&gt;&amp;quot;In service operation &amp;#39;{0}&amp;#39;&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IOperationBehavior&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;IContractBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;ClientOperation&lt;/span&gt; clientOperation)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        clientOperation.Formatter = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientMessageFormatter&lt;/span&gt;(clientOperation.Formatter);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        clientOperation.ParameterInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyParameterInspector&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;false&lt;/span&gt;));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;DispatchOperation&lt;/span&gt; dispatchOperation)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        dispatchOperation.CallContextInitializers.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyCallContextInitializer&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        dispatchOperation.Formatter = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyDispatchMessageFormatter&lt;/span&gt;(dispatchOperation.Formatter);&lt;/li&gt; &lt;li&gt;        dispatchOperation.Invoker = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationInvoker&lt;/span&gt;(dispatchOperation.Invoker);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        dispatchOperation.ParameterInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyParameterInspector&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;true&lt;/span&gt;));&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        clientRuntime.ChannelInitializers.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyChannelInitializer&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;false&lt;/span&gt;));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        clientRuntime.InteractiveChannelInitializers.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInteractiveChannelInitializer&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;        clientRuntime.MessageInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientMessageInspector&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        clientRuntime.OperationSelector = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyClientOperationSelector&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;DispatchRuntime&lt;/span&gt; dispatchRuntime)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        dispatchRuntime.ChannelDispatcher.ChannelInitializers.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyChannelInitializer&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;true&lt;/span&gt;));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        dispatchRuntime.ChannelDispatcher.ErrorHandlers.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyErrorHandler&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;        dispatchRuntime.InstanceContextInitializers.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInstanceContextInitializer&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        dispatchRuntime.InstanceContextProvider = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInstanceContextProvider&lt;/span&gt;(dispatchRuntime.InstanceContextProvider);&lt;/li&gt; &lt;li&gt;        dispatchRuntime.InstanceProvider = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyInstanceProvider&lt;/span&gt;(dispatchRuntime.ChannelDispatcher.Host.Description.ServiceType);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        dispatchRuntime.MessageInspectors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyDispatchMessageInspector&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;        dispatchRuntime.OperationSelector = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyDispatchOperationSelector&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; syncRoot = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt; color, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text, &lt;span style="color:#0000ff"&gt;params&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] args)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (args != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; args.Length &amp;gt; 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            text = &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture, text, args);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;lock&lt;/span&gt; (syncRoot)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ForegroundColor = color;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;[{0}] {1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Now.ToString(&lt;span style="color:#a31515"&gt;&amp;quot;HH:mm:ss.fff&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture), text);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ResetColor();&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Thread&lt;/span&gt;.Sleep(50);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteLine(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text, &lt;span style="color:#0000ff"&gt;params&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] args)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(text, args);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteLine(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; obj)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(obj);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ReflectionUtil&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; GetMethodSignature(&lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt; method)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt; sb = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        sb.Append(method.Name);&lt;/li&gt; &lt;li&gt;        sb.Append(&lt;span style="color:#a31515"&gt;&amp;quot;(&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;ParameterInfo&lt;/span&gt;[] parameters = method.GetParameters();&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; parameters.Length; i++)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (i &amp;gt; 0) sb.Append(&lt;span style="color:#a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sb.Append(parameters[i].ParameterType.Name);&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        sb.Append(&lt;span style="color:#a31515"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; sb.ToString();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Program&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;&amp;quot;http://&amp;quot;&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;&amp;quot;:8000/Service&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Service&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress)))&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            endpoint.Contract.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operation &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; endpoint.Contract.Operations)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                operation.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            host.Open();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Host opened&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt;(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(baseAddress)))&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                factory.Endpoint.Contract.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operation &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; factory.Endpoint.Contract.Operations)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                {&lt;/li&gt; &lt;li&gt;                    operation.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Calling operation&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(proxy.Add(3, 4));&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Called operation, calling it again, this time it the service will throw&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;try&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                {&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(proxy.Add(0, 0));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                }&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;catch&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;Exception&lt;/span&gt; e)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                {&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#2b91af"&gt;ConsoleColor&lt;/span&gt;.Red, &lt;span style="color:#a31515"&gt;&amp;quot;{0}: {1}&amp;quot;&lt;/span&gt;, e.GetType().Name, e.Message);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Now calling an OneWay operation&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;                proxy.Process(&lt;span style="color:#a31515"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;                ((&lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt;)proxy).Close();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ColorConsole&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Done&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;When run, the program will show when each method of the extension interfaces are called. The server ones are written in blue, while the ones from the client side are written in yellow, to make it easier to differentiate where each trace is coming from.&lt;/p&gt;  &lt;h3&gt;Coming up&lt;/h3&gt;  &lt;p&gt;The inspection interfaces, starting with the message inspectors, then the parameter inspectors.&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-96-WCFExtensibility/3414_2E00_WcfRuntime_2E00_cs"&gt;Code in this post&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;Carlos Figueira    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;     &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figueira&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10155887" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Extensibility/">Extensibility</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item><item><title>Microsoft .NET Framework 4 Platform Update 1</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/18/microsoft-net-framework-4-platform-update-1.aspx</link><pubDate>Mon, 18 Apr 2011 21:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10155403</guid><dc:creator>Steve Danielson</dc:creator><slash:comments>23</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10155403</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/18/microsoft-net-framework-4-platform-update-1.aspx#comments</comments><description>&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;The Microsoft .NET Framework 4 Platform Update 1 released today, 4/18/2011.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;The Microsoft .NET Framework 4 Platform Update 1 is a platform update that is a set of new features that provides additional functionality for top customer requests and important scenarios.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;The features that are enabled in this update are:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;Windows Workflow Foundation (WF)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;State machine workflows&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;New classes added: &lt;/span&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.statemachine.aspx"&gt;StateMachine&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;, &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.state.aspx"&gt;State&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;, &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.core.presentation.finalstate.aspx"&gt;FinalState&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;, &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.transition.aspx"&gt;Transition&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;, &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.tracking.statemachinestatequery.aspx"&gt;StateMachineStateQuery&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;, &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.tracking.statemachinestaterecord.aspx"&gt;StateMachineStateRecord&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/gg983472.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Getting Started Tutorial: How to Create a State Machine Workflow&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a target="_blank" href="http://go.microsoft.com/fwlink/?LinkId=216427"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Windows Workflow Foundation (WF4) - Introduction to State Machine Hands On Lab&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh180857.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;State Machine Activity Designers&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee264171.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;State Machine Workflows&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: #000000;"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;a href="http://blogs.msdn.com/b/endpoint/archive/2011/04/20/wf4-state-machine-user-experience.aspx"&gt;WF4 State Machine User Experience&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;SqlWorkflowInstanceStore support for SQL Azure&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;The scripts that create the persistence database are modified to be compatible with Sql Azure&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;Retry semantics have been added and new error codes added that are specific to SQL Azure scenarios&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;For more information, see the More Information section of &lt;a href="http://support.microsoft.com/kb/2478063" title="http://support.microsoft.com/kb/2478063"&gt;KB2478063&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&lt;span style="color: #000000;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.compensationextension.aspx"&gt;CompensationExtension&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt; class, which enables custom workflow hosts to use WF4 compensation&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;The Microsoft .NET Platform Update 1 consists of three packages:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;Microsoft .NET Framework 4 Platform Update 1 (&lt;a href="http://support.microsoft.com/kb/2478063" title="http://support.microsoft.com/kb/2478063"&gt;KB2478063&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;This package contains the runtime files for the platform update. This package must be deployed on systems where applications that target the platform update are deployed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;Multi-Targeting Pack for Microsoft .NET Framework 4 Platform Update 1 (&lt;a href="http://support.microsoft.com/kb/2495638" title="http://support.microsoft.com/kb/2495638"&gt;KB2495638&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;This package contains reference assemblies and intellisense files for the platform update. This package is installed as part of the next package.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;Microsoft .NET Framework 4 Platform Update 1 &amp;ndash; Design-time Package for Visual Studio 2010 SP1 (&lt;a href="http://support.microsoft.com/kb/2495593" title="http://support.microsoft.com/kb/2495593"&gt;KB2495593&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;This package installs the previous two packages and configures Visual Studio 2010 SP1 with new .NET Framework targeting profiles, intellisense, and adds the state machine activities to the toolbox.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;To develop workflow applications in Visual Studio 2010 SP1 that target the new Platform Update 1 functionality, the &lt;/span&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=209198"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Microsoft .NET Framework 4 Platform Update 1 &amp;ndash; Design-time Package for Visual Studio 2010 SP1 (KB2495593)&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt; must be installed. Once it is installed, the .NET Framework 4 Platform Update 1 (KB2478063) profile can be chosen when creating a new .NET application.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60/5810_2E00_.NET-Framework-4-Platform-Update-1-New-Project.jpg" border="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;T&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;here are two new profiles added to Visual Studio when the Design-time Package for Visual Studio 2010 SP1 (KB2495593) is installed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="font-size: small;"&gt;.NET Framework 4 Platform Update 1 (KB2478063)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;.NET Framework 4 Client Profile Platform Update 1 (KB2478063)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;When a new project is created with the platform update profile selected, the .NET Framework 4 Client Profile Platform Update 1 (KB2478063) is used. The .NET Framework 4 Platform Update 1 (KB2478063) profile builds on the .NET Framework 4 profile, and the .NET Framework 4 Client Profile Platform Update 1 (KB2478063) profile builds on the .NET Framework 4 Client Profile. The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. For more information, see &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc656912.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;.NET Framework Client Profile&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;To choose either profile or change the profile after a project has been created, right-click the project in Solution Explorer, choose Properties, and select the desired profile from the Target framework drop-down.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/1000x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60/6177_2E00_.NET-Framework-4-Platform-Update-1-Project-Properties.jpg" border="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;When either of these profiles is selected, the features in the platform update are available and the State Machine activities are available in the Toolbox.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60/5327_2E00_.NET-Framework-4-Platform-Update-1-State-Machine-Activities.jpg" border="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;
&lt;p class="MsoListParagraph"&gt;To configure .NET Framework 4 Platform Update 1 on computers with Visual Studio 2010 SP1 that are going to be used to develop applications that target the functionality in the platform update, install &lt;a href="http://go.microsoft.com/fwlink/?LinkID=209198"&gt;Microsoft .NET Framework 4 Platform Update 1 &amp;ndash; Design-time Package for Visual Studio 2010 SP1 (KB2495593)&lt;/a&gt;.&lt;/p&gt;
&lt;p class="MsoListParagraph"&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Note: &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5"&gt;&lt;span style="color: #0000ff;"&gt;Microsoft Visual Studio 2010 Service Pack 1&lt;/span&gt;&lt;/a&gt; is required to install the Design-time Package for Visual Studio 2010 SP1 (KB2495593)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;To configure a computer on which applications that target the .NET Framework 4 Platform Update 1 are to be deployed, deploy &lt;a href="http://go.microsoft.com/fwlink/?LinkID=209209"&gt;Microsoft .NET Framework 4 Platform Update 1 (KB2478063)&lt;/a&gt; and the appropriate version of the .NET Framework 4.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="color: #1f497d;"&gt;If the application targets &lt;/span&gt;.NET Framework 4 Client Profile Platform Update 1 (KB2478063), you must also deploy either:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="color: #1f497d;"&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7&amp;amp;displaylang=en"&gt;Microsoft .NET Framework 4&lt;/a&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="color: #1f497d;"&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=E5AD0459-CBCC-4B4F-97B6-FB17111CF544"&gt;Microsoft .NET Framework 4 Client Profile&lt;/a&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="color: #1f497d;"&gt;If the application targets &lt;/span&gt;.NET Framework 4 Platform Update 1 (KB2478063), you must also deploy:&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="color: #1f497d;"&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7&amp;amp;displaylang=en"&gt;Microsoft .NET Framework 4&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;&lt;/span&gt;

&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;For information on how to use the new state machine functionality in .NET Framework 4 Platform Update 1, see:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraph"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/gg983472.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Getting Started Tutorial: How to Create a State Machine Workflow&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;a target="_blank" href="http://go.microsoft.com/fwlink/?LinkId=216427"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Windows Workflow Foundation (WF4) - Introduction to State Machine Hands On Lab&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh180857.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;State Machine Activity Designers&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee264171.aspx"&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;State Machine Workflows&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10155403" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF4/">WF4</category></item><item><title>WF 4 hosting options: IIS, AppFabric, and Windows Service</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/18/wf-4-hosting-options-iis-appfabric-and-windows-service.aspx</link><pubDate>Mon, 18 Apr 2011 20:29:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10155365</guid><dc:creator>Patrick D. Fletcher [MSFT]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10155365</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/18/wf-4-hosting-options-iis-appfabric-and-windows-service.aspx#comments</comments><description>&lt;p&gt;Most of the Windows Workflow Foundation samples use workflows that are hosted in a console application, but this isn't a realistic scenario for real-world workflows. Workflows in actual business applications will be hosted in persistent processes- either a Windows service authored by the developer, or a server application such as IIS or AppFabric. The differences between these approaches are as follows.&lt;/p&gt;
&lt;h2&gt;Hosting workflows in IIS with Windows AppFabric&lt;/h2&gt;
&lt;p&gt;Using IIS with AppFabric is the preferred host for workflows. The host application for workflows using AppFabric is Windows Activation Service, which removes the dependency on HTTP over IIS alone. &lt;/p&gt;
&lt;h2&gt;Hosting workflows in IIS&lt;/h2&gt;
&lt;p&gt;Using IIS alone is not recommended, as there are management and monitoring tools available with AppFabric that facilitate maintenance of running applications. Workflows should only be hosted in IIS alone if there are infrastructure concerns with moving to AppFabric.&lt;/p&gt;
&lt;h2&gt;Hosting a workflow in a custom Windows Service&lt;/h2&gt;
&lt;p&gt;Creating a custom workflow service to host the workflow will require the developer to duplicate a lot of the functionality provided out-of-box by AppFabric, but will allow for more flexibility with custom functionality. This option should only be considered if AppFabric proves to not be an option.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10155365" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/wf+4+hosting+iis+appfabric/">wf 4 hosting iis appfabric</category></item><item><title>WF4 Versioning Spike: Planning for Change</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/13/wf4-versioning-spike-planning-for-change.aspx</link><pubDate>Wed, 13 Apr 2011 14:20:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10153294</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10153294</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/13/wf4-versioning-spike-planning-for-change.aspx#comments</comments><description>&lt;p&gt;In my investigation of versioning issues with Windows Workflow Foundation I’ve come to one important conclusion.&amp;#160; This isn’t something new, in fact at TechEd 2008 when I gave my very first “chalk talk” about WF3.5 I said that this issue (versioning) was going to be something that you must plan for.&lt;/p&gt;  &lt;p&gt;As architects and developers, we are often so focused on getting to Version 1 we rarely think about what will happen when we need to move to Version 2.&amp;#160; Of course, we know version 2 is going to happen (Unless version 1 is so bad that nobody wants version 2).&amp;#160; So let’s think about this for a moment… &lt;/p&gt;  &lt;p&gt;&lt;object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="512" height="288"&gt;&lt;param name="minRuntimeVersion" value="4.0.50401.0" /&gt;&lt;param name="source" value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" /&gt;&lt;param name="initParams" value="mediaurl=http://smooth.ch9.ms/ch9/d089/cebe9cad-ea98-4be2-8e4d-9ebf0004d089/endpointWFVersioningPt2.ism/manifest,thumbnail=http://media.ch9.ms/ch9/d089/cebe9cad-ea98-4be2-8e4d-9ebf0004d089/endpointWFVersioningPt2_512_ch9.jpg,deliverymethod=adaptivestreaming,autoplay=false,entryid=cebe9cadea984be28e4d9ebf0004d089" /&gt;&lt;/object&gt;&lt;/p&gt;  &lt;h3&gt;What is this versioning problem?&lt;/h3&gt;  &lt;p&gt;Let’s think about this problem outside of the context of workflow for a moment. Remember when you first learned about objects?&amp;#160; They told you that objects consist of three elements identity, state and behavior.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/2772.image_5F00_42471269.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/8156.image_5F00_thumb_5F00_36B1552A.png" width="244" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Over time you learned that you could make a copy of the state and save it somewhere else (like a database) and then at some later point, load the state back into your object.&amp;#160; When you did this you opened the door to the problem of versioning.&lt;/p&gt;  &lt;p&gt;Your object (v1) creates state which we could think of as (s1).&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/7266.image_5F00_56602EF2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/7587.image_5F00_thumb_5F00_35D8EF40.png" width="239" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then at some later time you load the state (s1) back into your object (v1) and everything is great.&amp;#160; But then change happens…    &lt;br /&gt;You change your class definition in some way and when you load your state…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/2388.image_5F00_599216DA.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/6518.image_5F00_thumb_5F00_14E57C99.png" width="240" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Ok – well maybe it doesn’t go boom but it could.&amp;#160; Of course it depends on the kind of change you made to the behavior of your object.&amp;#160; State is not just data, it is data with meaning and the meaning it has depends (to some degree) on your intention as the designer of the behavior.&amp;#160; And obviously if you changed the behavior in a very significant way, the state might go boom when you try to load it.&lt;/p&gt;  &lt;p&gt;Now let’s consider a Workflow in the same situation.&amp;#160; The biggest difference is that with a workflow you don’t create the instance.&amp;#160; In fact, the only thing you create is the Workflow Definition and you hand that to the Workflow Runtime which creates the Workflow Instance (which you never actually see because it is hidden inside the Workflow Runtime).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5037.image_5F00_7F87C730.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5025.image_5F00_thumb_5F00_05CE9DBF.png" width="244" height="229" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;What happens when you change your workflow runtime and load a persisted instance?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5444.image_5F00_6C669A84.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5050.image_5F00_thumb_5F00_0BA94158.png" width="244" height="238" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Yes.. things go boom.&amp;#160; And unlike the object example there is very little you can do about this one.&amp;#160; The state is created and managed by the workflow runtime.&amp;#160; You don’t have the same opportunity to get in the middle of this and fix it as you do when you write the code that manages the state.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;In the next release of .NET we are adding a feature called Dynamic Update which offers one path to fixing up the state so that it does not go boom but here today I’m speaking only of how .NET 4 behaves.&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Planning for Change&lt;/h3&gt;  &lt;p&gt;Now that we know what the problem is we can come up with a way to think about change and the first truth we must consider is that we must plan for change.&amp;#160; We know that change will happen and I am asserting that planned change is always better than unplanned change (at least when it comes to software).&lt;/p&gt;  &lt;p&gt;In my &lt;a href="http://blogs.msdn.com/b/rjacobs/archive/2011/03/30/wf4-workflow-versioning-spike.aspx"&gt;previous post&lt;/a&gt; on this versioning spike I described two scenarios for change.&amp;#160; The first question we want to ask will help us decide which scenario we are facing.&lt;/p&gt;  &lt;h3&gt;Can we allow persisted instances to complete?&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;Side By Side Version Aware Routing&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Suppose we have 1000 persisted workflow instances which were created with V1.&amp;#160; We need to decide if these workflow instances can complete using the V1 definition.&amp;#160; I we can allow them to complete then our versioning problem becomes a message routing problem.&amp;#160; What we must do is figure out a way to route messages meant for V1 instances to be routed to V1 instances and all other messages will route to V2 instances. If you want to see an example of doing this check out the &lt;a href="http://archive.msdn.microsoft.com/AppFabricRefImpl"&gt;AppFabric Reference Implementation: Managing the LifeCycle of a WorkFlow Service&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If that solves your problem then GoTo(EndOfBlog) Else ReadOn()&lt;/p&gt;  &lt;h3&gt;Are the changes breaking?&lt;/h3&gt;  &lt;p&gt;Maybe we decide that we can’t allow our persisted instances to complete because of a policy change or perhaps there is a bug in our workflow.&amp;#160; If that is the case we need to figure out if there is a way we can make the necessary change without causing the workflow to go boom when we load it.&lt;/p&gt;  &lt;h3&gt;A Change Is Breaking If…&lt;/h3&gt;  &lt;ol&gt;   &lt;li&gt;It causes the workflow to go boom when you load it &lt;/li&gt;    &lt;li&gt;It produces an incorrect result &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Our official position on the Workflow team is that any change is a breaking change. Why? Because the truth is that there are so many ways your change could break things that we can’t possibly say that any given change is safe. However as you saw in my previous post there are some changes which might work but you can’t know for sure until you test them. You do have tests don’t you?&lt;/p&gt;  &lt;p&gt;Sometimes the change is breaking when the logic of the workflow is broken by the change.&amp;#160; Imagine a workflow which loops and accumulates a result.&amp;#160; I can look in the Instance Store and see that I have a persisted instance which is in the middle of that loop.&amp;#160; If I make a change to the way the result is accumulated is that a breaking change?&lt;/p&gt;  &lt;p&gt;The answer depends on which iteration of the loop we are in.&amp;#160; If it is the first iteration then the change is not breaking because we have not accumulated a result yet.&amp;#160; If it is any other value then it is not safe to change the expression which calculates the result because part of the accumulated result will have been accumulated under the old behavior and part from the new behavior.&amp;#160; There is no way we can produce a correct result in this scenario.&lt;/p&gt;  &lt;h3&gt;If The Change Is Breaking&lt;/h3&gt;  &lt;p&gt;If the change is breaking then there is no safe means to upgrade persisted instances.&amp;#160; That leaves us only one option… Delete and Resubmit.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How do we delete a persisted instance?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;First you have to find it.&amp;#160; If you look in the InstancesTable (if you are using SqlWorkflowInstanceStore) you will see a lot of Guids and Binary data.&amp;#160; It is difficult to know which Instance you are looking for unless you have planned for it.&amp;#160; You need to store a human readable identifier of some kind that you can link to the InstanceId.&amp;#160; That way you can find and delete the correct record.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Where should you store this identifier?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You can store it in the InstanceStore or you can store it in another database.&amp;#160; SqlWorkflowInstanceStore provides a mechanism for doing this called &lt;a href="http://msdn.microsoft.com/en-us/library/ee364726.aspx"&gt;PromotedProperties&lt;/a&gt;.&amp;#160; This is the good news.&amp;#160; The bad news is that using PromotedProperties is not as easy or simple as it should be.&amp;#160; Fortunately we do have sample code in the WF4 Samples which includes a &lt;a href="http://msdn.microsoft.com/en-us/library/ff642473.aspx"&gt;Property Promotion activity&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;If you use this technique you can get the InstanceId and whatever other values you need to make a decision and these values will end up in the InstancePromotedProperties table.&amp;#160; Then when the workflow completes these values will get cleaned up like the rest of the instance data.&lt;/p&gt;  &lt;p&gt;Of course, you can always store these values in some other database if you like.&amp;#160; Then you have to come up with a way to clear out the values as workflows complete.&amp;#160; I tried both ways and once I got comfortable with PromotedProperties I think I would say that I prefer that approach.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How do you resubmit?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In order to resubmit you have to save the data that started your workflow somewhere.&amp;#160; Once again using PromotedProperties is a pretty good approach for doing this.&amp;#160; If you decide you need to resubmit you simply grab the values that started the workflow and send them in to start a new instance.&lt;/p&gt;  &lt;p&gt;But.. be careful.&amp;#160; Your workflow may have already done some work under the old (V1) definition.&amp;#160; Now that work will be repeated under (V2) unless you take some action to prevent it.&amp;#160; Ideally you should make your work &lt;a href="http://www.bing.com/Dictionary/search?q=define+idempotent&amp;amp;qpvt=define+idempotent&amp;amp;FORM=DTPDIA"&gt;idempotent&lt;/a&gt; then it won’t matter if it gets done more than once.&lt;/p&gt;  &lt;p&gt;To see how I worked through this problem, watch the following video.&lt;/p&gt;  &lt;p&gt;&lt;object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="512" height="288"&gt;&lt;param name="minRuntimeVersion" value="4.0.50401.0" /&gt;&lt;param name="source" value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5" /&gt;&lt;param name="initParams" value="mediaurl=http://smooth.ch9.ms/ch9/0a0f/86b9c5fa-1ac9-4e82-abbb-9ebf00080a0f/endpointWFVersioningPt3.ism/manifest,thumbnail=http://media.ch9.ms/ch9/0a0f/86b9c5fa-1ac9-4e82-abbb-9ebf00080a0f/endpointWFVersioningPt3_512_ch9.jpg,deliverymethod=adaptivestreaming,autoplay=false,entryid=86b9c5fa1ac94e82abbb9ebf00080a0f" /&gt;&lt;/object&gt;&lt;/p&gt;  &lt;p&gt;Happy Coding!    &lt;br /&gt;Ron Jacobs     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/rjacobs"&gt;http://blogs.msdn.com/rjacobs&lt;/a&gt;     &lt;br /&gt;Twitter: @ronljacobs &lt;a href="http://twitter.com/ronljacobs"&gt;http://twitter.com/ronljacobs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10153294" width="1" height="1"&gt;</description></item><item><title>WCF Extensibility - IOperationBehavior</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/12/wcf-extensibility-ioperationbehavior.aspx</link><pubDate>Tue, 12 Apr 2011 15:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10152595</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10152595</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/12/wcf-extensibility-ioperationbehavior.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;&lt;em&gt;index page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The last of the behavior interfaces in WCF is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.aspx"&gt;IOperationBehavior&lt;/a&gt;. The scope of this one is limited to an individual operation, so one can have different operations in the same contract. For example, the &lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.OperationBehaviorAttribute.aspx"&gt;OperationBehaviorAttribute&lt;/a&gt; can define that some specific operations in the contract will auto-complete transactions (if the operation returns successfully, i.e., does not throw an exception). Operation behaviors are typically used for those scenarios, when one wants fine-grained control over the operations in a service contract.&lt;/p&gt;
&lt;h3&gt;Public implementations in WCF&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Description.DataContractSerializerOperationBehavior.aspx"&gt;DataContractSerializerOperationBehavior&lt;/a&gt;: Defines the runtime behavior for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;DataContractSerializer&lt;/a&gt; used to serialize the parameters to the operation. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Description.XmlSerializerOperationBehavior.aspx"&gt;XmlSerializerOperationBehavior&lt;/a&gt;: Defines the runtime behavior for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt; used to serialize the parameters to the operation. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.OperationBehaviorAttribute.aspx"&gt;OperationBehaviorAttribute&lt;/a&gt;: Defines some attributes which apply to the operation, such as transaction parameters or impersonation options. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.ReceiveContextEnabledAttribute.aspx"&gt;ReceiveContextEnabledAttribute&lt;/a&gt;: Defines that the operation controls the acknowledgement that the message was completely received. Used in queue scenarios. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.TransactionFlowAttribute.aspx"&gt;TransactionFlowAttribute&lt;/a&gt;: Defines whether the operation accepts incoming transactions from a client. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Web.AspNetCacheProfileAttribute.aspx"&gt;AspNetCacheProfileAttribute&lt;/a&gt;: Defines the ASP.NET output cache profile for the operation. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Web.WebGetAttribute.aspx"&gt;WebGetAttribute&lt;/a&gt;: Indicates that the operation (in REST services) is a retrieval operation, to be consumed via HTTP GET requests. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Web.WebInvokeAttribute.aspx"&gt;WebInvokeAttribute&lt;/a&gt;: Indicates that the operation (in REST services) is an invoke operation, to be consumed via HTTP verbs other than GET. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Interface declaration&lt;/h3&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a2bb84a3-7ade-4e2d-bb88-a4b6b96fd651" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IOperationBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;ClientOperation&lt;/span&gt; clientOperation);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;DispatchOperation&lt;/span&gt; dispatchOperation);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription);&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Again, like in the previous behavior interfaces, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.validate.aspx"&gt;Validate&lt;/a&gt; is called first, with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.operationdescription.aspx"&gt;operation description&lt;/a&gt; passed as a parameter. If the behavior finds the description violating some of its logic, it should throw an exception to abort the host (or the client) from opening. &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.addbindingparameters.aspx"&gt;AddBindingParameters&lt;/a&gt; is called next, and again this is not commonly used.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.applydispatchbehavior.aspx"&gt;ApplyDispatchBehavior&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.applyclientbehavior.aspx"&gt;ApplyClientBehavior&lt;/a&gt; are called last, and they receive the operation description and the operation runtime (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.dispatchoperation.aspx"&gt;DispatchOperation&lt;/a&gt; for the server side, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.clientoperation.aspx"&gt;ClientOperation&lt;/a&gt; for client side). Among the properties in the operation runtime which are commonly used are the list of parameter inspectors (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.clientoperation.parameterinspectors.aspx"&gt;client&lt;/a&gt; / &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.dispatchoperation.parameterinspectors.aspx"&gt;server&lt;/a&gt;) and the message formatter (&lt;a href="http://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/"&gt;client&lt;/a&gt; / &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.dispatchoperation.formatter.aspx"&gt;server&lt;/a&gt;), which will be covered later in this series.&lt;/p&gt;
&lt;h3&gt;How to add an operation behavior&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Via service / endpoint / contract description (server)&lt;/strong&gt;: You can obtain a reference to the operation description via the contract description, and from there you can get a reference to the list of operation behaviors:&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:72efe2c0-97e4-4bef-be19-ea349e5b809f" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;"http://"&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;":8000/Service"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Service&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WSHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;""&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; od &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; endpoint.Contract.Operations)&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;od.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationBehavior&lt;/span&gt;());&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Via channel factory / generated proxy (client)&lt;/strong&gt;: Like on the server side, once you get a reference to the endpoint, you can reference the contract, then the operation description collection. Notice that (just like in the service) you don&amp;rsquo;t need to enumerate all the operations, you can select by name to apply the behavior to specific operations.&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2c0ed1f7-6505-4b9d-9630-6d24b03e5e05" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt;(binding, &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(address));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;factory.Endpoint.Contract.Operations.Find(&lt;span style="color:#a31515"&gt;"Add"&lt;/span&gt;).Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationBehavior&lt;/span&gt;());&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Via attributes&lt;/strong&gt;: If the operation behavior is derived from System.Attribute, it can be applied to the operation, either at the contract interface or at the actual implementation of the operation in the service code, and it will be added to the operation description by WCF. Adding it to both places is the same as adding it to a single one (the list of behaviors is a dictionary keyed by the behavior type, so a behavior collection cannot have more than one instance of each type).&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6c52c079-1876-4d32-bc41-8de1fb0b81c6" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyOperationBehaviorAttribute&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Attribute&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;IOperationBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#008000"&gt;// IOperationBehavior implementation&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;li&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ICalculator&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;MyOperationBehavior&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Multiply(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;CalculatorService&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ICalculator&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; x + y;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;MyOperationBehavior&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Multiply(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; x * y;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Using configuration&lt;/strong&gt;: Configuration is not an option for adding operation behaviors.&lt;/p&gt;
&lt;h3&gt;Real world scenario: a better parameter inspector&lt;/h3&gt;
&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.aspx"&gt;IParameterInspector&lt;/a&gt; interface is a great way to analyze the inputs and outputs to operations in WCF services &amp;ndash; it provides a callback where one can look, log, change, etc. the input and output parameters. It also lets the users see the return value of the operation, but doesn&amp;rsquo;t let the inspector change it. A &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f8615de8-5572-4cf6-98c9-0af806e2f708"&gt;few&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/2d18fcd4-1b0e-4b8d-b479-924ba580721f"&gt;posts&lt;/a&gt; from the forums needed to actually change the return value as well. In &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f8615de8-5572-4cf6-98c9-0af806e2f708"&gt;one of them&lt;/a&gt;, the user &lt;a href="http://social.msdn.microsoft.com/profile/antonello%20tesoro"&gt;Antonello Tesoro&lt;/a&gt; offered a great, simple suggestion on how to implement such inspector (wrapping an operation invoker), and I&amp;rsquo;ll implement his idea to show a real usage of operation behaviors.&lt;/p&gt;
&lt;p&gt;And here goes the usual disclaimer &amp;ndash; this is a sample for illustrating the topic of this post, this is not production-ready code. I tested it for a few contracts and it worked, but I cannot guarantee that it will work for all scenarios (please let me know if you find a bug or something missing). Also, for simplicity sake it doesn&amp;rsquo;t have a lot of error handling which a production-level code would, and doesn&amp;rsquo;t support all contract types (asynchronous operations, for example, are only partially supported). Finally, this sample (as well as most other samples in this series) uses extensibility points other than the one for this post (e.g., operation invoker) which are necessary to get a realistic scenario going. I&amp;rsquo;ll briefly describe what they do, and leave to their specific entries a more detailed description of their behavior.&lt;/p&gt;
&lt;p&gt;First, let&amp;rsquo;s define the new inspector interface. It&amp;rsquo;s almost a copy of IParameterInspector, with the only difference being the returnValue parameter to AfterCall being passed as reference:&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8664aa78-47dc-49f3-88e6-a1d1e853645d" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IBetterParameterInspector&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, &lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; returnValue, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState);&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;On to the behavior. On the call to &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.applydispatchbehavior.aspx"&gt;ApplyDispatchBehavior&lt;/a&gt;, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.dispatchoperation.aspx"&gt;DispatchOperation&lt;/a&gt; object is already created and populated. We&amp;rsquo;ll then replace the existing operation invoker with our own implementation, passing the existing one to it:&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ddfb2e8c-845a-4309-b81a-e550bb8136d6" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BetterParameterInspectorOperationBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IOperationBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;IBetterParameterInspector&lt;/span&gt; inspector;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; BetterParameterInspectorOperationBehavior(&lt;span style="color:#2b91af"&gt;IBetterParameterInspector&lt;/span&gt; inspector)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (inspector == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"inspector"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inspector = inspector;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;ClientOperation&lt;/span&gt; clientOperation)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription, &lt;span style="color:#2b91af"&gt;DispatchOperation&lt;/span&gt; dispatchOperation)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dispatchOperation.Invoker = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BetterParameterInspectorOperationInvoker&lt;/span&gt;(operationDescription.Name, dispatchOperation.Invoker, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inspector);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operationDescription)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The new operation invoker will simply delegate all the calls to the original invoker, calling the inspector before and after completing each call. On synchronous method implementations, the implementation of the correlation state is trivial &amp;ndash; simply store the return value of BeforeCall in a local variable, invoke the operation, then use that variable as the correlationState parameter to AfterCall. On asynchronous operations, however, it isn&amp;rsquo;t as simple. For this sample, the code throws if an inspector to an asynchronous operation returns anything other than null on BeforeCall. To fully implement correlation state for such operations, we&amp;rsquo;d need to chain the asynchronous operation as described in &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2009/07/23/chaining-async-calls-in-wcf-or-in-net-in-general.aspx" title="http://blogs.msdn.com/b/carlosfigueira/archive/2009/07/23/chaining-async-calls-in-wcf-or-in-net-in-general.aspx"&gt;http://blogs.msdn.com/b/carlosfigueira/archive/2009/07/23/chaining-async-calls-in-wcf-or-in-net-in-general.aspx&lt;/a&gt; &amp;ndash; too complex for this sample.&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:820f5aec-3d55-4dc3-b825-f939d55755a7" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BetterParameterInspectorOperationInvoker&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IOperationInvoker&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;IOperationInvoker&lt;/span&gt; originalInvoker;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;IBetterParameterInspector&lt;/span&gt; inspector;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; BetterParameterInspectorOperationInvoker(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#2b91af"&gt;IOperationInvoker&lt;/span&gt; originalInvoker, &lt;span style="color:#2b91af"&gt;IBetterParameterInspector&lt;/span&gt; inspector)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.operationName = operationName;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalInvoker = originalInvoker;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inspector = inspector;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] AllocateInputs()&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalInvoker.AllocateInputs();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; Invoke(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inspector.BeforeCall(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.operationName, inputs);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; result = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalInvoker.Invoke(instance, inputs, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; outputs);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inspector.AfterCall(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.operationName, outputs, &lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; result, correlationState);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; InvokeBegin(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs, &lt;span style="color:#2b91af"&gt;AsyncCallback&lt;/span&gt; callback, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; state)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inspector.BeforeCall(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.operationName, inputs);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (correlationState != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"Correlation not implemented yet for asynchronous methods"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalInvoker.InvokeBegin(instance, inputs, callback, state);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; InvokeEnd(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, &lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; result)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; operationResult = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalInvoker.InvokeEnd(instance, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; outputs, result);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.inspector.AfterCall(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.operationName, outputs, &lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; operationResult, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; operationResult;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsSynchronous&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.originalInvoker.IsSynchronous; }&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And that&amp;rsquo;s it. Now let&amp;rsquo;s put them to use. To test this scenario, I&amp;rsquo;ll define two service contract interfaces, one with synchronous operations, one with asynchronous ones.&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2653062e-b7d1-413e-9f5a-37a8ebc4d471" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Subtract(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Divide(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Multiply(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ITestWithAsyncOperation&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;(AsyncPattern = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;)]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; BeginEchoString(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text, &lt;span style="color:#2b91af"&gt;AsyncCallback&lt;/span&gt; callback, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; userState);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; EndEchoString(&lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; asyncResult);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Their implementations are trivial (for the asynchronous one we delegate to the &lt;a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx"&gt;Func&amp;lt;T,TResult&amp;gt;&lt;/a&gt; delegate and let it handle the asynchronous behavior for us).&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ff7ed769-ec82-4187-b222-934ea28582cc" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Service&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;ITestWithAsyncOperation&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; result = x + y;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"{0} + {1} = {2}"&lt;/span&gt;, x, y, result);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Subtract(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; result = x - y;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"{0} - {1} = {2}"&lt;/span&gt;, x, y, result);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Divide(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; result = x / y;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"{0} / {1} = {2}"&lt;/span&gt;, x, y, result);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Multiply(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; result = x * y;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"{0} * {1} = {2}"&lt;/span&gt;, x, y, result);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; BeginEchoString(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text, &lt;span style="color:#2b91af"&gt;AsyncCallback&lt;/span&gt; callback, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; userState)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt; func = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.EchoStringDoWork;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; func.BeginInvoke(text, callback, userState);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; EndEchoString(&lt;span style="color:#2b91af"&gt;IAsyncResult&lt;/span&gt; asyncResult)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt; func = ((System.Runtime.Remoting.Messaging.&lt;span style="color:#2b91af"&gt;AsyncResult&lt;/span&gt;)asyncResult).AsyncDelegate &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; func.EndInvoke(asyncResult);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; EchoStringDoWork(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; input) { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; input; }&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now for setting up the service. This operation behavior needs an instance of an inspector, so it cannot be defined as an attribute (attribute arguments cannot be user-defined objects). We&amp;rsquo;ll define two inspectors, one for the calculator (no negative numbers) and one for the asynchronous operations (no null return values):&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:961f5edc-9862-459d-8e72-8e416d266fef" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;NoNegativesInspector&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IBetterParameterInspector&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; inputs.Length; i++)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;inputs[i] = &lt;span style="color:#2b91af"&gt;Math&lt;/span&gt;.Abs((&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;)inputs[i]);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, &lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; returnValue, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;returnValue = &lt;span style="color:#2b91af"&gt;Math&lt;/span&gt;.Abs((&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;)returnValue);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (outputs != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; outputs.Length; i++)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;outputs[i] = &lt;span style="color:#2b91af"&gt;Math&lt;/span&gt;.Abs((&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;)outputs[i]);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;NoNullReturnValue&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IBetterParameterInspector&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; BeforeCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AfterCall(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; operationName, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, &lt;span style="color:#0000ff"&gt;ref&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; returnValue, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; correlationState)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (returnValue == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;returnValue = &lt;span style="color:#a31515"&gt;"&amp;lt;&amp;lt;null&amp;gt;&amp;gt;"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now for setting up the service itself (and calling it). In one of the endpoints the behavior is applied to all operations; in the other, the behavior is applied to one operation explicitly.&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:859036d3-f9c6-4096-9137-0c372a592987" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;"http://"&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;":8000/Service"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Service&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;""&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; asyncEndpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITestWithAsyncOperation&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;"async"&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; od &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; endpoint.Contract.Operations)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;od.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BetterParameterInspectorOperationBehavior&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;NoNegativesInspector&lt;/span&gt;()));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;asyncEndpoint.Contract.Operations.Find(&lt;span style="color:#a31515"&gt;"EchoString"&lt;/span&gt;).Behaviors.Add(&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BetterParameterInspectorOperationBehavior&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;NoNullReturnValue&lt;/span&gt;()));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.Open();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt;(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"Abs(Abs(33) + Abs(-44)) = {0}"&lt;/span&gt;, proxy.Add(33, -44));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"Abs(Abs(33) - Abs(-44)) = {0}"&lt;/span&gt;, proxy.Subtract(33, -44));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"Abs(Abs(33) * Abs(-44)) = {0}"&lt;/span&gt;, proxy.Multiply(33, -44));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;((&lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt;)proxy).Close();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;factory.Close();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITestWithAsyncOperation&lt;/span&gt;&amp;gt; asyncFactory = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITestWithAsyncOperation&lt;/span&gt;&amp;gt;(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(baseAddress + &lt;span style="color:#a31515"&gt;"/async"&lt;/span&gt;));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ITestWithAsyncOperation&lt;/span&gt; asyncProxy = asyncFactory.CreateChannel();&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(asyncProxy.EndEchoString(asyncProxy.BeginEchoString(&lt;span style="color:#a31515"&gt;"hello"&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(asyncProxy.EndEchoString(asyncProxy.BeginEchoString(&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;((&lt;span style="color:#2b91af"&gt;IClientChannel&lt;/span&gt;)asyncProxy).Close();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;asyncFactory.Close();&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That is it. This is an example on how an operation behavior can be used to implement this scenario. Notice that it only works for the server side, as there&amp;rsquo;s no invoker at the client side (for that side I think I&amp;rsquo;d use an &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageformatter.aspx"&gt;IClientMessageFormatter&lt;/a&gt;). If there is enough demand I&amp;rsquo;ll expand that scenario in the upcoming post for that interface.&lt;/p&gt;
&lt;h3&gt;Coming up&lt;/h3&gt;
&lt;p&gt;We&amp;rsquo;ll look at the interfaces for the runtime, starting at the inspection interfaces (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.aspx"&gt;IClientMessageInspector&lt;/a&gt; / &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspx"&gt;IDispatchMessageInspector&lt;/a&gt; / &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iparameterinspector.aspx"&gt;IParameterInspector&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;[&lt;a href="http://code.msdn.microsoft.com/Better-parameter-inspector-1b8cbf4d"&gt;Code for this post&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;Carlos Figueira    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;     &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figueira&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10152595" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item><item><title>The .NET 4 Platform Update and WF4 State Machine</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/11/the-net-4-platform-update-and-wf4-state-machine.aspx</link><pubDate>Tue, 12 Apr 2011 00:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10152302</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10152302</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/11/the-net-4-platform-update-and-wf4-state-machine.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;em&gt;Update: This went live 4/18/2011, and there are more details here:&lt;/em&gt; &lt;a href="http://blogs.msdn.com/b/endpoint/archive/2011/04/18/microsoft-net-framework-4-platform-update-1.aspx"&gt;Microsoft .NET Framework 4 Platform Update 1&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;On March 25&lt;sup&gt;th&lt;/sup&gt; at his Tech-Ed India keynote Jason Zander announced some great new resources for developers.&amp;nbsp; Our team has been working hard on these releases and I&amp;rsquo;m happy to share with you that on April &lt;span style="text-decoration: line-through;"&gt;25&lt;/span&gt;&lt;sup&gt;&lt;span style="text-decoration: line-through;"&gt;th &lt;/span&gt;18th&lt;/sup&gt; (released early!) the Multi-Targeting Pack for Microsoft .NET Framework 4 Platform Update 1 (KB2495638) will be available for download. &lt;/p&gt;
&lt;p&gt;There are two options for downloading the platform update.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4863f88f-5519-4b66-a195-752746b4389a"&gt;Microsoft .NET Framework 4 Platform Update 1 &amp;ndash; Design-time Update for Visual Studio 2010 SP1 (KB2495593)&lt;/a&gt; which includes Visual Studio updates and framework updates&lt;/li&gt;
&lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=209209"&gt;Multi-Targeting Pack for Microsoft .NET Framework 4 Platform Update 1 (KB2495638)&lt;/a&gt; which includes just the framework updates &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Windows Workflow Foundation - State Machine (.NET Framework Platform Update 1)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;New State Machine workflow model - builds upon WF runtime and add in new workflow style for event-driven processes - Events (or "Triggers") cause "Transitions" between known "States" &lt;/li&gt;
&lt;li&gt;New API and Visual Studio-based designer - enables simplified authoring of State Machine styled flow control &lt;/li&gt;
&lt;li&gt;Fully supported on .NET Framework 4 (replaces CodePlex based solution available today) &lt;/li&gt;
&lt;li&gt;New enhancements over existing CodePlex solution 
&lt;ul&gt;
&lt;li&gt;Entry/Exit actions on State, Conditional and default Transitions with Transition action, scoped variables in StateMachine, and improved Tracking support &lt;/li&gt;
&lt;li&gt;Designer enhancements ease the authoring experience with Auto Connect , Auto Insert and aggregated State and Transition views that aid configuration and navigation &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We also have a great new &lt;a href="http://go.microsoft.com/?linkid=9768290"&gt;Hands on Lab for State Machine&lt;/a&gt; to get you started so why not take an afternoon to learn how you can add the State Machine activity to your solutions. Also if you plan on using extensions from &lt;a href="http://wf.codeplex.com/releases"&gt;Microsoft.Activities&lt;/a&gt; or our unit testing framework &lt;a href="http://wf.codeplex.com/releases"&gt;Microsoft.Activities.UnitTesting&lt;/a&gt; be sure to download version 1.8 which includes binaries built for Platform Update 1.&lt;/p&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;How to Create a State Machine Workflow&lt;/h3&gt;
&lt;p&gt;After installing .NET Framework Platform Update 1, you will see new Target Framework available in Visual Studio in your project properties.&amp;nbsp; Just select one of the Platform Update 1 target framework profiles.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/2502.image_5F00_37F00EBB.png"&gt;&lt;img height="163" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/5722.image_5F00_thumb_5F00_702E85D3.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then create a workflow and you will be happy to see some new activities in your WF4 toolbox.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/0844.image_5F00_1DAFA597.png"&gt;&lt;img height="114" width="191" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/1033.image_5F00_thumb_5F00_488809A9.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Windows Communication Foundation -&amp;nbsp; RIA 1.1 (Included in .NET Framework 4 SP1)&lt;/h4&gt;
&lt;p&gt;And in case you missed it, the WCF RIA team shipped a great new release last month as well.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enhanced support for Windows Azure and SQL Azure - Simplified building cloud RIA applications thru new Business Application Template for Windows Azure Platform.&amp;nbsp; DomainService also now supports both SQL Azure and Windows Azure Tables. &lt;/li&gt;
&lt;li&gt;Custom code-generator extensibility and T4-based code generator - code generation is now abstracted away and implemented via a MEF-based mechanism for you to bring your own code generator; plus a new Text Template (T4) based code generator. &lt;/li&gt;
&lt;li&gt;End-to-end support for complex types - now allows entity members and invoke operation parameters of complex types.&amp;nbsp; Support for complex types covers serialization/deserialization, code generation, metadata addition, edit sessions, change tracking and deep validation. &lt;/li&gt;
&lt;li&gt;Additional customer-requested enhancements including sharing entity types across multiple DomainServices and ViewModel-friendly DataSource. &lt;/li&gt;
&lt;li&gt;Localization - now localized into 9 additional languages, matching the same list of languages supported by Visual Studio 2010 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And of course, we have more great new releases on the way so keep watching this space for more details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10152302" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF4/">WF4</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category></item><item><title>WCF Extensibility – IEndpointBehavior</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/04/05/wcf-extensibility-iendpointbehavior.aspx</link><pubDate>Tue, 05 Apr 2011 14:14:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10150007</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10150007</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/04/05/wcf-extensibility-iendpointbehavior.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;&lt;em&gt;index page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The next behavior in the list is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.aspx"&gt;IEndpointBehavior&lt;/a&gt;. Like the other ones, it can be used to inspect and change the endpoint description (which includes the contract description) and its runtime. Unlike the other behaviors, Endpoint behaviors cannot be applied to endpoints as attributes (unless the attribute is applied to an implementation of a &lt;em&gt;callback&lt;/em&gt; contract in a duplex pattern – see more details below). Endpoint behaviors are typically used to change the behavior of endpoints in a way which doesn’t interfere with other endpoints (which can potentially be using the same contract) in a service. For example, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/a&gt; changes the runtime to understand the WCF REST attributes (WebGet/WebInvoke).&lt;/p&gt;  &lt;h3&gt;Public implementations in WCF&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.callbackbehaviorattribute.aspx"&gt;CallbackBehaviorAttribute&lt;/a&gt;: A client callback (for duplex scenarios) equivalent to the [&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.ServiceBehaviorAttribute.aspx"&gt;ServiceBehavior&lt;/a&gt;]. On a duplex service. the client side acts both as a “normal” client and as a service, receiving callbacks initiated at the server side. This behavior allows the definition of parameters such as concurrency mode, transaction isolation level, among others. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.callbackdebugbehavior.aspx"&gt;CallbackDebugBehavior&lt;/a&gt;: The client callback equivalent to the &lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Description.ServiceDebugBehavior.aspx"&gt;ServiceDebugBehavior&lt;/a&gt;, defining whether the client should respond with unknown exceptions as faults. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.clientcredentials.aspx"&gt;ClientCredentials&lt;/a&gt;: The client equivalent to the &lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Description.ServiceCredentials.aspx"&gt;ServiceCredentials&lt;/a&gt;, where the user can configure the client credentials as well as service authentication settings. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.clientviabehavior.aspx"&gt;ClientViaBehavior&lt;/a&gt;: Defines the address used by the transport when sending a message, which may be different than the endpoint address (a.k.a. the final destination). Useful in proxying / multi-hop conversations. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.dispatchersynchronizationbehavior.aspx"&gt;DispatcherSynchronizationBehavior&lt;/a&gt; (new in 4.0): Defines the ability of the endpoint to send asynchronous replies. Sajay has a &lt;a href="http://blogs.msdn.com/b/sajay/archive/2009/08/03/concurrent-receives-maxpendingreceive.aspx"&gt;great post&lt;/a&gt; about when this can be useful. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.mustunderstandbehavior.aspx"&gt;MustUnderstandBehavior&lt;/a&gt;: Defines whether the endpoint must obey the &lt;a href="http://www.w3.org/TR/soap12-part0/#L1474"&gt;mustUnderstand&lt;/a&gt; attribute in message headers. Normally, if an endpoint receives a message with a header marked with mustUnderstand=”1” (or “true”) then it must process the header, or generate a fault. For routing scenarios, however, we can disable this validation and relay the message to the entity which is supposed to process the headers.Q &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.synchronousreceivebehavior.aspx"&gt;SynchronousReceiveBehavior&lt;/a&gt;: Defines that the channel listener in the endpoint must use a synchronous receive call, instead of the default asynchronous mode. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.transactedbatchingbehavior.aspx"&gt;TransactedBatchingBehavior&lt;/a&gt;: Instructs the endpoint to optimize transfer operations for transports which supports transacted receives. Essentially, it enables the batching of messages for MSMQ services. &lt;a href="http://blogs.msdn.com/b/drnick/archive/2007/05/07/optimizing-msmq.aspx"&gt;This port&lt;/a&gt; from Nick Allen has a good description of the scenario. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/a&gt; (new in 3.5): Enables the &lt;a href="http://msdn.microsoft.com/en-us/library/bb412169.aspx"&gt;WCF web programming model&lt;/a&gt; for this endpoint. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webscriptenablingbehavior.aspx"&gt;WebScriptEnablingBehavior&lt;/a&gt; (new in 3.5): Enables the endpoint to receive requests from an ASP.NET AJAX client. It provides a JavaScript proxy for the client to call the service in a strongly-typed way. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.discovery.endpointdiscoverybehavior.aspx"&gt;EndpointDiscoveryBehavior&lt;/a&gt; (new in 4.0): Controls the content of the discovery metadata returned by a discovery endpoint. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.routing.soapprocessingbehavior.aspx"&gt;SoapProcessingBehavior&lt;/a&gt; (new in 4.0): Defines rules for translating messages between different SOAP versions in a routing scenario. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Interface declaration&lt;/h3&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9c591cf3-e3a8-4e90-8709-137b3182072b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;interface&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Validate(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; AddBindingParameters(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; bindingParameters);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ApplyDispatchBehavior(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpointDispatcher);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ApplyClientBehavior(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ClientRuntime&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; clientRuntime);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The pattern continues like the previous posts: &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.validate.aspx"&gt;Validate&lt;/a&gt; is called first, letting the behavior throw if something does not comply with the behavior rules. For example, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/a&gt; (and the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webscriptenablingbehavior.aspx"&gt;WebScriptEnablingBehavior&lt;/a&gt;) both throw during validation if the binding does not use HTTP (or HTTPS), or if it is a SOAP binding (i.e., if its message version is not &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageversion.none.aspx"&gt;None&lt;/a&gt;). &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.addbindingparameters.aspx"&gt;AddBuindingParameters&lt;/a&gt; is the second one to be called, and it’s not commonly used.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applydispatchbehavior.aspx"&gt;ApplyDispatchBehavior&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applyclientbehavior.aspx"&gt;ApplyClientBehavior&lt;/a&gt; are the last ones to be called, after the runtime has been initialized. At that point, the behaviors can update the runtime, updating listeners / dispatchers and other runtime objects according to its logic. The example below will use an endpoint behavior to add a new listener for the endpoint to create a “help page” similar to the &lt;a href="http://msdn.microsoft.com/en-us/library/ee230442.aspx"&gt;WCF Web HTTP Service Help Page&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;How to add an endpoint behavior&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;Via service / endpoint description (server)&lt;/strong&gt;: On the server side, the list of the behaviors for the endpoint can be accessed via the Behaviors property of the endpoint description, which can be obtained once you add an endpoint to the service.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:111d5b07-a236-4483-8ff1-22086d30ddc2" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;&amp;quot;http://&amp;quot;&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;&amp;quot;:8000/Service&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Service&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyEndpointBehavior&lt;/span&gt;());&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;Via the channel factory / generated proxy (client)&lt;/strong&gt;: The &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channelfactory.aspx"&gt;ChannelFactory&lt;/a&gt; class has an &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channelfactory.endpoint.aspx"&gt;Endpoint&lt;/a&gt; property which is of the same type as the one on the server. Likewise, generated proxies (using svcutil / add service reference) are subclasses of &lt;a href="http://msdn.microsoft.com/en-us/library/ms576141.aspx"&gt;ClientBase&amp;lt;T&amp;gt;&lt;/a&gt;, which also has an &lt;a href="http://msdn.microsoft.com/en-us/library/ms553831.aspx"&gt;Endpoint&lt;/a&gt; property which contains a reference to the list of the endpoint behaviors. Like for contract behaviors, endpoint behaviors need to be added prior to opening the client, otherwise they will not be used.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cf9438d2-f270-4742-aca8-79751c861017" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;TestClient&lt;/span&gt; client = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;TestClient&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;client.Endpoint.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyEndpointBehavior&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; result = client.Add(4, 5);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;Using attributes&lt;/strong&gt;: Endpoint behaviors for “normal” clients / server &lt;em&gt;cannot &lt;/em&gt;be applied as attributes – if you define an attribute class and apply it to either the service class, the contract interface or any operations, it will simply be ignored. For duplex endpoints, however, attribute-based endpoint behaviors can be applied to the class which implements the callback contract.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c8fe7269-1f66-4d49-8c1c-b899d71c673f" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyEndpointBehaviorAttribute&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Attribute&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;In {0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;In {0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().Name);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;In {0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;In {0}.{1}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetType().Name, &lt;span style="color:#2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().Name);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;(CallbackContract = &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITestCallback&lt;/span&gt;))]&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    [&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Ping(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ITestCallback&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    [&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;(IsOneWay = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;)]&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Pong(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Service&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Ping(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;OperationContext&lt;/span&gt;.Current.GetCallbackChannel&amp;lt;&lt;span style="color:#2b91af"&gt;ITestCallback&lt;/span&gt;&amp;gt;().Pong(text);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;[&lt;span style="color:#2b91af"&gt;MyEndpointBehavior&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyCallback&lt;/span&gt; : &lt;span style="color:#0000ff"&gt;global&lt;/span&gt;::&lt;span style="color:#2b91af"&gt;ITestCallback&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Pong(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; text)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Received on client: {0}&amp;quot;&lt;/span&gt;, text);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Program&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;&amp;quot;http://&amp;quot;&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;&amp;quot;:8000/Service&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;WSDualHttpBinding&lt;/span&gt; dualBinding = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WSDualHttpBinding&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;WSDualHttpSecurityMode&lt;/span&gt;.None);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Service&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;), dualBinding, &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        host.Description.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceMetadataBehavior&lt;/span&gt; { HttpGetEnabled = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt; });&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Opening the host&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        host.Open();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; callbackInstance = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyCallback&lt;/span&gt;());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;TestClient&lt;/span&gt; client = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;TestClient&lt;/span&gt;(callbackInstance, dualBinding, &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(baseAddress));&lt;/li&gt; &lt;li&gt;        client.Ping(&lt;span style="color:#a31515"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Press ENTER to close&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/li&gt; &lt;li&gt;        host.Close();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;&amp;quot;Host closed&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;Using configuration&lt;/strong&gt;: If the endpoint behavior has a &lt;a href="http://msdn.microsoft.com/en-us/library/aa734726.aspx"&gt;configuration extension&lt;/a&gt;, then it can be applied directly in the configuration. This works for both service endpoints, and for client endpoints:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:15f8aead-401d-4992-b75c-f26663ab9e47" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;extensions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;add&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;myEndpointBehavior&lt;/span&gt;&amp;quot;&lt;/li&gt; &lt;li&gt;           &lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;assembly-qualified-name-of-extension-class&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;extensions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;behaviors&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;behavior&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;UsingMyEndpointBehavior&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;myEndpointBehavior&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;behavior&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;behaviors&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;services&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;service&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;MyNamespace.MyService&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;endpoint&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;address&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&amp;quot;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;UsingMyEndpointBehavior&lt;/span&gt;&amp;quot;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;binding&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;basicHttpBinding&lt;/span&gt;&amp;quot;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;contract&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;MyNamespace.IMyContract&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;service&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;services&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;client&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;endpoint&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;address&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;http://contoso.com/service&lt;/span&gt;&amp;quot;&lt;/li&gt; &lt;li&gt;              &lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;UsingMyBehavior&lt;/span&gt;&amp;quot;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;              &lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;binding&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;basicHttpBinding&lt;/span&gt;&amp;quot;&lt;/li&gt; &lt;li&gt;              &lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;contract&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;MyNamespace.IMyClientContract&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;client&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Real-world scenario: an endpoint help page&lt;/h3&gt;  &lt;p&gt;One of the nice features added in .NET Framework 4 was a &lt;a href="http://msdn.microsoft.com/en-us/library/ee230442.aspx"&gt;help page for REST endpoints&lt;/a&gt;. It described all the operations on the endpoint, as well as the schema for parameters. A &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/59025b10-b2c7-4dad-b5ca-eebaf085a84a"&gt;few&lt;/a&gt; &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/646df17c-64b9-4401-83f8-47c773422820"&gt;posts&lt;/a&gt; on the forums asked about how to customize that page (or the “service” help page), so this is a generic help page implementation (not only for REST endpoints, but for SOAP ones as well). The implementation idea is similar to the one for the POCO Service Host (described in the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/22/wcf-extensibility-iservicebehavior.aspx"&gt;post about service behaviors&lt;/a&gt;): during the call to &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applydispatchbehavior.aspx"&gt;ApplyDispatchBehavior&lt;/a&gt;, the behavior will add a new dispatcher which can handle requests for the help page. Browser clients will then be able to point to that help page, and get a human-readable description of the endpoint.&lt;/p&gt;  &lt;p&gt;And before I go any further, here goes the usual disclaimer – this is a sample for illustrating the topic of this post, this is not production-ready code. I tested it for a few contracts and it worked, but I cannot guarantee that it will work for all scenarios (please let me know if you find a bug or something missing). Also, for simplicity sake it doesn’t have a lot of error handling which a production-level code would, and doesn’t support all contract types (asynchronous operations, for example). Finally, this sample (as well as most other samples in this series) uses extensibility points other than the one for this post (e.g., operation invoker, instance providers, etc.) which are necessary to get a realistic scenario going. I’ll briefly describe what they do, and leave to their specific entries a more detailed description of their behavior.&lt;/p&gt;  &lt;p&gt;This behavior will also have a customized part of the help page. For this sample, it’s a simple string (the “name of the company” which provides the services), but it can be easily extended to more complex information. Here’s the implementation of &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.aspx"&gt;IEndpointBehavior&lt;/a&gt;. Only ApplyDispatchBehavior will be used here, where we’ll add the new dispatcher to the service. And only if the endpoint address is HTTP – it doesn’t make sense to add a help page for browsers for TCP or named pipes:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:49e9b4ac-5f28-4b2c-8ee2-ce6524b9a145" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HelpPageEndpointBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; companyName;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; HelpPageEndpointBehavior(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; companyName)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.companyName = companyName;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt; endpointAddress = endpoint.Address.Uri;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (endpointAddress.Scheme == &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;.UriSchemeHttp || endpointAddress.Scheme == &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;.UriSchemeHttps)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; address = endpointAddress.ToString();&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!address.EndsWith(&lt;span style="color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                address = address + &lt;span style="color:#a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt; helpPageUri = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(address + &lt;span style="color:#a31515"&gt;&amp;quot;help&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;ServiceHostBase&lt;/span&gt; host = endpointDispatcher.ChannelDispatcher.Host;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;ChannelDispatcher&lt;/span&gt; helpDispatcher = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.CreateChannelDispatcher(host, endpoint, helpPageUri);&lt;/li&gt; &lt;li&gt;            host.ChannelDispatchers.Add(helpDispatcher);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;CreateChannelDispatcher will create the listener (based on WebHttpBinding, which can handle GET requests natively). The help page will be created by an internal class (HelpPageService) which can handle requests for the help page, and an object of that class will be used as a singleton instance for this dispatcher (since the class is thread-safe, we can share the same instance). Unlike in the service behavior, in which we used the operation behaviors to set up the operation dispatcher properties, this time we need to set them ourselves. So we need to define our invoker and message formatter as well.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5c7180b3-6a30-4cc9-bbbf-d30506e122c8" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelDispatcher&lt;/span&gt; CreateChannelDispatcher(&lt;span style="color:#2b91af"&gt;ServiceHostBase&lt;/span&gt; host, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt; helpPageUri)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Binding&lt;/span&gt; binding = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;WebHttpBinding&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt; address = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(helpPageUri);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;IChannelListener&lt;/span&gt; channelListener = binding.BuildChannelListener&amp;lt;&lt;span style="color:#2b91af"&gt;IReplyChannel&lt;/span&gt;&amp;gt;(helpPageUri, bindingParameters);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ChannelDispatcher&lt;/span&gt; channelDispatcher = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelDispatcher&lt;/span&gt;(channelListener, &lt;span style="color:#a31515"&gt;&amp;quot;HelpPageBinding&amp;quot;&lt;/span&gt;, binding);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    channelDispatcher.MessageVersion = &lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt;.None;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;HelpPageService&lt;/span&gt; service = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HelpPageService&lt;/span&gt;(endpoint, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.companyName);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt; endpointDispatcher = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointDispatcher&lt;/span&gt;(address, &lt;span style="color:#a31515"&gt;&amp;quot;HelpPageContract&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;DispatchOperation&lt;/span&gt; operationDispatcher = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DispatchOperation&lt;/span&gt;(endpointDispatcher.DispatchRuntime, &lt;span style="color:#a31515"&gt;&amp;quot;GetHelpPage&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    operationDispatcher.Formatter = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;PassthroughMessageFormatter&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;    operationDispatcher.Invoker = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HelpPageInvoker&lt;/span&gt;(service);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    operationDispatcher.SerializeReply = &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    operationDispatcher.DeserializeRequest = &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    endpointDispatcher.DispatchRuntime.InstanceProvider = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SingletonInstanceProvider&lt;/span&gt;(service);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    endpointDispatcher.DispatchRuntime.Operations.Add(operationDispatcher);&lt;/li&gt; &lt;li&gt;    endpointDispatcher.DispatchRuntime.InstanceContextProvider = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SimpleInstanceContextProvider&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    endpointDispatcher.DispatchRuntime.SingletonInstanceContext = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt;(host, service);&lt;/li&gt; &lt;li&gt;    endpointDispatcher.ContractFilter = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MatchAllMessageFilter&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    endpointDispatcher.FilterPriority = 0;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    channelDispatcher.Endpoints.Add(endpointDispatcher);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; channelDispatcher;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now for the implementation of the helper classes. First the HelpPageService. It’s a very, very simple class which only receives requests for the help page, then returns an instance of a custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;Message&lt;/a&gt; class.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:41eddc2a-b413-4014-8af8-9a43f814bfcd" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HelpPageService&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; companyName;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; HelpPageService(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; companyName)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint = endpoint;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.companyName = companyName;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; Process(&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; input)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HelpPageMessage&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.companyName);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The HelpPageMessage implements the abstract Message class by overriding the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.onwritebodycontents.aspx"&gt;OnWriteBodyContents&lt;/a&gt; method. Since WCF messages are XML-based, we’ll use the XML writer passed to the method to write the HTML (as well-formatted XML). The HTML page generated contains a few tables with information about the endpoint obtained from the description, but it’s plain HTML, not too interesting – although it’s useful to notice that the logic to print the operation signature is too simple, as it doesn’t handle out/ref/array/generic parameters correctly (to handle them all this sample would get too big). The interesting item in the message class is the InitializeMessageProperties method. By default, WCF will use the encoder’s ContentType property to determine the Content-Type header of the response, which is usually some XML (or SOAP) type. By adding a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httpresponsemessageproperty.aspx"&gt;HttpResponseMessageProperty&lt;/a&gt; to the message, we change the response content type to text/html.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e287aea6-c3af-40a7-85d3-9eed03dead5d" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HelpPageMessage&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;MessageHeaders&lt;/span&gt; headers;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;MessageProperties&lt;/span&gt; properties;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; companyName;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; HelpPageMessage(&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; companyName)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.headers = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MessageHeaders&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt;.None);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.properties = InitializeMessageProperties();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint = endpoint;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.companyName = companyName;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MessageHeaders&lt;/span&gt; Headers&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.headers; }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MessageProperties&lt;/span&gt; Properties&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.properties; }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt; Version&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt;.None; }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; OnWriteBodyContents(&lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;html&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;head&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Better help page, presented by &amp;quot;&lt;/span&gt; + &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.companyName);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;style&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.CreateStyleValue());&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;body&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;h1&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Endpoint help page, by &amp;quot;&lt;/span&gt; + &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.companyName);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.WriteEndpointDetails(writer);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.WriteEndpointBehaviors(writer);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.WriteContractOperations(writer);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement(); &lt;span style="color:#008000"&gt;// body&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteEndElement(); &lt;span style="color:#008000"&gt;// html&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; CreateStyleValue()&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;&amp;quot;table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} &amp;quot;&lt;/span&gt; +&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#a31515"&gt;&amp;quot;table th { border-right: 2px white solid; border-bottom: 1.5px white solid; font-weight: bold; background-color: #cecf9c;} &amp;quot;&lt;/span&gt; +&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#a31515"&gt;&amp;quot;table td { border-right: 2px white solid; border-bottom: 1.5px white solid; background-color: #e5e5cc;} &amp;quot;&lt;/span&gt; +&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#a31515"&gt;&amp;quot;h1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} &amp;quot;&lt;/span&gt; +&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#a31515"&gt;&amp;quot;h2 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 20px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} &amp;quot;&lt;/span&gt; +&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#a31515"&gt;&amp;quot;.signature { font-family: Consolas; font-size: 12px; }&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteEndpointDetails(&lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;h2&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Endpoint details&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;table&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Element&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Value&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteEndElement();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Address&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint.Address.ToString());&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Binding&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint.Binding.ToString());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteEndElement();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Contract Type&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint.Contract.ContractType.FullName);&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement(); &lt;span style="color:#008000"&gt;// &amp;lt;/table&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteEndpointBehaviors(&lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;h2&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Endpoint behaviors&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;table&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Type&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint.Behaviors.Count; i++)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;IEndpointBehavior&lt;/span&gt; behavior = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint.Behaviors[i];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;, i.ToString(&lt;span style="color:#2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;, behavior.GetType().FullName);&lt;/li&gt; &lt;li&gt;            writer.WriteEndElement();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteEndElement(); &lt;span style="color:#008000"&gt;// &amp;lt;/table&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteContractOperations(&lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;h2&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Operations&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;table&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Signature&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;th&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;Description&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operation &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.endpoint.Contract.Operations)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;tr&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;, operation.Name);&lt;/li&gt; &lt;li&gt;            writer.WriteStartElement(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            writer.WriteAttributeString(&lt;span style="color:#a31515"&gt;&amp;quot;class&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;signature&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            writer.WriteString(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetOperationSignature(operation));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            writer.WriteEndElement();&lt;/li&gt; &lt;li&gt;            writer.WriteElementString(&lt;span style="color:#a31515"&gt;&amp;quot;td&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.GetOperationDescription(operation));&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            writer.WriteEndElement();&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        writer.WriteEndElement(); &lt;span style="color:#008000"&gt;// &amp;lt;/table&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; GetOperationDescription(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operation)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;DescriptionAttribute&lt;/span&gt;[] description = (&lt;span style="color:#2b91af"&gt;DescriptionAttribute&lt;/span&gt;[])operation.SyncMethod.GetCustomAttributes(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;DescriptionAttribute&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (description == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt; || description.Length == 0 || &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(description[0].Description))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;&amp;quot;Operation &amp;quot;&lt;/span&gt; + operation.SyncMethod.Name;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; description[0].Description;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; GetOperationSignature(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operation)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt; sb = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;StringBuilder&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (operation.SyncMethod != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;MethodInfo&lt;/span&gt; method = operation.SyncMethod;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (method.ReturnType == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt; || method.ReturnType == &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;void&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                sb.Append(&lt;span style="color:#a31515"&gt;&amp;quot;void&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                sb.Append(method.ReturnType.Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sb.Append(&lt;span style="color:#a31515"&gt;&amp;#39; &amp;#39;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            sb.Append(method.Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sb.Append(&lt;span style="color:#a31515"&gt;&amp;#39;(&amp;#39;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;ParameterInfo&lt;/span&gt;[] parameters = method.GetParameters();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; parameters.Length; i++)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (i &amp;gt; 0)&lt;/li&gt; &lt;li&gt;                {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    sb.Append(&lt;span style="color:#a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;                }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;                sb.AppendFormat(&lt;span style="color:#a31515"&gt;&amp;quot;{0} {1}&amp;quot;&lt;/span&gt;, parameters[i].ParameterType.Name, parameters[i].Name);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            sb.Append(&lt;span style="color:#a31515"&gt;&amp;#39;)&amp;#39;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;NotImplementedException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;Behavior not yet implemented for async operations&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; sb.ToString();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MessageProperties&lt;/span&gt; InitializeMessageProperties()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;MessageProperties&lt;/span&gt; result = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MessageProperties&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;HttpResponseMessageProperty&lt;/span&gt; httpResponse = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HttpResponseMessageProperty&lt;/span&gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        httpResponse.StatusCode = &lt;span style="color:#2b91af"&gt;HttpStatusCode&lt;/span&gt;.OK;&lt;/li&gt; &lt;li&gt;        httpResponse.Headers[&lt;span style="color:#2b91af"&gt;HttpResponseHeader&lt;/span&gt;.ContentType] = &lt;span style="color:#a31515"&gt;&amp;quot;text/html&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        result.Add(&lt;span style="color:#2b91af"&gt;HttpResponseMessageProperty&lt;/span&gt;.Name, httpResponse);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The instance provider will always return the singleton instance of the HelpPageService class – nothing too fancy here. The operation invoker implementation is simple – it will always deliver the incoming Message object to the singleton HelpPageService instance.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5f6ead75-fc95-4e19-b431-e68b6bb39dde" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SingletonInstanceProvider&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IInstanceProvider&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; SingletonInstanceProvider(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.instance = instance;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; GetInstance(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; instance;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; GetInstance(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; instance;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ReleaseInstance(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;HelpPageInvoker&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IOperationInvoker&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;HelpPageService&lt;/span&gt; service;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; HelpPageInvoker(&lt;span style="color:#2b91af"&gt;HelpPageService&lt;/span&gt; service)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.service = service;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] AllocateInputs()&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[1];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; Invoke(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        outputs = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[0];&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.service.Process((&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt;)inputs[0]);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; IAsyncResult InvokeBegin(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] inputs, AsyncCallback callback, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; state)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; NotSupportedException();&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; InvokeEnd(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; instance, &lt;span style="color:#0000ff"&gt;out&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] outputs, IAsyncResult result)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; NotSupportedException();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsSynchronous&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;; }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Finally, the instance context provider is the same as the one used in the service behavior sample. And the message formatter (converting between &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;Message&lt;/a&gt; objects and operation parameters) is trivial, since the operation in the service takes a parameter of that type and returns a value of the same type, so it simply passes them through.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7e4d39d1-b100-4099-8ba4-010ac05394ae" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SimpleInstanceContextProvider&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IInstanceContextProvider&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; GetExistingInstanceContext(&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message, &lt;span style="color:#2b91af"&gt;IContextChannel&lt;/span&gt; channel)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; InitializeInstanceContext(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext, &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message, &lt;span style="color:#2b91af"&gt;IContextChannel&lt;/span&gt; channel)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsIdle(&lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; NotifyIdle(&lt;span style="color:#2b91af"&gt;InstanceContextIdleCallback&lt;/span&gt; callback, &lt;span style="color:#2b91af"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;PassthroughMessageFormatter&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IDispatchMessageFormatter&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DeserializeRequest(&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; message, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        parameters[0] = message;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Message&lt;/span&gt; SerializeReply(&lt;span style="color:#2b91af"&gt;MessageVersion&lt;/span&gt; messageVersion, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt;[] parameters, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; result)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;Message&lt;/span&gt;)result;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;And that’s it. The help page for REST endpoints also contains links to help pages for specific operations and operations schema. To to the same with this example one would need to simply create (one for each new page to be retrieved), or return a different message depending on the request URI.&lt;/p&gt;  &lt;h3&gt;Coming up&lt;/h3&gt;  &lt;p&gt;The last behavior interface (&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.aspx"&gt;IOperationBehavior&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://code.msdn.microsoft.com/WCF-Custom-Help-Page-6f5a90f0"&gt;Code in this post&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;  &lt;p&gt;Carlos Figueira   &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;    &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figueira&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10150007" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item><item><title>(WF4) Why can’t I change the TypeArgument of Switch&lt;&gt; or FlowSwitch&lt;&gt; using the property grid?</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/03/31/wf4-why-can-t-i-change-the-typeargument-of-switch-lt-gt-or-flowswitch-lt-gt-using-the-property-grid.aspx</link><pubDate>Thu, 31 Mar 2011 19:07:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10148346</guid><dc:creator>tilovell09</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10148346</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/03/31/wf4-why-can-t-i-change-the-typeargument-of-switch-lt-gt-or-flowswitch-lt-gt-using-the-property-grid.aspx#comments</comments><description>&lt;p&gt;I don’t remember anyone ever actually asking me this, but I found myself wondering the question while rustling up a quick rehosting app.&lt;/p&gt;  &lt;p&gt;Foreach&amp;lt;&amp;gt; activity lets you change the TypeArgument dynamically via the property grid. But FlowSwitch&amp;lt;&amp;gt; doesn’t. Why? &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/0333.image_5F00_040F305A.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-03-60-metablogapi/1321.image_5F00_thumb_5F00_23BE0A22.png" width="358" height="187" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As usual, although it take a while, I like investigating issues like this in a practical way. Is it possible for us to ‘Add’ the TypeArgument property in the property grid for FlowSwitch&amp;lt;&amp;gt; in the same way that ForEach&amp;lt;&amp;gt; does? Starting off with disassembly diving, we can figure out that there is a bunch of internal classes like &lt;em&gt;FeatureAttribute&lt;/em&gt;, &lt;em&gt;UpdatableGenericArgumentsFeature&lt;/em&gt; and &lt;em&gt;GenericArgumentUpdaterService &lt;/em&gt;which are involved in the addition of the TypeArgument property to the ForEach&amp;lt;&amp;gt; activity’s property grid. We can also figure out that &lt;em&gt;none of that really matters&lt;/em&gt;. Because GenericArgumentUpdaterService is really just a helper class for using a regular public API which is &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.presentation.model.attachedpropertiesservice.aspx"&gt;AttachedPropertiesService&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;What is AttachedPropertiesService, and what is it being used for here?     &lt;br /&gt;    &lt;br /&gt;For a quick and abstract intro on AttachedPropertiesService, see Matt’s old &lt;a href="https://blogs.msdn.com/b/mwinkle/archive/2009/12/06/wf4-design-time-attachedpropertiesservice-and-attached-properties.aspx"&gt;post&lt;/a&gt;. In short, what it allows you to do is add ‘extra properties’ on any type which you want to display in WorfklowDesigner. This is pretty awesome in its flexibility and power. Want to add a new, fake property on a built-in framework type? You can!&lt;/p&gt;  &lt;p&gt;So, how would we go about adding the updatable TypeArgument property to FlowSwitch&amp;lt;&amp;gt;?&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;u&gt;Step 1: Register the Attached Property&lt;/u&gt;&lt;/h3&gt;  &lt;table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; border-top: medium none; border-right: medium none; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;       &lt;td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; background: #ffff99; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-alt: solid windowtext .5pt" valign="top" width="638"&gt;         &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: ; color: "&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 9.5pt"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt"&gt; &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;static&lt;/font&gt;&lt;/span&gt; &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt; MakeGenericArgumentUpdatable(&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;EditingContext&lt;/font&gt;&lt;/span&gt; context)&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;AttachedPropertiesService&lt;/font&gt;&lt;/span&gt; aps;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;AttachedProperty&lt;/font&gt;&lt;/span&gt; property;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;aps = context.Services.GetService&amp;lt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;AttachedPropertiesService&lt;/font&gt;&lt;/span&gt;&amp;gt;();&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;property = &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt; &lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;AttachedProperty&lt;/font&gt;&lt;/span&gt;&amp;lt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;Type&lt;/font&gt;&lt;/span&gt;&amp;gt;()&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;IsBrowsable = &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;true&lt;/font&gt;&lt;/span&gt;,&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;Name = &lt;span style="color: "&gt;&lt;font color="#a31515"&gt;&amp;quot;TypeArgument&amp;quot;&lt;/font&gt;&lt;/span&gt;,&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;Getter = GetTypeArgument,&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;Setter = SetTypeArgument,&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;OwnerType = &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;typeof&lt;/font&gt;&lt;/span&gt;(&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;FlowSwitch&lt;/font&gt;&lt;/span&gt;&amp;lt;&amp;gt;),&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;};&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;aps.AddProperty(property);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt" class="MsoNormal"&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;We passed in an EditingContext from the WorkflowDesigner where we want this attached property to be registered in. The generic type of our attached property is AttachedProperty&amp;lt;&lt;strong&gt;Type&lt;/strong&gt;&amp;gt;, because the &lt;em&gt;type&lt;/em&gt; of the virtual property we are creating should be &lt;strong&gt;System.Type&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;  &lt;h3&gt;&lt;u&gt;Step 2: Implement the Getter&lt;/u&gt;&lt;/h3&gt;  &lt;table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; border-top: medium none; border-right: medium none; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;       &lt;td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; background: #ffff99; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-alt: solid windowtext .5pt" valign="top" width="638"&gt;         &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: ; color: "&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 9.5pt"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt"&gt; &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;static&lt;/font&gt;&lt;/span&gt; &lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;Type&lt;/font&gt;&lt;/span&gt; GetTypeArgument(&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;ModelItem&lt;/font&gt;&lt;/span&gt; mi)&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt; value = mi.GetCurrentValue();&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;Type&lt;/font&gt;&lt;/span&gt; ret = value.GetType().GetGenericArguments()[0]; &lt;/font&gt;&lt;span style="color: "&gt;&lt;font style="font-size: 9.5pt" color="#008000"&gt;// Should be first generic argument of FlowSwitch&amp;lt;T&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt; ret;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt" class="MsoNormal"&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h3&gt;Just pull apart the ModelItem assuming it is a FlowSwitch&amp;lt;X&amp;gt;, and figure out what X is.&lt;/h3&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;u&gt;Step 3: Implement the Setter&lt;/u&gt;&lt;/h3&gt;  &lt;table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; border-top: medium none; border-right: medium none; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;       &lt;td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; background: #ffff99; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-alt: solid windowtext .5pt" valign="top" width="638"&gt;         &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: ; color: "&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 9.5pt"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt"&gt; &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;static&lt;/font&gt;&lt;/span&gt; &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt; SetTypeArgument(&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;ModelItem&lt;/font&gt;&lt;/span&gt; oldModelItem, &lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;Type&lt;/font&gt;&lt;/span&gt; value)&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;Type&lt;/font&gt;&lt;/span&gt; newItemType = &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;typeof&lt;/font&gt;&lt;/span&gt;(&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;FlowSwitch&lt;/font&gt;&lt;/span&gt;&amp;lt;&amp;gt;).MakeGenericType(value);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt; newItem = &lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;Activator&lt;/font&gt;&lt;/span&gt;.CreateInstance(newItemType);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;ModelItem&lt;/font&gt;&lt;/span&gt; newModelItem = WrapAsModelItem(oldModelItem.GetEditingContext(), newItem);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style="color: "&gt;&lt;font style="font-size: 9.5pt" color="#008000"&gt;// use the somewhat magical MorphHelper&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;MorphHelper&lt;/font&gt;&lt;/span&gt;.MorphObject(oldModelItem, newModelItem);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: ; color: "&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 9.5pt"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt"&gt; &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;static&lt;/font&gt;&lt;/span&gt; &lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;ModelItem&lt;/font&gt;&lt;/span&gt; WrapAsModelItem(&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;EditingContext&lt;/font&gt;&lt;/span&gt; context, &lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt; obj)&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt; context.Services.GetService&amp;lt;&lt;span style="color: "&gt;&lt;font color="#2b91af"&gt;ModelTreeManager&lt;/font&gt;&lt;/span&gt;&amp;gt;().CreateModelItem(&lt;span style="color: "&gt;&lt;font color="#0000ff"&gt;null&lt;/font&gt;&lt;/span&gt;, obj);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="line-height: normal; margin: 0in 0in 0pt" class="MsoNormal"&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;This bit is the weirdest. &lt;strong&gt;MorphHelper.MorphObject&lt;/strong&gt; is being used to replace one ModelItem in the Model Tree with another, and simultaneously updates all references to the old model item. This is a generally useful trick for ‘swapping in’ one object to replace another in the model tree.&lt;/p&gt;  &lt;p&gt;There’s some remaining wrinkles… none of the properties of the old FlowSwitch&amp;lt;&amp;gt; got copied over the new one, ack! Also, the viewstate which tracks the FlowSwitch&amp;lt;&amp;gt;’s position in the designer is lost. Ideally we would also implement that copying behavior in our SetTypeArgument function, so that we don’t unexpected lose flowchart connections whenever someone changes their TypeArgument in the property grid…    &lt;br /&gt;    &lt;br /&gt;You can use MorphHelper.MorphProperties as a best-effort implementation of automatic property cloning. But in this case it’s kind of hard not to lose data, because the type data on the FlowSwitch links is dependent on the type of FlowSwitch&amp;lt;&amp;gt;.     &lt;br /&gt;    &lt;br /&gt;Which is probably the &lt;em&gt;real &lt;/em&gt;reason that FlowSwitch&amp;lt;&amp;gt; doesn’t (currently) show a TypeArgument property. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10148346" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Designer/">Designer</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF4/">WF4</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Attached+Properties/">Attached Properties</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/Rehosting/">Rehosting</category></item><item><title>PDC10–WF4 Session “Windows Workflow Futures”</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/03/31/pdc10-wf4-session-windows-workflow-futures.aspx</link><pubDate>Thu, 31 Mar 2011 16:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10148292</guid><dc:creator>Ron Jacobs</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10148292</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/03/31/pdc10-wf4-session-windows-workflow-futures.aspx#comments</comments><description>&lt;p&gt;Last year we at PDC10 we gave you a preview of the next release of Windows Workflow Foundation.&amp;#160; The video has just been posted to Channel 9.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/Events/PDC/PDC10/FT08"&gt;Windows Workflow Futures&lt;/a&gt;    &lt;br /&gt;Speaker: &lt;a href="http://blogs.msdn.com/rjacobs"&gt;Ron Jacobs&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Learn about the key investments we’re making in Windows Workflow Foundation (WF). See the WF improvements we’re working on for workflow authoring, hosting and management. Learn how we’re bringing WF to the cloud, and how WF and Windows Azure AppFabric will provide a great middle-tier platform for building, deploying, running and managing scalable workflow solutions in Windows Azure. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10148292" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/PDC/">PDC</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF4/">WF4</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WFNews/">WFNews</category></item><item><title>WCF Extensibility – IContractBehavior</title><link>http://blogs.msdn.com/b/endpoint/archive/2011/03/30/wcf-extensibility-icontractbehavior.aspx</link><pubDate>Wed, 30 Mar 2011 16:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10147815</guid><dc:creator>CarlosFigueira</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/endpoint/rsscomments.aspx?WeblogPostID=10147815</wfw:commentRss><comments>http://blogs.msdn.com/b/endpoint/archive/2011/03/30/wcf-extensibility-icontractbehavior.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;This post is part of a series about WCF extensibility points. For a list of all previous posts and planned future ones, go to the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;index page&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Going down the list of behaviors, the second one to be covered is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehavior.aspx"&gt;IContractBehavior&lt;/a&gt;. Like the other ones, it can be used to inspect or change the contract description and its runtime for all endpoints which have that contract. For example, the behavior can validate the contract against the binding to ensure that the it&amp;rsquo;s used the contract is only used with appropriate, or it can modify the runtime for all its operations in a centralized location. Unlike IServiceBehavior mentioned in the previous post, the IContractBehavior is also used to change the client runtime.&lt;/p&gt;
&lt;h3&gt;Public implementations in WCF&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.deliveryrequirementsattribute.aspx"&gt;DeliveryRequirementsAttribute&lt;/a&gt;: Defines ordering requirements for the binding which uses the contract, such as whether the contract requires ordered or queued delivery. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Description.ServiceMetadataContractBehavior.aspx"&gt;ServiceMetadataContractBehavior&lt;/a&gt; (new in 4.0): Determines whether endpoints with the given contract should be exposed in the service metadata. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/System.ServiceModel.Web.JavascriptCallbackBehaviorAttribute.aspx"&gt;JavascriptCallbackBehaviorAttribute&lt;/a&gt;: For REST/JSON endpoints, defines the URL query string parameter name which needs to be passed to change the response from &amp;ldquo;normal&amp;rdquo; JSON to JSONP. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Interface declaration&lt;/h3&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f2f6f7d6-81ae-4f0b-9a6c-76976cc9c6b2" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;interface&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;IContractBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; Validate(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ContractDescription&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; contractDescription, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ApplyDispatchBehavior(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ContractDescription&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; contractDescription, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;DispatchRuntime&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; dispatchRuntime);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ApplyClientBehavior(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ContractDescription&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; contractDescription, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ClientRuntime&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; clientRuntime);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; AddBindingParameters(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ContractDescription&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; contractDescription, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; endpoint, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; bindingParameters);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As was mentioned in the &lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/16/wcf-extensibility-behaviors.aspx"&gt;post about Behaviors&lt;/a&gt;, you can use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehavior.validate.aspx"&gt;Validate&lt;/a&gt; method to ensure that the contract doesn&amp;rsquo;t violate the validation logic on the behavior. One example is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.deliveryrequirementsattribute.aspx"&gt;DeliveryRequirementsAttribute&lt;/a&gt;, which throws if the behavior requires ordered message delivery but it&amp;rsquo;s not there (i.e., using HTTP, MSMQ), or if the behavior says that it cannot have queued delivery but the binding provides that.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehavior.addbindingparameters.aspx"&gt;AddBindingParameters&lt;/a&gt; is used to pass information to the binding elements themselves. It&amp;rsquo;s not used as often, but one (not too common) example would be for a contract, after validating that the binding does not contain any message encoding binding elements, to add one in the binding parameters at this method, thus guaranteeing that it would always use that encoding type.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehavior.applydispatchbehavior.aspx"&gt;ApplyDispatchBehavior&lt;/a&gt; is the method which is most used in the server side. It&amp;rsquo;s called right after the runtime was initialized, so at that point the code has access to the listeners / dispatchers / runtime objects for the server, and can add / remove / modify those. The example below will use an endpoint behavior to change the serializer used by all of the operations in the contract.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehavior.applyclientbehavior.aspx"&gt;ApplyClientBehavior&lt;/a&gt; is the counterpart to ApplyDispatchBehavior for the client side. After the client runtime is initialized, the method is called so that the code can update the client runtime objects.&lt;/p&gt;
&lt;h3&gt;How to add a contract behavior&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Via the service / endpoint description (server)&lt;/strong&gt;: On the server side, once you add an endpoint you can get a reference to it, then you can access its &lt;a href="http://technet.microsoft.com/en-us/library/system.servicemodel.description.serviceendpoint.contract.aspx"&gt;Contract&lt;/a&gt; property, and from there you can access the behavior collection.&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:81e1af56-2729-468f-b402-446b70c727b3" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color:#a31515"&gt;"http://"&lt;/span&gt; + &lt;span style="color:#2b91af"&gt;Environment&lt;/span&gt;.MachineName + &lt;span style="color:#a31515"&gt;":8000/Service"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt; host = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Service&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(baseAddress));&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint = host.AddServiceEndpoint(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;), &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BasicHttpBinding&lt;/span&gt;(), &lt;span style="color:#a31515"&gt;""&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;endpoint.Contract.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyContractBehavior&lt;/span&gt;());&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Via the channel factory / generated proxy (client)&lt;/strong&gt;: The &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channelfactory.aspx"&gt;ChannelFactory&lt;/a&gt; class has an &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channelfactory.endpoint.aspx"&gt;Endpoint&lt;/a&gt; property which is of the same type as the one on the server. Likewise, generated proxies (using svcutil / add service reference) are subclasses of &lt;a href="http://msdn.microsoft.com/en-us/library/ms576141.aspx"&gt;ClientBase&amp;lt;T&amp;gt;&lt;/a&gt;, which also has an &lt;a href="http://msdn.microsoft.com/en-us/library/ms553831.aspx"&gt;Endpoint&lt;/a&gt; property which contains a reference to the contract description, and from there to the behavior collection. Just remember that, once the endpoint has been opened (for channel factories, when it&amp;rsquo;s been explicitly opened or a channel created; for generated clients when it&amp;rsquo;s been explicitly opened or an operation called), modifying the description will have no effect on the runtime, since it&amp;rsquo;s already been created).&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e59b01ce-12db-45e9-b281-602e0461a2b4" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt; factory = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt;&amp;gt;(binding, &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;EndpointAddress&lt;/span&gt;(address));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;factory.Endpoint.Contract.Behaviors.Add(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyContractBehavior&lt;/span&gt;());&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#2b91af"&gt;ITest&lt;/span&gt; proxy = factory.CreateChannel();&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Using attributes&lt;/strong&gt;: if the contract behavior is derived from System.Attribute, it can be applied to either the contract interface or the service class, and it will be added to the contract description by WCF. If it&amp;rsquo;s applied to the contract interface, it will be added to the contract description in all endpoints which use that contract (both server and client). If the attribute is applied to the service implementation, it will be applied to all contracts implemented by the service (unless the attribute also implements the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehaviorattribute.aspx"&gt;IContractBehaviorAttribute&lt;/a&gt; interface, in which case it can be restricted to a single contract type &amp;ndash; see more information in the remarks section of the documentation for &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.icontractbehavior.aspx"&gt;IContractBehavior&lt;/a&gt;.&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ce354823-f434-464c-9601-31cd2ce56331" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyContractBehaviorAttribute&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Attribute&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;IContractBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#008000"&gt;// IContractBehavior implementation&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;li&gt;[&lt;span style="color:#2b91af"&gt;ServiceContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;[&lt;span style="color:#2b91af"&gt;MyContractBehavior&lt;/span&gt;]&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ICalculator&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style="color:#2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Add(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; y);&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Using configuration&lt;/strong&gt;: Configuration is not an option for adding endpoint behaviors.&lt;/p&gt;
&lt;h3&gt;Real world scenario: using a new serializer&lt;/h3&gt;
&lt;p&gt;This has come up a few times in the forums (&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/dcd48a7f-4494-455f-8504-cbdc372badcf"&gt;1&lt;/a&gt;, &lt;a href="http://social.msdn.microsoft.com/forums/en-US/wcf/thread/e4d55f3f-86d1-441d-9187-64fbd8ab2b3d"&gt;2&lt;/a&gt;, &lt;a href="http://social.msdn.microsoft.com/forums/en-us/wcf/thread/9c1231ef-1c32-4a01-afcf-f7782a436e9b"&gt;3&lt;/a&gt;, &amp;hellip;). Most of the time it&amp;rsquo;s about forcing WCF to use &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt;, or replace the default &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;DataContractSerializer&lt;/a&gt; with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.netdatacontractserializer.aspx"&gt;NetDataContractSerializer&lt;/a&gt; (to avoid having to deal with known types in inheritance-heavy scenarios). Other times people really need a new way of serializing / deserializing objects &amp;ndash; for performance or size reasons, for example. In this example I have a custom serializer which knows how to serialize very compactly some data types which are tagged with a specific interface. The interface is a simple one with two methods: one for the object to serialize itself into a stream, and another for an object to initialize itself from a stream.&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b3303433-8e9d-4822-9051-1f5af9304f06" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ICustomSerializable&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteTo(&lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; stream);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt; InitializeFrom(&lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; stream);&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And before I go any further, here goes the usual disclaimer &amp;ndash; this is a sample for illustrating the topic of this post, this is not production-ready code. I tested it for a few inputs and it worked, but I cannot guarantee that it will work for all types (please let me know if you find a bug or something missing). Also, for simplicity sake it doesn&amp;rsquo;t have a lot of error handling which a production-level code would. Finally, this sample (as well as most other samples in this series) uses extensibility points other than the one for this post (e.g., operation behavior, custom serializers, etc.) which are necessary to get a realistic scenario going. I&amp;rsquo;ll briefly describe what they do, and leave to their specific entries a more detailed description of their behavior.&lt;/p&gt;
&lt;p&gt;Below are a few types which implement this interface. They use some helper functions to read/write data in a compact binary format (the code for the helper can be found in the [Code for this post] link at the end). This is a format similar to the one used by the &lt;a href="http://msdn.microsoft.com/en-us/library/cc219210(v=PROT.10).aspx"&gt;.NET XML Binary Format&lt;/a&gt; (the one used by the binary encoding in WCF).&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:73c9005b-967d-4d70-8443-491dc3bd8652" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Product&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ICustomSerializable&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Name;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Unit;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; UnitPrice;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteTo(&lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; stream)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.WriteString(stream, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Name);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.WriteString(stream, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Unit);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.WriteInt(stream, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.UnitPrice);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; InitializeFrom(&lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; stream)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Name = &lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.ReadString(stream);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Unit = &lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.ReadString(stream);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.UnitPrice = &lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.ReadInt(stream);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Order&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ICustomSerializable&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; Id;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Product&lt;/span&gt;[] Items;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt; Date;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteTo(&lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; stream)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.WriteInt(stream, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Id);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.WriteInt(stream, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Items.Length);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Items.Length; i++)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Items[i].WriteTo(stream);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.WriteLong(stream, &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Date.ToBinary());&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; InitializeFrom(&lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; stream)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Id = &lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.ReadInt(stream);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; itemCount = &lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.ReadInt(stream);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Items = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Product&lt;/span&gt;[itemCount];&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; itemCount; i++)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Items[i] = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Product&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Items[i].InitializeFrom(stream);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Date = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.FromBinary(&lt;span style="color:#2b91af"&gt;FormatHelper&lt;/span&gt;.ReadLong(stream));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now to the behavior. In order to easily share the behavior between client and server (after all, both sides need to agree on the serialization format), I&amp;rsquo;m implementing it as an attribute, so we can share the contract definition between the parties and it will be decorated with the behavior. The behavior will do two things: validate that all types which will use the new serializer can be created (i.e., they&amp;rsquo;re public types with a public, parameter-less constructor), and replace a behavior in all of the contract operations. The behavior which selects the serializer in WCF is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.datacontractserializeroperationbehavior.aspx"&gt;DataContractSerializerOperationBehavior&lt;/a&gt; (DCSOB), whose task is to add a formatter to the runtime which knows how to convert between the incoming / outgoing message and the parameters in the operations. We could create a new formatter to do that, but inheriting from DCSOB (even though we won&amp;rsquo;t be using the DataContractSerializer for our custom serialization) will save us time, as it exposes two helper virtual methods that makes it easier to replace the serializer).&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f86598c5-4fc8-4960-a5e5-a9d773fb6457" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyNewSerializerContractBehaviorAttribute&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;Attribute&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;IContractBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddBindingParameters(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;BindingParameterCollection&lt;/span&gt; bindingParameters)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyClientBehavior(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;ClientRuntime&lt;/span&gt; clientRuntime)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ReplaceSerializerOperationBehavior(contractDescription);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ApplyDispatchBehavior(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint, &lt;span style="color:#2b91af"&gt;DispatchRuntime&lt;/span&gt; dispatchRuntime)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ReplaceSerializerOperationBehavior(contractDescription);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Validate(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contractDescription, &lt;span style="color:#2b91af"&gt;ServiceEndpoint&lt;/span&gt; endpoint)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operation &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; contractDescription.Operations)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;MessageDescription&lt;/span&gt; message &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; operation.Messages)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ValidateMessagePartDescription(message.Body.ReturnValue);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;MessagePartDescription&lt;/span&gt; part &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; message.Body.Parts)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ValidateMessagePartDescription(part);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;MessageHeaderDescription&lt;/span&gt; header &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; message.Headers)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ValidateCustomSerializableType(header.Type);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ValidateMessagePartDescription(&lt;span style="color:#2b91af"&gt;MessagePartDescription&lt;/span&gt; part)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (part != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ValidateCustomSerializableType(part.Type);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ValidateCustomSerializableType(&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt; type)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ICustomSerializable&lt;/span&gt;).IsAssignableFrom(type))&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!type.IsPublic)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"Custom serialization is supported in public types only"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;ConstructorInfo&lt;/span&gt; defaultConstructor = type.GetConstructor(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Type&lt;/span&gt;[0]);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (defaultConstructor == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"Custom serializable types must have a public, parameterless constructor"&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ReplaceSerializerOperationBehavior(&lt;span style="color:#2b91af"&gt;ContractDescription&lt;/span&gt; contract)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; od &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; contract.Operations)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; od.Behaviors.Count; i++)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;DataContractSerializerOperationBehavior&lt;/span&gt; dcsob = od.Behaviors[i] &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DataContractSerializerOperationBehavior&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (dcsob != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;od.Behaviors[i] = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyNewSerializerOperationBehavior&lt;/span&gt;(od);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyNewSerializerOperationBehavior&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;DataContractSerializerOperationBehavior&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyNewSerializerOperationBehavior(&lt;span style="color:#2b91af"&gt;OperationDescription&lt;/span&gt; operation) : &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;(operation) { }&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af"&gt;XmlObjectSerializer&lt;/span&gt; CreateSerializer(&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt; type, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; name, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; ns, &lt;span style="color:#2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt;&amp;gt; knownTypes)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyNewSerializer&lt;/span&gt;(type, &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;.CreateSerializer(type, name, ns, knownTypes));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af"&gt;XmlObjectSerializer&lt;/span&gt; CreateSerializer(&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt; type, &lt;span style="color:#2b91af"&gt;XmlDictionaryString&lt;/span&gt; name, &lt;span style="color:#2b91af"&gt;XmlDictionaryString&lt;/span&gt; ns, &lt;span style="color:#2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt;&amp;gt; knownTypes)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyNewSerializer&lt;/span&gt;(type, &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;.CreateSerializer(type, name, ns, knownTypes));&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Finally, the serializer. Implementing a new WCF serializer is a matter of finding a mapping between XML (the internal format used by WCF messages) and the format you want. For this optimized serialization, I&amp;rsquo;ll use a very simple mapping which writes the serialized object as binary data, wrapped inside a XML element. The mapping is done by subclassing &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.xmlobjectserializer.aspx"&gt;XmlObjectSerializer&lt;/a&gt;, by overriding a few methods about reading / writing the object from / to XML reader / writers. Also, since there are types which can be used in the operation but aren&amp;rsquo;t ready for optimized serialization, the serializer is holding on to a reference to the original serializer from WCF, so that they can be used as well. So the implementation checks whether the type being serialized supports custom serialization; if it does, the new logic is used; otherwise it delegates the call to the original serializer for that type.&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8613aade-0aa8-4ce2-9a55-58e40f036fde" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #fff; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyNewSerializer&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;XmlObjectSerializer&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;const&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; MyPrefix = &lt;span style="color:#a31515"&gt;"new"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt; type;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; isCustomSerialization;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;XmlObjectSerializer&lt;/span&gt; fallbackSerializer;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; MyNewSerializer(&lt;span style="color:#2b91af"&gt;Type&lt;/span&gt; type, &lt;span style="color:#2b91af"&gt;XmlObjectSerializer&lt;/span&gt; fallbackSerializer)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.type = type;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.isCustomSerialization = &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;ICustomSerializable&lt;/span&gt;).IsAssignableFrom(type);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.fallbackSerializer = fallbackSerializer;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsStartObject(&lt;span style="color:#2b91af"&gt;XmlDictionaryReader&lt;/span&gt; reader)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.isCustomSerialization)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; reader.LocalName == MyPrefix;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.fallbackSerializer.IsStartObject(reader);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; ReadObject(&lt;span style="color:#2b91af"&gt;XmlDictionaryReader&lt;/span&gt; reader, &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; verifyObjectName)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.isCustomSerialization)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; result = &lt;span style="color:#2b91af"&gt;Activator&lt;/span&gt;.CreateInstance(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.type);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt;(reader.ReadElementContentAsBase64());&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;((&lt;span style="color:#2b91af"&gt;ICustomSerializable&lt;/span&gt;)result).InitializeFrom(ms);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.fallbackSerializer.ReadObject(reader, verifyObjectName);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteEndObject(&lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.isCustomSerialization)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteEndElement();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.fallbackSerializer.WriteEndObject(writer);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteObjectContent(&lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; graph)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.isCustomSerialization)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt; ms = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MemoryStream&lt;/span&gt;();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;((&lt;span style="color:#2b91af"&gt;ICustomSerializable&lt;/span&gt;)graph).WriteTo(ms);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;[] bytes = ms.ToArray();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteBase64(bytes, 0, bytes.Length);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.fallbackSerializer.WriteObjectContent(writer, graph);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; WriteStartObject(&lt;span style="color:#2b91af"&gt;XmlDictionaryWriter&lt;/span&gt; writer, &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; graph)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.isCustomSerialization)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.WriteStartElement(MyPrefix);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.fallbackSerializer.WriteStartObject(writer, graph);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Coming up&lt;/h3&gt;
&lt;p&gt;The remaining 2 behavior interfaces.&lt;/p&gt;
&lt;p&gt;[&lt;a href="http://code.msdn.microsoft.com/WCF-Custom-Serialization-43b3ee7a"&gt;Code in this post&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;[&lt;a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx"&gt;Back to the index&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;Carlos Figueira    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/carlosfigueira"&gt;http://blogs.msdn.com/carlosfigueira&lt;/a&gt;    &lt;br /&gt;Twitter: @carlos_figueira &lt;a href="http://twitter.com/carlos_figueira"&gt;http://twitter.com/carlos_figueira&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10147815" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/endpoint/archive/tags/WCFNews/">WCFNews</category></item></channel></rss>
