<?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>Windows Server AppFabric Customer Advisory Team</title><link>http://blogs.msdn.com/b/appfabriccat/</link><description>Technical guidance &amp;amp; best practices from AppFabric, Azure, BizTalk, WCF, WF, SQL Data Modeling &amp;amp; StreamInsight technology experts</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>We Have Moved to MSDN</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2011/02/07/we-have-moved-to-http-www-appfabriccat-com.aspx</link><pubDate>Mon, 07 Feb 2011 21:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10122457</guid><dc:creator>Christian.Martinez</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10122457</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10122457</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2011/02/07/we-have-moved-to-http-www-appfabriccat-com.aspx#comments</comments><description>&lt;p&gt;We blog too much! We have maxed out the storage space allowed on MSDN blogs.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;All new content will be located on the &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj673464.aspx"&gt;MSDN Library&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;See you there!&lt;/p&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=10122457" width="1" height="1"&gt;</description></item><item><title>Intellisense when editing Service Bus configuration files? Yes please!</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2011/02/07/intellisense-when-editing-service-bus-configuration-files-yes-please.aspx</link><pubDate>Mon, 07 Feb 2011 19:20:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10125826</guid><dc:creator>Paolo Salvatori</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10125826</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10125826</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2011/02/07/intellisense-when-editing-service-bus-configuration-files-yes-please.aspx#comments</comments><description>&lt;h2&gt;The problem&lt;/h2&gt;  &lt;p align="justify"&gt;The setup of &lt;a href="http://www.microsoft.com/downloads/en/results.aspx?freetext=Windows+Azure+AppFabric+SDK&amp;amp;displaylang=en&amp;amp;stype=s_basic"&gt;Windows Azure&amp;#160; AppFabric SDK&lt;/a&gt; adds the elements reported in the table below to the configuration contained in the the &lt;strong&gt;machine.config&lt;/strong&gt; files under the following folders: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;%windir%\Microsoft.NET\Framework\v4.0.30319\Config &lt;/li&gt;    &lt;li&gt;%windir%\Microsoft.NET\Framework64\v4.0.30319\Config &lt;/li&gt; &lt;/ul&gt;  &lt;br /&gt;  &lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="900"&gt;         &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;UTF-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;...
 &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;extensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;...
    &lt;span style="color: blue"&gt;&amp;lt;!-- &lt;/span&gt;&lt;span style="color: green"&gt;Windows Azure AppFabric Service Bus Endpoint Behaviors &lt;/span&gt;&lt;span style="color: blue"&gt;--&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;connectionStatusBehavior&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.ConnectionStatusElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;transportClientEndpointBehavior&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;serviceRegistrySettings&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.ServiceRegistrySettingsElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
   &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;bindingElementExtensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;...
    &lt;span style="color: blue"&gt;&amp;lt;!-- &lt;/span&gt;&lt;span style="color: green"&gt;Windows Azure AppFabric Service Bus Transport Binding Elements &lt;/span&gt;&lt;span style="color: blue"&gt;--&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;tcpRelayTransport&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.TcpRelayTransportElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;httpRelayTransport&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.HttpRelayTransportElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;httpsRelayTransport&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.HttpsRelayTransportElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;onewayRelayTransport&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.RelayedOnewayTransportElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
   &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;bindingElementExtensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
     &lt;/span&gt;...
    &lt;span style="color: blue"&gt;&amp;lt;!-- &lt;/span&gt;&lt;span style="color: green"&gt;Windows Azure AppFabric Service Bus Relay Binding &lt;/span&gt;&lt;span style="color: blue"&gt;--&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;basicHttpRelayBinding&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.BasicHttpRelayBindingCollectionElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;webHttpRelayBinding&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.WebHttpRelayBindingCollectionElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ws2007HttpRelayBinding&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.WS2007HttpRelayBindingCollectionElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;netTcpRelayBinding&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;netOnewayRelayBinding&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.NetOnewayRelayBindingCollectionElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;netEventRelayBinding&lt;/span&gt;&amp;quot; 
         &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.ServiceBus.Configuration.NetEventRelayBindingCollectionElement, Microsoft.ServiceBus, ...&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
   &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;extensions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &lt;/span&gt;...
&lt;span style="color: blue"&gt;&lt;font color="#333333"&gt; &lt;/font&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;...
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;p align="justify"&gt;However, configuring WCF extensions in the machine.config is not sufficient to enable &lt;strong&gt;Intellisense &lt;/strong&gt;on the relay bindings and endpoint behaviors contained in the &lt;a href="http://msdn.microsoft.com/en-us/library/ee172187.aspx"&gt;AppFabric Service Bus Class Library&lt;/a&gt; when you edit the configuration file (web.config, app.config) of an application that exposes or consume services in the cloud. To scope the problem, let’s assume for a moment that you create an on-premises or cloud application that exposes a service via the AppFabric Service Bus. Your service will surely expose one or more endpoints based on one of the relay bindings supplied out-of the-box by the &lt;a href="http://msdn.microsoft.com/en-us/library/ee172187.aspx"&gt;AppFabric Service Bus Class Library&lt;/a&gt;. However, when you try to use Visual Studio to define the configuration of any relay bindings and endpoint behaviors provided by the Service Bus, &lt;a href="http://msdn.microsoft.com/en-us/library/hcw1s69b(v=VS.100).aspx"&gt;IntelliSense&lt;/a&gt; is unable to recognize these elements. For example, the picture below shows what happens when you try to define the configuration for the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.servicebus.webhttprelaybinding.aspx"&gt;WebHttpRelayBinding&lt;/a&gt; and the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.servicebus.transportclientendpointbehavior.aspx"&gt;TransportClientEndpointBehavior&lt;/a&gt;. In a nutshell, you cannot rely on IntelliSense to compose and validate your configuration file using a syntax-driven approach. Moreover, Visual Studio raises a warning for each unrecognized element within your configuration. Now, I don’t know about you, but when I compile my projects I cross my fingers until the build process completes.&lt;strong&gt;&amp;#160;&lt;/strong&gt;When I see the &lt;strong&gt;Rebuild All succeeded&lt;/strong&gt; message on the left-bottom corner of Visual Studio I heave a sigh of relief, but in order to attain the maximum level of happiness, my Errors and Warnings lists must be empty! &lt;/p&gt;

&lt;p align="justify"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/4621.Before_5F00_2B0D9AB3.jpg" /&gt;&lt;/p&gt;

&lt;h2 align="justify"&gt;The solution&lt;/h2&gt;

&lt;p align="justify"&gt;Now, the XSD used by Visual Studio IntelliSense is stored under &lt;strong&gt;&amp;quot;%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas\DotNetConfig.xsd&lt;/strong&gt;&amp;quot;. Hence, I decided to extend this XML schema file to add Intellisense for the bindings and behaviors provided by AppFabric Service Bus. BizTalk Editor came in handy&amp;#160; for this purpose because I could use its cut and paste capabilities to accelerate the task. I created an entry for each relay binding or endpoint behavior defined within the &lt;a href="http://msdn.microsoft.com/en-us/library/ee172187.aspx"&gt;AppFabric Service Bus Class Library&lt;/a&gt; as you can see in the image below:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/7026.DotNetConfig_5F00_05902F20.jpg" /&gt;&lt;/p&gt;

&lt;p align="justify"&gt;After customizing the DotNetConfig.xsd, IntelliSense works as expected as shown in the following picture.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/4377.After_5F00_465E1750.jpg" /&gt;&lt;/p&gt;

&lt;h2 align="justify"&gt;Conclusions&lt;/h2&gt;

&lt;p align="justify"&gt;Utilizing IntelliSense rather than cut and paste or memorization makes it more likely I will enter settings correctly and also gets rid of all of those unsightly warnings! &lt;a href="http://code.msdn.microsoft.com/appfabriccat/Release/ProjectReleases.aspx?ReleaseId=5435"&gt;Here&lt;/a&gt; you can download the Visual Studio 2010 DotNetConfig.xsd customized for the Azure Service Bus. Please drop me a line if you find any problems or improvements to suggest. Thanks!&lt;/p&gt;

&lt;p align="justify"&gt;Review by: &lt;a href="http://blogs.msdn.com/members/Christian.Martinez/"&gt;Christian Martinez&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/Tim-Wieman/ProfileUrlRedirect.ashx"&gt;Tim Wieman&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=10125826" width="1" height="1"&gt;</description></item><item><title>Enterprise Library on Windows Azure: Key Learnings from Customer Project</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/31/enterprise-library-on-windows-azure-key-learnings-from-customer-project.aspx</link><pubDate>Mon, 31 Jan 2011 12:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10124561</guid><dc:creator>Valery M</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10124561</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10124561</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/31/enterprise-library-on-windows-azure-key-learnings-from-customer-project.aspx#comments</comments><description>&lt;p align="justify"&gt;This post has been moved to a new location. Please follow the link below. Thank you.&lt;/p&gt;
&lt;p align="justify"&gt;&lt;a href="http://windowsazurecat.com/2011/02/enterprise-library-on-windows-azure-key-learnings-from-customer-project/"&gt;http://windowsazurecat.com/2011/02/enterprise-library-on-windows-azure-key-learnings-from-customer-project/&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=10124561" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Windows+Azure/">Windows Azure</category></item><item><title>How to use Duplex MEP to communicate with BizTalk from a .NET application or a WF workflow running inside AppFabric Part 3</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/20/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-3.aspx</link><pubDate>Thu, 20 Jan 2011 15:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10118711</guid><dc:creator>Paolo Salvatori</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10118711</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10118711</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/20/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-3.aspx#comments</comments><description>&lt;h1&gt;Introduction&lt;/h1&gt;  &lt;p align="justify"&gt;In the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/11/23/how-using-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-1.aspx"&gt;first article&lt;/a&gt; of the series we discussed how to exchange messages with an orchestration via a two-way WCF Receive Location using the &lt;a href="http://msdn.microsoft.com/en-us/library/ms731184.aspx"&gt;Duplex Message Exchange Pattern&lt;/a&gt;. This form of bi-directional communication is characterized by the ability of both the service and the client to send messages to each other independently either using one-way or request/reply messaging. In a service-oriented architecture or a service bus composed of multiple, heterogeneous systems, interactions between autonomous client and service applications are asynchronous and loosely-coupled. All communications require published and discoverable service contracts, well-known data formats and a shared communication infrastructure. In the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;second part&lt;/a&gt; of the article we saw how to implement an asynchronous communication between a client application and a &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx"&gt;WCF Workflow Service&lt;/a&gt; running within IIS\&lt;a href="http://msdn.microsoft.com/en-us/rampup/gg296345.aspx"&gt;AppFabric Hosting Services&lt;/a&gt; using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt; provided by WF 4.0. Besides, we discussed how to create a custom Activity for extending &lt;strong&gt;AppFabric Tracking&lt;/strong&gt; with user-defined events and how to exploit the XML-based data transformation capabilities provided by the new &lt;a href="http://blogs.msdn.com/b/biztalk_server_team_blog/archive/2010/08/24/improved-productivity-with-biztalk-server-2010-mapper.aspx"&gt;BizTalk Server Mapper&lt;/a&gt; directly in a WF project thanks to the new &lt;strong&gt;Mapper&lt;/strong&gt; Activity contained in the &lt;a href="http://www.microsoft.com/biztalk/en/us/appfabricconnect.aspx"&gt;AppFabric Connect&lt;/a&gt;. In the final article of the series, we’ll examine how to implement an asynchronous communication between a &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx"&gt;WCF Workflow Service&lt;/a&gt; and an Orchestration using WS-Addressing and &lt;a href="http://msdn.microsoft.com/en-us/library/ee358755.aspx"&gt;Content-Based Correlation&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Before explaining the architecture of the demo, let me briefly introduce and discuss some of the techniques that I used to implement my solution.&lt;/p&gt;  &lt;h1 align="justify"&gt;Correlation in WF 4.0&lt;/h1&gt;  &lt;p align="justify"&gt;If you are a WF or a BizTalk developer, you are surely familiar with the concept of correlation. Typically, at runtime workflows or orchestrations have multiple instances executing simultaneously. Therefore, when a workflow service implements an asynchronous communication pattern to exchange messages with other services, correlation provides the mechanism to ensure that messages are sent to the appropriate workflow instance. &lt;a href="http://msdn.microsoft.com/en-us/library/dd456784.aspx"&gt;Correlation&lt;/a&gt; enables relating workflow service messages to each other or to the application instance state, such as a reply to an initial request, or a particular order ID to the persisted state of an order-processing workflow. Workflow Foundation 4.0 provides 2 different categories of correlation called, respectively, &lt;strong&gt;Protocol-Based Correlation&lt;/strong&gt; and &lt;strong&gt;Content-Based Correlation&lt;/strong&gt;. Protocol-based correlations use data provided by the message delivery infrastructure to provide the mapping between messages. Messages that are correlated using protocol-based correlation are related to each other using an object in memory, such as a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.requestcontext.aspx"&gt;RequestContext&lt;/a&gt;, or by a token provided by the transport protocol. Content-based correlations relate messages to each other using application-specified data. Messages that are correlated using content-based correlation are related to each other by some application-defined data in the message, such as a customer number. &lt;/p&gt;  &lt;h1 align="justify"&gt;Protocol-Based Correlation&lt;/h1&gt;  &lt;p align="justify"&gt;Protocol-based correlation uses the transport mechanism to relate messages to each other and the appropriate workflow instance. Some system-provided protocol correlation mechanisms include &lt;a href="http://msdn.microsoft.com/en-us/library/ee358750.aspx"&gt;Request-Reply&lt;/a&gt; correlation and &lt;a href="http://msdn.microsoft.com/en-us/library/ee358724.aspx"&gt;Context-Based&lt;/a&gt; correlation. A Request-Reply correlation is used to correlate a single pair of messaging activities to form a two-way synchronous inbound or outbound operation, such as a &lt;strong&gt;Send&lt;/strong&gt; paired with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receivereply.aspx"&gt;ReceiveReply&lt;/a&gt;, or a &lt;strong&gt;Receive&lt;/strong&gt; paired with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.sendreply.aspx"&gt;SendReply&lt;/a&gt;. The Visual Studio 2010 Workflow Designer also provides a set of activity templates to quickly implement this pattern. A context-based correlation is based on the context exchange mechanism described in the &lt;a href="http://go.microsoft.com/fwlink/?LinkID=166059"&gt;.NET Context Exchange Protocol Specification&lt;/a&gt;. To use context-based correlation, a context-based binding such as &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpcontextbinding.aspx"&gt;BasicHttpContextBinding&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpcontextbinding.aspx"&gt;WSHttpContextBinding&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpcontextbinding.aspx"&gt;NetTcpContextBinding&lt;/a&gt; must be used on the endpoint. &lt;/p&gt;  &lt;p align="justify"&gt;For more information about protocol correlation, see the following topics on MSDN:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee358724.aspx"&gt;Context Exchange Correlation&lt;/a&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee358750.aspx"&gt;Request-Reply Correlation&lt;/a&gt;&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;For more information about using the Visual Studio 2010 Workflow Designer activity templates, see &lt;a href="http://msdn.microsoft.com/en-us/library/ee358739.aspx"&gt;Messaging Activities&lt;/a&gt;. For sample code, see the &lt;a href="http://msdn.microsoft.com/en-us/library/ee662960.aspx"&gt;Durable Duplex&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ee662963.aspx"&gt;NetContextExchangeCorrelation&lt;/a&gt; samples.&lt;/p&gt;  &lt;h1 align="justify"&gt;Content-Based Correlation&lt;/h1&gt;  &lt;p align="justify"&gt;Content-based correlation uses data in the message to associate it to a particular workflow instance. Unlike protocol-based correlation, content-based correlation requires the application developer to explicitly state where this data can be found in each related message. Activities that use content-based correlation specify this message data by using a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.messagequeryset.aspx"&gt;MessageQuerySet&lt;/a&gt;. Content-based correlation is useful when communicating with services that do not use one of the context bindings such as &lt;strong&gt;BasicHttpContextBinding&lt;/strong&gt;. For more information about content-based correlation, see &lt;a href="http://msdn.microsoft.com/en-us/library/ee358755.aspx"&gt;Content Based Correlation&lt;/a&gt;. For sample code, see the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/dd807391.aspx"&gt;Correlated Calculator&lt;/a&gt; samples.&lt;/p&gt;  &lt;p align="justify"&gt;A content-based correlation takes data from the incoming message and maps it to an existing instance. This kind of correlation can be used in the following 2 scenarios:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;when a WCF workflow service has multiple methods that are accessed by a single client and a piece of data in the exchanged messages identifies the desired instance;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;when a WCF workflow service submits a request to a downstream service and asynchronously waits for a response that could potentially arrive after some minutes, hours or days.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;In my demo I used 2 different types of protocol-based correlation, respectively, the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt; to realize an asynchronous message exchange between the client application and the WCF workflow service and the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; to implement an asynchronous communication between the WF workflow service and the underlying BizTalk orchestration. &lt;/p&gt;  &lt;h1&gt;Architecture of the Demo&lt;/h1&gt;  &lt;p align="justify"&gt;The following picture depicts the architecture of the demo. The idea behind the application is quite simple: a Windows Forms application submits a question to a WCF workflow service hosted in IIS\AppFabric and asynchronously waits for the related answer. The &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; WCF workflow service uses the &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the incoming request in a format suitable to be consumed by the underlying BizTalk application. For more information on how using the &lt;strong&gt;Mapper&lt;/strong&gt; activity in a WF workflow to implement message transformation, please refer to the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;second part&lt;/a&gt; of this series. Next, the WCF workflow service sends the request message to BizTalk Server via via a one-way WCF-NetTcp Receive Location. In particular, the client endpoint used by the WCF workflow service to transmit the request to BizTalk is configured to use a custom message inspector called &lt;strong&gt;ReplyToMessageInspector&lt;/strong&gt;. At runtime, this component assigns the URL where the WCF workflow service is asynchronously waiting for the response to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageheaders.replyto.aspx"&gt;ReplyTo&lt;/a&gt; header of the outgoing request message. Once received, the request message is read and processed by a new instance of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; orchestration that returns a response message containing one of 20 standardized answers.&amp;#160; In particular, the orchestration copies the request ID from the request to the response message. This piece of information will be used by the WF runtime to correlate the response message back to the appropriate instance of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; WCF workflow service. Then the orchestration reads the callback URL from the &lt;a href="http://msdn.microsoft.com/en-us/library/bb245991(BTS.70).aspx"&gt;WCF.ReplyToAddress&lt;/a&gt; context property and assigns its value to the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.xlangs.basetypes.address(v=bts.10).aspx"&gt;Address&lt;/a&gt; property of the dynamic send port used to return the response to the appropriate instance of the WCF workflow service. Upon receiving the response message from BizTalk, the WCF workflow service applies another map using the &lt;strong&gt;Mapper&lt;/strong&gt; activity and returns the resulting message to the client application.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/5047.AsyncMagic8BallUseCase_5F00_2C35A6D8.jpg" /&gt;&lt;/p&gt;  &lt;h5 align="justify"&gt;Message Flow&lt;/h5&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div align="justify"&gt;The&amp;#160; &lt;strong&gt;Windows Forms Client Application &lt;/strong&gt;enables a user to specify a question and a delay in seconds. When the user presses the &lt;strong&gt;Ask &lt;/strong&gt;button, a new request message containing the question and the delay is created and sent to a the WCF workflow service. Before sending the first message, the client application creates and opens a service host to expose a callback endpoint that the workflow can invoke to return the response message. In particular, the binding used to expose this callback contract is the &lt;strong&gt;NetTcpBinding&lt;/strong&gt;, whereas the binding used to send the request message to the WCF workflow service is the &lt;strong&gt;NetTcpContextBinding&lt;/strong&gt;. We will expand on this point in the next sections when we’ll analyze the client-side code.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The WCF workflow service receives the request message of type &lt;strong&gt;WFRequest&lt;/strong&gt; using the &lt;strong&gt;Receive&lt;/strong&gt; activity of a &lt;strong&gt;ReceiveAndSendReply&lt;/strong&gt; composed activity. In particular, the &lt;strong&gt;Receive&lt;/strong&gt; activity is used to initialize 2 distinct correlation handles:&lt;/div&gt;      &lt;ul&gt;       &lt;li&gt;         &lt;div align="justify"&gt;The &lt;strong&gt;callbackHandle&lt;/strong&gt; is configured to use the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt; and is used to correlate the incoming request with the response returned to the client application.&lt;/div&gt;       &lt;/li&gt;        &lt;li&gt;         &lt;div align="justify"&gt;The &lt;strong&gt;correlationHandle&lt;/strong&gt; is instead configured to use the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; and is used to correlate the outgoing request with the response returned by BizTalk Server.&lt;/div&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The WCF workflow service uses the &lt;strong&gt;CustomTrackingActivity &lt;/strong&gt;to keep track of individual processing steps and uses an instance of the &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the &lt;strong&gt;WFRequest &lt;/strong&gt;object into an instance of the &lt;strong&gt;BizTalkRequest&lt;/strong&gt; class. See the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;second part&lt;/a&gt; of this series for more information on the &lt;strong&gt;CustomTrackingActivity&amp;#160; &lt;/strong&gt;and &lt;strong&gt;Mapper&lt;/strong&gt; activities.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The WCF workflow service uses a composed &lt;strong&gt;SendAndReceiveReply&lt;/strong&gt; activity to send the &lt;strong&gt;BizTalkRequest&lt;/strong&gt; message to the &lt;strong&gt;WCF-NetTcp&lt;/strong&gt; receive location exposed by the BizTalk application. The &lt;strong&gt;ReplyToMessageInspector &lt;/strong&gt;assigns the URL where the WCF workflow service is asynchronously waiting for the response to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageheaders.replyto.aspx"&gt;ReplyTo&lt;/a&gt; header of the outgoing request message. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;A one-way WCF-NetTcp receive location receives the request message and the &lt;strong&gt;XmlReceive &lt;/strong&gt;pipeline promotes the &lt;strong&gt;MessageType&lt;/strong&gt; context property.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The &lt;strong&gt;Message Agent&lt;/strong&gt; submits the request message to the MessageBox (BizTalkMsgBoxDb).&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;A new instance of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; orchestration receives the request message via a one-way logical port and uses a custom helper component called &lt;strong&gt;XPathHelper&lt;/strong&gt; to read the value of the &lt;strong&gt;Question&lt;/strong&gt; and &lt;strong&gt;Delay&lt;/strong&gt; elements from the inbound message.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; orchestration invokes the &lt;strong&gt;SetResponse&lt;/strong&gt; static method exposed by the &lt;strong&gt;ResponseHelper&lt;/strong&gt; class to build the response message containing the answer to this question contained in the request message. Then it copies the request ID from the request to the response message, reads the callback URL from the &lt;a href="http://msdn.microsoft.com/en-us/library/bb245991(BTS.70).aspx"&gt;WCF.ReplyToAddress&lt;/a&gt; context property and assigns its value to the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.xlangs.basetypes.address(v=bts.10).aspx"&gt;Address&lt;/a&gt; property of the dynamic send port used to return the response to the appropriate instance of the WCF workflow service. The response message is finally published to the MessageBox (BizTalkMsgBoxDb) by the &lt;strong&gt;Message Agent&lt;/strong&gt;. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The response message is retrieved by a one-way Dynamic Send Port. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The &lt;strong&gt;PassThruTransmit&lt;/strong&gt; send pipeline is executed by the Dynamic Send Port.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The response message is returned to the WCF workflow service. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The WCF workflow service uses a &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the &lt;strong&gt;BizTalkResponse&lt;/strong&gt; object into an instance of the &lt;strong&gt;WFRequest&lt;/strong&gt; class.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The WCF workflow service uses a &lt;strong&gt;Send&lt;/strong&gt; activity to send back the response message to the client application. The &lt;strong&gt;Send&lt;/strong&gt; activity is configured to use the callback correlation that contains the URI of the callback endpoint exposed by the client application.&lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;h1&gt;Client Code&lt;/h1&gt;  &lt;p align="justify"&gt;Please refer to the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;second article&lt;/a&gt; of this series for a full explanation of the code used by the client application to invoke the WCF workflow service using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex&lt;/a&gt; communication pattern.&lt;/p&gt;  &lt;h1&gt;The AsyncMagic8Ball WCF Workflow Service&lt;/h1&gt;  &lt;p align="justify"&gt;In this section I will focus my attention on how the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; WCF workflow service exchange messages with both the client application and the BizTalk orchestration. When I created the WCF Workflow Service, the initial workflow just contained a &lt;strong&gt;Sequence&lt;/strong&gt; activity with a &lt;strong&gt;Receive&lt;/strong&gt; activity followed by a &lt;strong&gt;SendReply&lt;/strong&gt; activity as shown in the following illustration.&lt;/p&gt;  &lt;p align="justify"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8132.WCFWorkflowService_5F00_122AEF07.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;I selected the &lt;strong&gt;Sequential&lt;/strong&gt; activity and clicked the &lt;strong&gt;Variables&lt;/strong&gt; button to display the corresponding editor. Next, I created a variable for each message to exchange with the client and BizTalk application and then I created two &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.correlationhandle.aspx"&gt;CorrelationHandle&lt;/a&gt; variables called respectively &lt;strong&gt;callbackHandle&lt;/strong&gt; and &lt;strong&gt;correlationHandle&lt;/strong&gt;.&amp;#160; The first of these two variables is used to implement the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt; with the client application, whereas the second one is configured to use the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; and holds the Id of the incoming request. This information is copied into the request sent to BizTalk and is contained in the corresponding response message. Upon receiving a response from BizTalk Server, the WF runtime uses this correlation handle to identify the appropriate instance of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; WCF workflow service to pass the message to. In order to expose a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpcontextbinding.aspx"&gt;NetTcpContextBinding&lt;/a&gt; endpoint I configured the &lt;strong&gt;Receive&lt;/strong&gt; activity as shown in the following picture:&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6507.ReceiveActivityProperties_5F00_038C54F0.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;In particular, I used the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.servicecontractname.aspx"&gt;ServiceContractName&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.aspx"&gt;Receive&lt;/a&gt; activity to specify the target namespace and the contract interface of the service endpoint and I used the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.action.aspx"&gt;Action&lt;/a&gt; property to specify the action header of the request message. To initialize the callback correlation handle, I selected the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.aspx"&gt;Receive&lt;/a&gt; activity and then I clicked the ellipsis button next to the (Collection) text for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.correlationinitializers.aspx"&gt;CorrelationInitializers&lt;/a&gt; property in the property grid for the &lt;strong&gt;Add Correlation Initializers&lt;/strong&gt; dialog box to appear. As shown in the picture below, I specified &lt;strong&gt;callbackHandle&lt;/strong&gt; as correlation handle and I selected &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.callbackcorrelationinitializer.aspx"&gt;Callback correlation initializer&lt;/a&gt; in as correlation initializer.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7674.InitializeCorrelationHandle_5F00_63BD2F8D.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;Before invoking the downstream BizTalk application, the WCF workflow service immediately returns an &lt;strong&gt;ACK&lt;/strong&gt; message to the caller. Therefore, I configured the &lt;strong&gt;SendReply&lt;/strong&gt; activity, bound to the initial &lt;strong&gt;Receive&lt;/strong&gt; activity, to return a &lt;strong&gt;WFAck&lt;/strong&gt; message, as shown in the picture below.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3480.WFWorkflowFirstPart_5F00_669248A6.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;As you can notice, the workflow uses a &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt; to emit a user-defined event. This pattern is used throughout the workflow. Custom tracking records generated at runtime by the WCF workflow service can be analyzed using the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee677276.aspx"&gt;AppFabric Dashboard&lt;/a&gt;&lt;/strong&gt;. For more information on the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt; and how to use the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee677276.aspx"&gt;AppFabric Dashboard&lt;/a&gt;&lt;/strong&gt; to monitor the runtime behavior of the WCF workflow service, please read the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;previous article&lt;/a&gt; of this series. &lt;/p&gt;  &lt;p align="justify"&gt;There are two options to invoke the WCF-NetTcp receive location exposed by the BizTalk application: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;The first possibility is to generate a custom WCF proxy activity using the&amp;#160; &lt;strong&gt;Add Service Reference&lt;/strong&gt; and use this activity to invoke the underlying WCF receive location in a synchronous way.&lt;strong&gt; &lt;/strong&gt;For more information on this technique, please refer to the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;previous article&lt;/a&gt; of this series. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The second alternative is using the the messaging activities provided out-of-the-box by WF and the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; to implement an asynchronous communication between the WCF workflow service and the underlying orchestration. In this article, we examine this approach.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following picture depicts the central part of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; WCF workflow service.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/3324.AsyncMagic8BallActivitiesToInvokeBizTalk_5F00_4F624FE3.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;In a nutshell, this section of the workflow executes the following actions:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Uses a &lt;strong&gt;SendAndReceiveReply&lt;/strong&gt; activity to send the request message to the one-way WCF-NetTcp receive location exposed by the BizTalk application. &lt;/li&gt;    &lt;li&gt;Tracks a user-defined event using the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;Uses a &lt;strong&gt;Receive&lt;/strong&gt; activity to receive the response back from BizTalk. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following figure shows how I configured the &lt;strong&gt;Send&lt;/strong&gt; activity to transmit the request message to BizTalk.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/2275.AskQuestionToBizTalk_5F00_4615EED5.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;As highlighted above, I used the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.servicecontractname.aspx"&gt;ServiceContractName&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt; property to specify the target namespace and the contract interface utilized by the client endpoint and the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.endpointconfigurationname.aspx"&gt;EndpointConfigurationName&lt;/a&gt; property to define the name of the client endpoint used to transmit the request message to BizTalk. The &lt;strong&gt;bizTalkAsyncNetTcpBinding&lt;/strong&gt; endpoint is defined in the &lt;strong&gt;configuration/system.serviceModel/client&lt;/strong&gt; section of the web.config (the configuration file is shown later in the article). In particular, this endpoint is configured to use a custom message inspector that assigns the callback address of the workflow service to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageheaders.replyto.aspx"&gt;ReplyTo&lt;/a&gt; header of request messages. &lt;/p&gt;  &lt;p align="justify"&gt;Next, I initialized the correlation handle used to implement the content-based correlation. To accomplish this task, I selected the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.aspx"&gt;Send&lt;/a&gt; activity and then I clicked the ellipsis button next to the (Collection) text for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.correlationinitializers.aspx"&gt;CorrelationInitializers&lt;/a&gt; property in the property grid for the &lt;strong&gt;Add Correlation Initializers&lt;/strong&gt; dialog box to appear. On the left panel of the dialog, I specified &lt;strong&gt;correlationHandle&lt;/strong&gt; as correlation handle and then I selected &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.querycorrelationinitializer.aspx"&gt;Query correlation initializer&lt;/a&gt; as correlation initializer. Finally, I specified the correlation key by selecting the Id element from the data contract of the &lt;strong&gt;BizTalkRequest&lt;/strong&gt; message&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/5342.AddCorrelationInitializer_5F00_6F896E6E.jpg"&gt;.&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/8078.CorrelationHandle_5F00_616A7F71.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;To complete the configuration of the content-based correlation, I selected the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.aspx"&gt;Receive&lt;/a&gt; activity and I specified the &lt;strong&gt;correlationHandle &lt;/strong&gt;as value for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.correlateswith.aspx"&gt;CorrelatesWith&lt;/a&gt; property. The latter defines the correlation handle that is used to route the message to the appropriate workflow instance, whereas the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.correlateson.aspx"&gt;CorrelatesOn&lt;/a&gt; property sets the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.messagequeryset.aspx"&gt;MessageQuerySet&lt;/a&gt; used to query the message to extract correlation data.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/6036.ReceiveResponseFromBizTalk_5F00_2D926353.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;To specify the correlation key on the response message, I clicked the ellipsis button next to the (Collection) text for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.correlateson.aspx"&gt;CorrelatesOn&lt;/a&gt; property to open the &lt;strong&gt;Add Correlation Initializers&lt;/strong&gt; dialog box.&amp;#160; Then, as shown in the picture below, I selected the Id property from the data contract of the &lt;strong&gt;BizTalkResponse&lt;/strong&gt; message. &lt;/p&gt;  &lt;p align="justify"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/5228.CorrelatesOn_5F00_5FD5EB38.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;The last part of the WCF workflow invokes the callback endpoint exposed by the client application to return the response to the initial request. In particular, the latter contains the Id of the original request, and this allows the client application to correlate the response to the corresponding request, especially when the client has multiple in-flight requests. For more details on how the client handles the callback, please refer to the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;second part&lt;/a&gt; of this series.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8400.WFLastPart_5F00_7761F123.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;This portion of the workflow performs just 2 steps:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Uses a &lt;strong&gt;Send&lt;/strong&gt; activity&amp;#160; to send the response message back to the caller. This activity is configured to use the callback handle correlation. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Tracks a user-defined event using the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt;. &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following figure shows how I configured the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.aspx"&gt;Send&lt;/a&gt; activity used to transmit the response message back to the caller.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5415.SendActivityProperties_5F00_6084CA3F.jpg" /&gt;&lt;/p&gt;  &lt;p align="justify"&gt;As highlighted above, I assigned to the the &lt;strong&gt;callbackHandle,&lt;/strong&gt; previously initialized, to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.correlateswith.aspx"&gt;CorrelatesWith&lt;/a&gt; property. Then I properly set the other properties like &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.operationname.aspx"&gt;OperationName&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.action.aspx"&gt;Action&lt;/a&gt;, and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.servicecontractname.aspx"&gt;ServiceContractName&lt;/a&gt; to match the characteristics of the callback service endpoint exposed by the client application.&lt;/p&gt;  &lt;h1&gt;The ReplyToMessageInspector component&lt;/h1&gt;  &lt;p align="justify"&gt;In order to transparently add the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageheaders.replyto.aspx"&gt;ReplyTo&lt;/a&gt; header to outgoing request messages, I created a custom message inspector. For your convenience, I include below the code of this component along with the code of endpoint behavior used to register at runtime this extension.&lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;ReplyToBehaviorExtensionElement&amp;#160; Class&lt;/strong&gt;&lt;/p&gt;  &lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="900"&gt;         &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; Using Directives
&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Configuration;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Channels;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Configuration;
&lt;span class="preproc"&gt;#endregion&lt;/span&gt;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.ReplyToHelper
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// This ReplyToBehaviorExtensionElement inherits from BehaviorExtensionElement base class&lt;br /&gt;    /// and allows to register &lt;/span&gt;&lt;span class="rem"&gt;the ReplyToEndpointBehavior in the configuration file.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ReplyToBehaviorExtensionElement : BehaviorExtensionElement
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Constants
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; AddressProperty = &lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; EnabledProperty = &lt;span class="str"&gt;&amp;quot;enabled&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; TraceEnabledProperty = &lt;span class="str"&gt;&amp;quot;traceEnabled&amp;quot;&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Protected Methods
        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; CreateBehavior()
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ReplyToEndpointBehavior(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Enabled,
                                               &lt;span class="kwrd"&gt;this&lt;/span&gt;.TraceEnabled,
                                               &lt;span class="kwrd"&gt;this&lt;/span&gt;.Address);
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Methods
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Type BehaviorType
        {
            get 
            { 
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ReplyToEndpointBehavior); 
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Configuration Properties
        [ConfigurationProperty(EnabledProperty, DefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Enabled
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[EnabledProperty];
            }
            set
            {
                &lt;span class="kwrd"&gt;base&lt;/span&gt;[EnabledProperty] = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [ConfigurationProperty(TraceEnabledProperty, DefaultValue = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; TraceEnabled
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[TraceEnabledProperty];
            }
            set
            {
                &lt;span class="kwrd"&gt;base&lt;/span&gt;[TraceEnabledProperty] = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [ConfigurationProperty(AddressProperty, &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DefaultValue = &lt;span class="str"&gt;&amp;quot;http://www.w3.org/2005/08/addressing/anonymous&amp;quot;&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Address
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[AddressProperty];
            }
            set
            {
                &lt;span class="kwrd"&gt;base&lt;/span&gt;[AddressProperty] = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;ReplyToEndpointBehavior class&lt;/strong&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;p&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; Using Directives
&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Description;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Channels;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Dispatcher;
&lt;span class="preproc"&gt;#endregion&lt;/span&gt;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.ReplyToHelper
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// The ReplyToEndpointBehavior class implements the IEndpointBehavior interface &lt;/span&gt;
    &lt;span class="rem"&gt;/// and adds the ReplyToMessageInspector to the client runtime. &lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ReplyToEndpointBehavior : IEndpointBehavior
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; enabled = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; traceEnabled = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; address = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ReplyToEndpointBehavior(&lt;span class="kwrd"&gt;bool&lt;/span&gt; enabled, 
                                       &lt;span class="kwrd"&gt;bool&lt;/span&gt; traceEnabled, 
                                       &lt;span class="kwrd"&gt;string&lt;/span&gt; address)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.enabled = enabled;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.traceEnabled = traceEnabled;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.address = address;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; IEndpointBehavior Members
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.MessageInspectors.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; ReplyToMessageInspector(enabled, traceEnabled, address));
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;p&gt;        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }&lt;/p&gt;&lt;/pre&gt;
&lt;p&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Validate(ServiceEndpoint endpoint)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/p&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;ReplyToMessageInspector class&lt;/strong&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; Using Directives
&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Channels;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Dispatcher;
&lt;span class="preproc"&gt;#endregion&lt;/span&gt;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.ReplyToHelper
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// The ReplyToMessageInspector adds the ReplyTo header to outgoing messages.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ReplyToMessageInspector : IDispatchMessageInspector, IClientMessageInspector
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Constants
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ReplyToFormat = &lt;span class="str"&gt;&amp;quot;[ReplyToMessageInspector] ReplyTo header set to {0}.&amp;quot;&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; enabled = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; traceEnabled = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; address = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ReplyToMessageInspector(&lt;span class="kwrd"&gt;bool&lt;/span&gt; enabled,
                                       &lt;span class="kwrd"&gt;bool&lt;/span&gt; traceEnabled,
                                       &lt;span class="kwrd"&gt;string&lt;/span&gt; address)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.enabled = enabled;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.traceEnabled = traceEnabled;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.address = address;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; IDispatchMessageInspector Members
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message request, 
                                          IClientChannel channel, 
                                          InstanceContext instanceContext)
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeforeSendReply(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message reply, &lt;span class="kwrd"&gt;object&lt;/span&gt; correlationState)
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; IClientMessageInspector Members
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AfterReceiveReply(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message reply, &lt;span class="kwrd"&gt;object&lt;/span&gt; correlationState)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; BeforeSendRequest(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message request, IClientChannel channel)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (enabled &amp;amp;&amp;amp;
                request != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(address))
            {
                request.Headers.ReplyTo = &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(address);
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (traceEnabled)
                {
                    Trace.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(ReplyToFormat, address));
                    Trace.WriteLine(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;(&lt;span class="str"&gt;'-'&lt;/span&gt;, 100));
                }
            }
            &lt;span class="kwrd"&gt;return&lt;/span&gt; request;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The following table shows an excerpt from the configuration file used by the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt;&amp;#160; service and by the &lt;strong&gt;SyncMagi8cBall&lt;/strong&gt; service introduced in the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;second part&lt;/a&gt; of this article. You can find the original configuration file in the companion code for this article. Note in particular the definition of the &lt;strong&gt;ReplyToBehaviorExtensionElement&lt;/strong&gt; component in the &lt;strong&gt;configuration/system.serviceModel/extensions&lt;/strong&gt; section.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kwrd"&gt;  ...&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;...&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Transport&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;protectionLevel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netTcpContextBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Transport&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;protectionLevel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netTcpContextBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;net.tcp://localhost:7171/Magic8BallBizTalk/Sync&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Magic8Ball&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;bizTalkSyncNetTcpBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;net.tcp://localhost:7172/Magic8BallBizTalk/Async&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;behaviorConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;replyToBehavior&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Magic8Ball&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;bizTalkAsyncNetTcpBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SyncMagic8Ball&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWF&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding_SyncMagic8Ball&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWF&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding_SyncMagic8Ball&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AsyncMagic8Ball&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWF&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding_AsyncMagic8Ball&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWF&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding_AsyncMagic8Ball&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWFCallback&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding_AsyncMagic8BallCallback&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpointBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;&amp;lt;!-- This behavior configuration is adopted by the client endpoint used by the Send Activity &lt;/span&gt;
&lt;span class="rem"&gt;             that transmits the request message to the AsyncMagic8Ball orchestration. --&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;replyToBehavior&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;replyTo&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;net.tcp://localhost/Magic8BallWF/AsyncMagic8Ball.xamlx&amp;quot;&lt;/span&gt; 
                   &lt;span class="attr"&gt;enabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; 
                   &lt;span class="attr"&gt;traceEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;endpointBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;...&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceHostingEnvironment&lt;/span&gt; &lt;span class="attr"&gt;multipleSiteBindingsEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behaviorExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;&amp;lt;!-- It's necessary to register the custom behavior extension element --&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;replyTo&amp;quot;&lt;/span&gt; 
             &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.AppFabric.CAT.Samples.DuplexMEP.ReplyToHelper.ReplyToBehaviorExtensionElement, &lt;br /&gt;                   Microsoft.AppFabric.CAT.Samples.DuplexMEP.ReplyToHelper, &lt;br /&gt;                   Version=1.0.0.0, Culture=neutral, &lt;br /&gt;                   PublicKeyToken=80577993de400321&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behaviorExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;...&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h1&gt;&amp;#160;&lt;/h1&gt;

&lt;h1&gt;The AsyncMagic8Ball Orchestration&lt;/h1&gt;

&lt;p&gt;The following picture shows the structure of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; orchestration. &lt;/p&gt;

&lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/4274.AsyncMagic8BallOrchestration_5F00_47A25B10.jpg" /&gt;&lt;/p&gt;

&lt;p&gt;The orchestration uses a one-way logical port to receive the inbound request message and&amp;#160; dynamic send port to return the corresponding response message. The &lt;strong&gt;Trace Request &lt;/strong&gt;Expression Shape contains the following code to extract the information from the request message. The namespace of the &lt;strong&gt;LogHelper&lt;/strong&gt; and &lt;strong&gt;XPathHelper&lt;/strong&gt; static classes have been eliminated for ease of reading.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;LogHelper.WriteLine(System.String.Format(&lt;span class="str"&gt;&amp;quot;[SyncMagic8Ball] Transport: {0}&amp;quot;&lt;/span&gt;,
                                         RequestMessage(BTS.InboundTransportType)));
id = XPathHelper.GetValue(RequestMessage, 0, &lt;span class="str"&gt;&amp;quot;Id Element XPath Expression&amp;quot;&lt;/span&gt;);
&lt;span class="kwrd"&gt;if&lt;/span&gt; (!System.Int32.TryParse(XPathHelper.GetValue(RequestMessage, 0, &lt;span class="str"&gt;&amp;quot;Delay Element XPath Expression&amp;quot;&lt;/span&gt;),
                           &lt;span class="kwrd"&gt;out&lt;/span&gt; delayInSeconds))
{
    delayInSeconds = 0;
}
LogHelper.WriteLine(System.String.Format(&lt;span class="str"&gt;&amp;quot;[SyncMagic8Ball] Id: {0}&amp;quot;&lt;/span&gt;, id));
LogHelper.WriteLine(System.String.Format(&lt;span class="str"&gt;&amp;quot;[SyncMagic8Ball] Question: {0}&amp;quot;&lt;/span&gt;,
                                         XPathHelper.GetValue(RequestMessage, 
                                                              0, 
                                                              &lt;span class="str"&gt;&amp;quot;Question Element XPath Expression&amp;quot;&lt;/span&gt;)));
LogHelper.WriteLine(System.String.Format(&lt;span class="str"&gt;&amp;quot;[SyncMagic8Ball] Delay: {0}&amp;quot;&lt;/span&gt;, delayInSeconds)); &lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;You can use &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx"&gt;DebugView&lt;/a&gt;, as shown in the picture below, to monitor the trace produced by the orchestration and helper components.&lt;/p&gt;

&lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5187.DebugView_5F00_117E795A.jpg" /&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3302.Quotes_5F00_Icon_5F00_3242470A.gif"&gt;&lt;img title="Quotes_Icon" border="0" alt="Quotes_Icon" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6064.Quotes_5F00_Icon_5F00_thumb_5F00_620CC2FE.gif" width="23" height="15" /&gt;&lt;/a&gt; &lt;strong&gt;Note&amp;#160; &lt;br /&gt;&lt;/strong&gt;My &lt;strong&gt;LogHelper&lt;/strong&gt; class traces messages to the standard output using the capability supplied by the &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx"&gt;Trace&lt;/a&gt; class. This component is primarily intended to be used for debugging a BizTalk application in a test environment, rather than to be used in a production environment. If you are looking for a tracing framework which combines the high performance and flexibility provided by the Event Tracing for Windows (ETW) infrastructure, you can read the following whitepaper by Valery Mizonov: &lt;/p&gt;

        &lt;ul&gt;
          &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=205874"&gt;Instrumentation Best Practices for High Performance BizTalk Solutions&lt;/a&gt;. &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;The value of the &lt;strong&gt;Delay&lt;/strong&gt; Shape is defined as follows:&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;new&lt;/span&gt; System.TimeSpan(0, 0, delayInSeconds); &lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Therefore, the orchestration waits for the time interval in seconds specified in the request message before returning the response message to the caller. Finally, the table below shows the code used to set the response message. As you can see, the code specifies the value for the context properties exposed by the &lt;a href="http://msdn.microsoft.com/en-us/library/bb245991(v=bts.10).aspx"&gt;WCF Adapter&lt;/a&gt;. The penultimate line of code reads the callback URL from the &lt;a href="http://msdn.microsoft.com/en-us/library/bb245991(BTS.70).aspx"&gt;WCF.ReplyToAddress&lt;/a&gt; context property and assigns its value to the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.xlangs.basetypes.address(v=bts.10).aspx"&gt;Address&lt;/a&gt; property of the dynamic send port used to return the response to the appropriate instance of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; workflow service, whereas the last line of code specifies to use the WCF-NetTcp to send the response back to the initial caller.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;ResponseMessage = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
Microsoft.AppFabric.CAT.Samples.DuplexMEP.Helpers.ResponseHelper.SetResponse(ResponseMessage, id);
ResponseMessage(WCF.Action) = &lt;span class="str"&gt;&amp;quot;AskQuestionResponse&amp;quot;&lt;/span&gt;;
ResponseMessage(WCF.SecurityMode) = &lt;span class="str"&gt;&amp;quot;Transport&amp;quot;&lt;/span&gt;;
ResponseMessage(WCF.TransportClientCredentialType) = &lt;span class="str"&gt;&amp;quot;Windows&amp;quot;&lt;/span&gt;;
Magic8BallOutPort(Microsoft.XLANGs.BaseTypes.Address) = RequestMessage(WCF.ReplyToAddress);
Magic8BallOutPort(Microsoft.XLANGs.BaseTypes.TransportType) = &lt;span class="str"&gt;&amp;quot;WCF-NetTcp&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h1&gt;&amp;#160;&lt;/h1&gt;

&lt;h1&gt;Testing the Application&lt;/h1&gt;

&lt;p&gt;To test the application, you can proceed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Makes sure to start the &lt;strong&gt;DuplexMEP&lt;/strong&gt; BizTalk application. &lt;/li&gt;

  &lt;li&gt;Open a new instance of the &lt;strong&gt;Client&lt;/strong&gt; Application, as indicated in the picture below. &lt;/li&gt;

  &lt;li&gt;Enter an existential question like &amp;quot;Why am I here?&amp;quot;, &amp;quot;What's the meaning of like?&amp;quot; or &amp;quot;Will the world end in 2012?&amp;quot; in the &lt;strong&gt;Question&lt;/strong&gt; textbox. &lt;/li&gt;

  &lt;li&gt;Select one of &lt;strong&gt;NetTcpEndpointAsyncWF &lt;/strong&gt;in the &lt;strong&gt;Endpoint&lt;/strong&gt; drop down list. &lt;/li&gt;

  &lt;li&gt;Specify a &lt;strong&gt;Delay&lt;/strong&gt; in seconds in the corresponding textbox. &lt;/li&gt;

  &lt;li&gt;Press the &lt;strong&gt;Ask&lt;/strong&gt; button. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/2553.NetTcpEndpointAsyncWFClient_5F00_14264C1A.jpg" /&gt;&lt;/p&gt;

&lt;p align="justify"&gt;Now, if you press the &lt;strong&gt;Ask&lt;/strong&gt; button multiple times in a row, you can easily notice that the client application is called back by the WCF workflow service in an asynchronous way, that in turn invokes the underlying &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; orchestration in an asynchronous manner. Therefore, the client application doesn't need to wait for the response to a previous question before posing a new request.&lt;/p&gt;

&lt;p align="justify"&gt;Make some calls and then open the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677236.aspx"&gt;AppFabric Dashboard&lt;/a&gt;. This page is composed of three detailed metrics sections: three detailed metrics sections: &lt;strong&gt;Persisted WF Instances&lt;/strong&gt;, &lt;strong&gt;WCF Call History&lt;/strong&gt;, and &lt;strong&gt;WF Instance History&lt;/strong&gt;. These sections display monitoring and tracking metrics for instances of .NET Framework 4 WCF and WF services. Let’s focus our attention on the &lt;strong&gt;WF Instance History&lt;/strong&gt; section, highlighted in red in the figure below. The latter displays historical statistics derived from tracked workflow instance events stored in one or more monitoring databases. It can draw data from several monitoring databases, if the server or farm uses more than one monitoring database for services deployed at the selected scope.&lt;/p&gt;

&lt;p align="center"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/0743.AsyncMagic8BallAppFabricDashboard_5F00_7BE29624.jpg" width="860" height="510" /&gt;&lt;/p&gt;

&lt;p&gt;If you click the &lt;strong&gt;Completions&lt;/strong&gt; link you can review the instances of the &lt;strong&gt;AsyncMagic8Ball&lt;/strong&gt; service that completed in the selected period of time. You can use the &lt;strong&gt;Query&lt;/strong&gt; control on the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677287(v=MSDN.10).aspx"&gt;Tracked WF Instances Page&lt;/a&gt; to run a simple query and restrict the number of rows displayed in the grid below.&lt;/p&gt;

&lt;p align="center"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/2043.AsyncMagic8BallTrackedWFInstances_5F00_19349B97.jpg" width="860" height="510" /&gt;&lt;/p&gt;

&lt;p align="justify"&gt;Finally, you can right-click one of the completed WF instances and select &lt;strong&gt;View Tracked Events&lt;/strong&gt; to access the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677338(v=MSDN.10).aspx"&gt;Tracked Events Page&lt;/a&gt; where you can examine events generated by WCF and WF services. On this page you can group events by &lt;strong&gt;Event Type&lt;/strong&gt;, as shown in the figure below, and analyze the user-defined events emitted by the current WCF instance using the &lt;strong&gt;CustomTrackingActivity &lt;/strong&gt;that we saw at the beginning of this article.&lt;/p&gt;

&lt;p align="center"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-08-22-metablogapi/3806.AsyncMagic8BallTrackedWFEvents_5F00_28D3E501.jpg" width="860" height="583" /&gt;&lt;/p&gt;

&lt;p&gt;In particular, you can quickly investigate the details of a selected event in the &lt;strong&gt;Details&lt;/strong&gt; pane, as highlighted in red in the figure above. &lt;/p&gt;

&lt;h1&gt;Conclusions&lt;/h1&gt;

&lt;p align="justify"&gt;In the final article of this 3-posts series we have seen how to implement an asynchronous communication between a &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx"&gt;WCF Workflow Service&lt;/a&gt; and an Orchestration using WS-Addressing and &lt;a href="http://msdn.microsoft.com/en-us/library/ee358755.aspx"&gt;Content-Based Correlation&lt;/a&gt; that represent probably the safest and most reliable way to correlate across truly disparate and disconnected applications in an asynchronous manner. As we have observed in the introduction of the present article, the use of asynchronous communication patterns can dramatically improve the scalability and performance of a distributed application platform where multiple systems exchange messages using WCF. In the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/11/23/how-using-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-1.aspx"&gt;first part&lt;/a&gt; of this series we have examined how to implement an asynchronous message exchange between a .NET application and an orchestration via a two-way WCF receive location using the &lt;a href="http://msdn.microsoft.com/en-us/library/ms731184.aspx"&gt;Duplex Message Exchange Pattern&lt;/a&gt;, whereas in the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx"&gt;second part&lt;/a&gt; we have seen how to realize an asynchronous communication between a client application and a &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx"&gt;WCF Workflow Service&lt;/a&gt; running within IIS&lt;a href="http://msdn.microsoft.com/en-us/rampup/gg296345.aspx"&gt;\AppFabric Hosting Services&lt;/a&gt; using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt;. In the second article we have also seen how to create a custom activity to emit user-defined events, how to use the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677236.aspx"&gt;AppFabric Dashboard&lt;/a&gt; to monitor custom tracking events generated by WF services, and finally how to exploit the &lt;strong&gt;Mapper&lt;/strong&gt; activity provided by &lt;a href="http://www.microsoft.com/biztalk/en/us/appfabricconnect.aspx"&gt;AppFabric Connect&lt;/a&gt; to implement message transformations in a WCF workflow service. I hope this article can provide you with useful ideas on how to improve the scalability and flexibility of your AppFabric/BizTalk applications. &lt;a href="http://cid-09dba4a06b360a65.office.live.com/self.aspx/Pubblica/DuplexMEP.zip"&gt;Here&lt;/a&gt; you can download the companion code for this article. As always, you feedbacks are more than welcome!&lt;/p&gt;































&lt;p&gt;Reviewed by &lt;a href="http://blogs.msdn.com/members/Christian.Martinez/"&gt;Christian Martinez&lt;/a&gt;. Thanks mate!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10118711" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/BizTalk/">BizTalk</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Best+Practices/">Best Practices</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/-NET4/">.NET4</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Correlation/">Correlation</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Mapper/">Mapper</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric+Connect/">AppFabric Connect</category></item><item><title>Running .NET4 Windows Workflows in Azure</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/12/running-net4-windows-workflows-in-azure-today.aspx</link><pubDate>Wed, 12 Jan 2011 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111324</guid><dc:creator>SurenM</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10111324</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10111324</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/12/running-net4-windows-workflows-in-azure-today.aspx#comments</comments><description>&lt;p&gt;This blog reviews the current (January 2011) set of optio&lt;a name="_GoBack"&gt;&lt;/a&gt;ns available for hosting existing .NET4 Workflow (WF) programs in &lt;a href="http://www.microsoft.com/windowsazure/windowsazure/"&gt;Windows Azure&lt;/a&gt; and also provides a roadmap to the upcoming features that will further enhance support for hosting and monitoring the Workflow programs. The code snippets included below are also available as an attachment for you to download and try it out yourself.&amp;nbsp; &lt;/p&gt;
&lt;h1&gt;&amp;nbsp;&lt;/h1&gt;
&lt;h1&gt;Workflow in Azure &amp;ndash; Today&lt;/h1&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/netframework/aa663328.aspx"&gt;Workflow programs&lt;/a&gt; can broadly classified as durable or non-durable (aka non-persisted Workflow Instances). &lt;a href="http://msdn.microsoft.com/en-us/library/bb412197.aspx"&gt;Durable Workflow Services&lt;/a&gt; are inherently long running, persist their state, and use correlation for follow-on activities. &lt;a href="http://msdn.microsoft.com/en-us/library/ff729669.aspx"&gt;Non-durable Workflows&lt;/a&gt; are stateless, effectively they start and run to completion in a single burst. &lt;/p&gt;
&lt;p&gt;Today non-durable Workflows are readily supported by Windows Azure of course with a few configuration/trivial changes. Hosting durable Workflows today is a challenge; since we do not yet have a &amp;lsquo;&lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849.aspx"&gt;Windows Server AppFabric&lt;/a&gt;&amp;rsquo; equivalent for Azure which can persist, manage and monitor the Service. In brief the big buckets of functionality required to host the durable Workflow Services are: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Monitoring store: &lt;/b&gt;There is no Event Collection Service available to gather the &lt;a href="http://msdn.microsoft.com/en-us/library/ms751538.aspx"&gt;ETW&lt;/a&gt; events and write them to the &lt;a href="http://www.microsoft.com/en-us/sqlazure/default.aspx"&gt;SQL Azure&lt;/a&gt; based Monitoring database. There is also no schema that ships with &lt;a href="http://www.microsoft.com/net/"&gt;.NET Framework&lt;/a&gt; for creating the monitoring database, and the one that ships with Windows Server AppFabric is incompatible with SQL Azure &amp;ndash; an example, the scripts that are provided with Windows Server AppFabric make use of the &lt;a href="http://msdn.microsoft.com/en-us/library/ee336233.aspx"&gt;XML column type&lt;/a&gt; which is currently not supported by SQL Azure. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;Instance Store: &lt;/b&gt;The schemas used by the SqlWorkflowInstanceStore have incompatibilities with SQL Azure. Specifically, the schema scripts require page locks, which are not supported on SQL Azure. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;Reliability: &lt;/b&gt;While the SqlWorkflowInstanceStore provides a lot of the functionality for managing instance lifetimes, the lack of the AppFabric Workflow Management Service means that you need to manually implement a way to start your WorkflowServiceHosts before any messages are received (such as when you bring up a new role instance or restart a role instance), so that the contained SqlWorkflowInstanceStore can poll for workflow service instances having expired timers and subsequently resume their execution. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The above limitations make it rather difficult to run a durable Workflow Service on Azure &amp;ndash; the upcoming release of &lt;a href="http://www.microsoft.com/en-us/appfabric/azure/product.aspx"&gt;Azure AppFabric (Composite Application)&lt;/a&gt; is expected to make it possible to run durable Workflow Services. In this blog, we will focus on the design approaches to get your non-durable Workflow instances running within Azure roles.&lt;/p&gt;
&lt;p&gt;Today you can run your non-durable Workflow on Azure. What this means, is that your Workflow programs really cannot persist their state and wait for subsequent input to resume execution- they must complete following their initial launch. With Azure you can run non-durable Workflows programs in one of the three ways: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Web Role &lt;/li&gt;
&lt;li&gt;Worker Roles &lt;/li&gt;
&lt;li&gt;Hybrid &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The Web Role acts very much like IIS does on premise as an HTTP server, and is easier to configure and requires little code to integrate and is activated by an incoming request. The Worker Role acts like an on-premise Windows Service and is typically used in backend processing scenarios have multiple options to kick off the processing &amp;ndash; which in turn add to the complexity.&amp;nbsp; The hybrid approach, which bridges communication between Azure hosted and on-premise resources, has multiple advantages: it enables you to leverage existing deployment models and also enables use of durable Workflows on premise as a solution until the next release.&amp;nbsp; The following sections, succinctly, provide details on these three approaches and in the &amp;lsquo;Conclusion&amp;rsquo; section we will also provide you pointers on the appropriateness of each approach.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Host Workflow Services in a Web Role&lt;/h2&gt;
&lt;p&gt;The Web Role is similar to a &amp;lsquo;Web Application&amp;rsquo; and can also provide a Service perspective to anything that uses the http protocol - such as a WCF service using basicHttpBinding. The Web Role is generally driven by a user interface &amp;ndash; the user interacts with a Web Page, but a call to a hosted Service can also cause some processing to happen. Below are the steps that enable you to host a Workflow Service in a Web Role. &lt;/p&gt;
&lt;p&gt;First step is to create a Cloud Project in Visual Studio, and add a WCF Service Web Role to it. Delete the IService1.cs, Service1.svc and Service1.svc.cs added by the template since they are not needed and will be replaced by the workflow service XAMLX. &lt;/p&gt;
&lt;p&gt;To the Web Role project, add a WCF Workflow Service. The structure of your solution is now complete (see the screenshot below for an example), but you need to add a few configuration elements to enable it to run on Azure. &lt;/p&gt;
&lt;p&gt;&lt;img height="237" width="253" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2068.Fig_2D00_1_5F00_4B63C4D6.png" alt="Fig 1" border="0" title="Fig 1" style="background-image: none; border-right-width: 0px; margin: ; 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;/p&gt;
&lt;p&gt;Windows Azure does not include a section handler in its machine.config for system.xaml.hosting as you have in an on-premises solution. Therefore, the first configuration change (HTTP Handler for XAMLX and XAMLX Activation) is to add the following to the top of your web.config, within the configuration element:&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 style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&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 style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;sectionGroup&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="system.xaml.hosting"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.Xaml.Hosting.Configuration.XamlHostingSectionGroup, System.Xaml.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&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 style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;section&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="httpHandlers"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.Xaml.Hosting.Configuration.XamlHostingSection, System.Xaml.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&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 style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;sectionGroup&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 style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next, you need to add XAML http handlers for WorkflowService and Activities root element types by adding the following within the configuration element of your web.config, below the configSection that we included above:&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 style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;system.xaml.hosting&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 style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;httpHandlers&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 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;xamlRootElementType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.ServiceModel.Activities.WorkflowService, System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;httpHandlerType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.ServiceModel.Activities.Activation.ServiceModelActivitiesActivationHandlerAsync, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&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 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;xamlRootElementType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.Activities.Activity, System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;httpHandlerType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.ServiceModel.Activities.Activation.ServiceModelActivitiesActivationHandlerAsync, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&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 style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;httpHandlers&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 style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;system.xaml.hosting&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Finally, configure the WorkflowServiceHostFactory to handle activation for your service by adding a serviceActivation element to system.serviceModel\serviceHostingEnvironment element:&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 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;="true"&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 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 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;="~/Service1.xamlx"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Service1.xamlx"&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;factory&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory"&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 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 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;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The last step is to deploy your Cloud Project and with that you now have your Workflow service hosted on Azure &amp;ndash; graphic below! &lt;/p&gt;
&lt;p&gt;&lt;img height="377" width="590" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5148.Fig_2D00_3_5F00_254DC8E6.png" alt="Fig 3" border="0" title="Fig 3" style="background-image: none; border-right-width: 0px; margin: ; 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;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: &lt;em&gt;Sam Vanhoutte from CODit in his blog also elaborates on &lt;/em&gt;&lt;a href="http://www.biztalkgurus.com/blogs/biztalksyn/archive/2010/06/17/hosting-workflow-services-in-windows-azure.aspx"&gt;&lt;em&gt;Hosting workflow services in Windows Azure&lt;/em&gt;&lt;/a&gt;&lt;em&gt; and focuses on troubleshooting configuration by disabling custom errors-- do review. &lt;/em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Host Workflows in a Worker Role &lt;/h2&gt;
&lt;p&gt;The Worker Role is similar to a Windows Service and would start up &amp;lsquo;automatically&amp;rsquo; and be running all the time. While the Workflow Programs could be initiated by a timer, it could use other means to activate such as a simple while (true) loop and a sleep statement. When it &amp;lsquo;ticks&amp;rsquo; it performs work. This is generally the option for background or computational processing.&lt;/p&gt;
&lt;p&gt;In this scenario you use Workflows to define Worker Role logic.&amp;nbsp; Worker Roles are created by deriving from the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.aspx"&gt;RoleEntryPoint Class&lt;/a&gt; and overriding a few of its method. The method that defines the actual logic performed by a Worker Role is the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.run.aspx"&gt;Run Method&lt;/a&gt;. Therefore, to get your workflows executing within a Worker Role, use WorkflowApplication* or WorkflowInvoker to host an instance of your non-service Workflow (e.g., it doesn&amp;rsquo;t use Receive activities) within this Method. In either case, you only exit the Run Method when you want the Worker Role to stop executing Workflows. &lt;/p&gt;
&lt;p&gt;The general strategy to accomplish this is to start with an Azure Project and add a Worker Role to it. To this project you &lt;i&gt;Add &lt;/i&gt;a reference to an assembly containing your XAML Workflow types. Within the Run Method of WorkerRole.cs, you initialize one of the host types (WorkflowApplication or WorkflowInvoker), referring to an Activity type contained in the referenced assembly. Alternatively, you can initialize one of the host types by loading an Activity instance from the XAML Workflow file available on the file system.. You will also need to add references to .NET Framework assemblies (System.Activities and System.Xaml - if you wish to load XAML workflows from a file).&lt;/p&gt;
&lt;h3&gt;Host Workflow (Non-Service) in a Worker Role &lt;/h3&gt;
&lt;p&gt;For &amp;lsquo;non-Service&amp;rsquo; Workflows, your Run method needs to describe a loop that examines some input data and passes it to a workflow instance for processing. The following shows how to accomplish this when the Workflow type is acquired from a referenced assembly: &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;public override void Run()&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;/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;    Trace.WriteLine(&lt;span style="color: #006080"&gt;"WFWorker entry point called"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"Information"&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    while (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;/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;/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;        Thread.Sleep(1000)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&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;         * ...Poll &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; data &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; hand &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; WF instance...&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;/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;/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;&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;        //Create a dictionary &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; hold input data&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;        Dictionary&amp;lt;&lt;span style="color: #008000"&gt;;string, object&amp;gt; inputData = new Dictionary&amp;lt;string,object&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;&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;        //Instantiate a workflow instance from a type defined &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; a referenced assembly&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;        System.Activities.Activity workflow = new Workflow1()&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        //Execute the WF passing in parameter data and capture output results&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;        IDictionary&amp;lt;&lt;span style="color: #008000"&gt;;string, object&amp;gt; outputData =  &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;        System.Activities.WorkflowInvoker.Invoke(workflow, inputData)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        Trace.WriteLine("Working", "Information");&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;/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;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively, you could perform the above using the WorkflowApplication to host the Workflow instance. In this case, the main difference is that you need to use semaphores to control the flow of execution because the workflow instances will be run on threads separate from the one executing the Run method. &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;public override void Run()&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;/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;    Trace.WriteLine(&lt;span style="color: #006080"&gt;"WFWorker entry point called"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"Information"&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    while (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;/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;/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;        Thread.Sleep(1000)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&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;            * ...Poll &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; data &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; hand &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; WF...&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;/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;/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;&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;        AutoResetEvent syncEvent = new AutoResetEvent(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        //Create a dictionary to hold input data and declare another for output data&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;        Dictionary&amp;lt;&lt;span style="color: #008000"&gt;;string, object&amp;gt; inputData = new Dictionary&amp;lt;string,object&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;        IDictionary&amp;lt;&lt;span style="color: #008000"&gt;;string, object&amp;gt; outputData;&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;&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;        //Instantiate a workflow instance from a type defined &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; a referenced assembly&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;        System.Activities.Activity workflow = new Workflow1()&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        //Run the workflow instance using WorkflowApplication as the host.&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;        System.Activities.WorkflowApplication workflowHost = new System.Activities.WorkflowApplication(workflow, inputData)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        workflowHost.Completed = (e) =&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;/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;                outputData = e.Outputs&lt;span style="color: #008000"&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 style="color: #008000"&gt;                syncEvent.Set();&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 style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        workflowHost.Run();&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;&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;        syncEvent.WaitOne()&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        Trace.WriteLine("Working", "Information");&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;/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;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Finally, if instead of loading Workflow types from a referenced assembly, you want to load the XAML from a file available, for example, one included with WorkerRole or stored on an Azure Drive, you would simply replace the line that instantiates the Workflow in the above two examples with the following, passing in the appropriate path to the XAML file to XamlServices.Load:&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;System.Activities.Activity workflow = (System.Activities.Activity) &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;            System.Xaml.XamlServices.Load(@&lt;span style="color: #006080"&gt;"X:\workflows\Workflow1.xaml"&lt;/span&gt;)&lt;span style="color: #008000"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;By and large, if you are simply hosting logic described in a non-durable workflow, WorkflowInvoker is the way to go. As it offers fewer lifecycle features (when compared to WorkflowApplication), it is also more light weight and may help you scale better when you need to run many workflows simultaneously.&lt;/p&gt;
&lt;h3&gt;Host Workflow Service in a Worker Role &lt;/h3&gt;
&lt;p&gt;When you need to host Workflow Service in a Worker Role, there are a few more steps to take. Mainly, these exist to address the fact that Worker Role instances run behind a load balancer. From a high-level, to host a Workflow Service means creating an instance of a WorkflowServiceHost based upon an instance of an Activity or WorkflowService defined either in a separate assembly or as a XAML file. The WorkflowService instance is created and opened in the Worker Role&amp;rsquo;s &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.onstart.aspx"&gt;OnStart Method&lt;/a&gt;, and closed in the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx"&gt;OnStop Method&lt;/a&gt;. It is important to note that you should always create the WorkflowServiceHost instance within the OnStart Method (as opposed to within Run as was shown for non-service Workflow hosts). This ensures that if a startup error occurs, the Worker Role instance will be restarted by Azure automatically. This also means the opening of the WorkflowServiceHost will be attempted again. &lt;/p&gt;
&lt;p&gt;Begin by defining a global variable to hold a reference to the WorkflowServiceHost (so that you can access the instance within both the OnStart and OnStop Methods).&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;public class WorkerRole : RoleEntryPoint&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;/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;    System.ServiceModel.Activities.WorkflowServiceHost wfServiceHostA&lt;span style="color: #008000"&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 style="color: #008000"&gt;    &amp;hellip;&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;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next, within the OnStart Method, add code to initialize and open the WorkflowServiceHost, within a try block. For example:&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;public override bool OnStart()&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;/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;    Trace.WriteLine(&lt;span style="color: #006080"&gt;"Worker Role OnStart Called."&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    //&amp;hellip;&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;&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;    try&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;/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;        OpenWorkflowServiceHostWithAddressFilterMode()&lt;span style="color: #008000"&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 style="color: #008000"&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;    catch (Exception ex)&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;/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;        Trace.TraceError(ex.Message)&lt;span style="color: #008000"&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 style="color: #008000"&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;/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;&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;    //&amp;hellip;&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;&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 style="color: #0000ff"&gt;return&lt;/span&gt; base.OnStart()&lt;span style="color: #008000"&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 style="color: #008000"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s take a look at the OpenWorkflowServiceHostWithAddressFilterMode method implementation, which really does the work. Starting from the top, notice how either an Activity or WorkflowService instance can be used by the WorkflowServiceHost constructor, they can even be loaded from a XAMLX file on the file-system. Then we acquire the internal instance endpoint and use it to define both the logical and physical address for adding an application service endpoint using a NetTcpBinding. When calling AddServiceEndpoint on a WorkflowServiceHost, you can specify either just the service name as a string or the namespace plus name as an XName (these values come from the Receive activity&amp;rsquo;s ServiceContractName property). &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;private void OpenWorkflowServiceHostWithAddressFilterMode()&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;/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;    //workflow service hosting &lt;span style="color: #0000ff"&gt;with&lt;/span&gt; AddressFilterMode approach&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;&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;    //Loading from a XAMLX on the file system&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;    System.ServiceModel.Activities.WorkflowService wfs =&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;        (System.ServiceModel.Activities.WorkflowService)System.Xaml.XamlServices.Load(&lt;span style="color: #006080"&gt;"WorkflowService1.xamlx"&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    //As an alternative you can load from an Activity type in a referenced assembly:&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;    //System.Activities.Activity wfs = new WorkflowService1()&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    wfServiceHostA = new System.ServiceModel.Activities.WorkflowServiceHost(wfs);&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;&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;    IPEndPoint ip =         RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[&lt;span style="color: #006080"&gt;"WorkflowServiceTcp"&lt;/span&gt;].IPEndpoint&lt;span style="color: #008000"&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 style="color: #008000"&gt;    wfServiceHostA.AddServiceEndpoint(System.Xml.Linq.XName.Get("IService", "http://tempuri.org/"),&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;        new NetTcpBinding(SecurityMode.None),&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;        String.Format(&lt;span style="color: #006080"&gt;"net.tcp://{0}/MyWfServiceA"&lt;/span&gt;, ip))&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    //You can also refer to the implemented contract without the namespace, just passing the name as a string:&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;    //wfServiceHostA.AddServiceEndpoint(&lt;span style="color: #006080"&gt;"IService"&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;    //    new NetTcpBinding(SecurityMode.None),&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;    //    String.Format(&lt;span style="color: #006080"&gt;"net.tcp://{0}/MyWfServiceA"&lt;/span&gt;, ip))&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    wfServiceHostA.ApplyServiceMetadataBehavior(String.Format("net.tcp://{0}/MyWfServiceA/mex", ip));&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;&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;    wfServiceHostA.ApplyServiceBehaviorAttribute()&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    wfServiceHostA.Open();&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;&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;    Trace.WriteLine(String.Format(&lt;span style="color: #006080"&gt;"Opened wfServiceHostA"&lt;/span&gt;))&lt;span style="color: #008000"&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 style="color: #008000"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In order to enable our service to be callable externally, we next need to add an Input Endpoint that Azure will expose at the load balancer for remote clients to use. This is done within the Worker Role configuration, on the Endpoints tab. The figure below shows how we have defined a single TCP Input Endpoint on port 5555 named WorkflowServiceTcp. It is this Input Endpoint, or IPEndpoint as it appears in code, that we use in the call to AddServiceEndpoint in the previous code snippet. At runtime, the variable &lt;i&gt;ip&lt;/i&gt; provides the local instance physical address and port which the service must use, to which the load balancer will forward messages. The port number assigned at runtime (e.g., 20000) is almost always different from the port you specify in the Endpoints tab (e.g., 5555), and the address (e.g., 10.26.58.148) is not the address of your application in Azure (e.g., &lt;em&gt;myapp.cloudapp.net&lt;/em&gt;), but rather the particular Worker Role instance. &lt;/p&gt;
&lt;p&gt;&lt;img height="176" width="590" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2664.image_5F00_40708F3F.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; margin: ; 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;/p&gt;
&lt;p&gt;It is very important to know that currently, Azure Worker Roles do not support using HTTP or HTTPS endpoints (primarily due to permissions issues that only Worker Roles face when trying to open one). Therefore, when exposing your service or metadata to external clients, your only option is to use TCP. &lt;/p&gt;
&lt;p&gt;Returning to the implementation, before opening the service we add a few behaviors. The key concept to understand is that any workflow service hosted by an Azure Worker Role will run behind a load balancer, and this affects how requests must be addressed. This results in two challenges which the code above solves:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to properly expose service metadata and produce metadata which includes the load balancer&amp;rsquo;s address (and not the internal address of the service hosted within a Worker Role instance). &lt;/li&gt;
&lt;li&gt;How to configure the service to accept messages it receives from the load balancer, that are addressed to the load balancer. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To reduce repetitive work, we defined a helper class that contains extension methods for ApplyServiceBehaviorAttribute and ApplyServiceMetadataBehavior that apply the appropriate configuration to the WorkflowServiceHost and alleviate the aforementioned challenges.&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;//Defines extensions methods &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; ServiceHostBase (useable by ServiceHost &amp;amp;&lt;span style="color: #008000"&gt;; WorkflowServiceHost)&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;public static class ServiceHostingHelper&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;/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;    public static void ApplyServiceBehaviorAttribute(this ServiceHostBase host)&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;/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;        ServiceBehaviorAttribute sba = host.Description.Behaviors.Find&amp;lt;&lt;span style="color: #008000"&gt;;ServiceBehaviorAttribute&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 style="color: #0000ff"&gt;if&lt;/span&gt; (sba == null)&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;/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 style="color: #0000ff"&gt;For&lt;/span&gt; WorkflowServices, this behavior is not added by &lt;span style="color: #0000ff"&gt;default&lt;/span&gt; (unlike &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; traditional WCF services).&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;            host.Description.Behaviors.Add(new ServiceBehaviorAttribute() { AddressFilterMode = AddressFilterMode.Any })&lt;span style="color: #008000"&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 style="color: #008000"&gt;            Trace.WriteLine(String.Format("Added address filter mode ANY."));&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;/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 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;/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;            sba.AddressFilterMode = System.ServiceModel.AddressFilterMode.Any&lt;span style="color: #008000"&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 style="color: #008000"&gt;            Trace.WriteLine(String.Format("Configured address filter mode to ANY."));&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;/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;/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;&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;    public static void ApplyServiceMetadataBehavior(this ServiceHostBase host, string metadataUri)&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;/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;        //Must add this &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; expose metadata externally&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;        UseRequestHeadersForMetadataAddressBehavior addressBehaviorFix = new UseRequestHeadersForMetadataAddressBehavior()&lt;span style="color: #008000"&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 style="color: #008000"&gt;        host.Description.Behaviors.Add(addressBehaviorFix);&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;&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;        Trace.WriteLine(String.Format(&lt;span style="color: #006080"&gt;"Added Address Behavior Fix"&lt;/span&gt;))&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;        //Add TCP metadata endpoint. NOTE, as for application endpoints, HTTP endpoints are not supported in Worker Roles.&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;        ServiceMetadataBehavior smb = host.Description.Behaviors.Find&amp;lt;&lt;span style="color: #008000"&gt;;ServiceMetadataBehavior&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 style="color: #0000ff"&gt;if&lt;/span&gt; (smb == null)&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;/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;            smb = new ServiceMetadataBehavior()&lt;span style="color: #008000"&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 style="color: #008000"&gt;            host.Description.Behaviors.Add(smb);&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;            Trace.WriteLine(&lt;span style="color: #006080"&gt;"Added ServiceMetaDataBehavior."&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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;&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;        host.AddServiceEndpoint(&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;            ServiceMetadataBehavior.MexContractName,&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;            MetadataExchangeBindings.CreateMexTcpBinding(),&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;            metadataUri&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 style="color: #008000"&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 style="color: #008000"&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;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Looking at how we enable service metadata in the ApplyServiceMetadataBehavior method, notice there are three key steps. First, we add the UseRequestHeadersForMetadataAddressBehavior. Without this behavior, you could only get metadata by communicating directly to the Worker Role instance, which is not possible for external clients (they must always communicate through the load balancer). Moreover, the WSDL returned in the metadata request would include the internal address of the service, which is not helpful to external clients either. By adding this behavior, the WSDL includes the address of the load balancer. Next, we add the ServiceMetadataBehavior and then add a service endpoint at which the metadata can be requested. Observe that when we call ApplyServiceMetadataBehavior, we specify a URI which is the service&amp;rsquo;s &lt;span style="text-decoration: underline;"&gt;internal&lt;/span&gt; address with mex appended. The load balancer will now correctly route metadata requests to this metadata endpoint. &lt;/p&gt;
&lt;p&gt;The rationale behind the ApplyServiceBehaviorAttribute method is similar to ApplyServiceMetadataBehavior. When we add a service endpoint by specifying only the address parameter (as we did above), the logical and physical address of the service are configured to be the same. This causes a problem when operating behind a load balancer, as messages coming from external clients via the load balancer will be addressed to the logical address of the load balancer, and when the instance receives such a message it will not accept&amp;mdash;throwing an AddressFilterMismatch exception. This happens because the address in the message does not match the logical address at which the endpoint was configured. With traditional code-based WCF services, we could resolve this simply by decorating the service implementation class with [ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)], which allows the incoming message to have any address and port. This is not possible with Workflow Services (as there is no code to decorate with an attribute), hence we have to add it in the hosting code.&lt;/p&gt;
&lt;p&gt;If allowing an incoming address concerns you, an alternative to using AddressFilterMode is simply to specify the logical address that is to be allowed. Instead of adding the ServiceBehaviorAttribute, you simply open the service endpoint specifying both the logical (namely the port the load balancer will receives messages on) and physical address (at which your service listens). The only complication, is that your Workflow Role instance does not know which port the load balancer is listening- so you need to add this value to configuration and read it from their before adding the service endpoint. To add this to configuration, return to the Worker Role&amp;rsquo;s properties, Settings tab. Add string setting with the value of the of the port you specified on the Endpoints tab, as we show here for the WorkflowServiceEndpointListenerPort. &lt;/p&gt;
&lt;p&gt;&lt;img height="156" width="590" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0511.image_5F00_2DF818BD.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; margin: ; 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;/p&gt;
&lt;p&gt;With that setting in place, the rest of the implementation is fairly straightforward:&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;private void OpenWorkflowServiceHostWithoutAddressFilterMode()&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;/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;    //workflow service hosting without AddressFilterMode&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;&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;    //Loading from a XAMLX on the file system&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;    System.ServiceModel.Activities.WorkflowService wfs =        (System.ServiceModel.Activities.WorkflowService)System.Xaml.XamlServices.Load(&lt;span style="color: #006080"&gt;"WorkflowService1.xamlx"&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    wfServiceHostB = new System.ServiceModel.Activities.WorkflowServiceHost(wfs);&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;&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;    //Pull the expected load balancer port from configuration...&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;    int externalPort = int.Parse(RoleEnvironment.GetConfigurationSettingValue(&lt;span style="color: #006080"&gt;"WorkflowServiceEndpointListenerPort"&lt;/span&gt;))&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    IPEndPoint ip = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WorkflowServiceTcp"].IPEndpoint;&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;&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;    //Use the external load balancer port &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; the logical address...&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;    wfServiceHostB.AddServiceEndpoint(System.Xml.Linq.XName.Get(&lt;span style="color: #006080"&gt;"IService"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"http://tempuri.org/"&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;        new NetTcpBinding(SecurityMode.None),&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;        String.Format(&lt;span style="color: #006080"&gt;"net.tcp://{0}:{1}/MyWfServiceB"&lt;/span&gt;, ip.Address, externalPort),&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;        new Uri(String.Format(&lt;span style="color: #006080"&gt;"net.tcp://{0}/MyWfServiceB"&lt;/span&gt;, ip)))&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    wfServiceHostB.ApplyServiceMetadataBehavior(String.Format("net.tcp://{0}/MyWfServiceB/mex", ip));&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;&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;    wfServiceHostB.Open()&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    Trace.WriteLine(String.Format("Opened wfServiceHostB"));&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;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With that, we can return to the RoleEntryPoint definition of our Worker Role and override the Run and OnStop Methods. For Run, because the WorkflowServiceHost takes care of all the processing, we just need to have a loop that keeps Run from exiting.&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;public override void Run()&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;/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;    Trace.WriteLine(&lt;span style="color: #006080"&gt;"Run - WFWorker entry point called"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"Information"&lt;/span&gt;)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    while (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;/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;/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;        Thread.Sleep(30000)&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&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;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For OnStop we simply close the WorkflowServiceHost.&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;public override void OnStop()&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;/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;    Trace.WriteLine(String.Format(&lt;span style="color: #006080"&gt;"OnStop - Called"&lt;/span&gt;))&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    if (wfServiceHostA != null)&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;        wfServiceHostA.Close()&lt;span style="color: #008000"&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 style="color: #008000"&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 style="color: #008000"&gt;    base.OnStop();&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;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With OnStart, Run and OnStop Methods defined, our Worker Role is fully capable of hosting a Workflow Service.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Hybrid Approach - Host Workflow On-Premise and Reach From the Cloud&lt;/h2&gt;
&lt;p&gt;Unlike &amp;lsquo;pure&amp;rsquo; cloud solutions, &lt;i&gt;hybrid &lt;/i&gt;solutions have a set of &amp;ldquo;on-premises&amp;rdquo; components: business processes, data stores, and services. These must be on-premises, possibly due to compliance or deployment restrictions. A &lt;i&gt;hybrid&lt;/i&gt; solution is one which has parts of the solution deployed in the cloud while some applications remain deployed on-premises. &lt;/p&gt;
&lt;p&gt;This is a great interim approach, leveraging on-premise Workflows hosted within on-premise Windows Server AppFabric (as illustrated in the diagram below) to various components and application that are hosted in Azure.&amp;nbsp; This approach may also be applied if stateful/durable Workflows are required to satisfy scenarios. You can build a &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/11/29/hybrid-cloud-solutions-with-windows-azure-appfabric-middleware.aspx"&gt;Hybrid solution&lt;/a&gt; and run the Workflows on-premise and use either the &lt;a href="http://msdn.microsoft.com/en-us/library/ee732537.aspx"&gt;AppFabric Service Bus&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/gg432997.aspx"&gt;Windows Azure Connect&lt;/a&gt; to reach into your on-premise Windows Server AppFabric instance.&lt;/p&gt;
&lt;p&gt;&lt;img height="444" width="559" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3463.Fig_2D00_4_5F00_70F95405.png" alt="Fig 4" border="0" title="Fig 4" style="background-image: none; border-right-width: 0px; margin: ; 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;/p&gt;
&lt;p&gt;&lt;em&gt;Source: MSDN Blog &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/11/29/hybrid-cloud-solutions-with-windows-azure-appfabric-middleware.aspx"&gt;Hybrid Cloud Solutions with Windows Azure AppFabric Middleware&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;How do you choose which approach to take? The decision ultimately boils down to your specific requirements, but here are some pointers that can help.&lt;/p&gt;
&lt;p&gt;Hosting Workflow Services in a Web Role is very easy and robust. If your Workflow is using Receive Activities as part of its definition, you should be hosting in a Web Role. While you can build and host a Workflow Service within a Worker Role, you take on the responsibility of rebuilding the entire hosting infrastructure provided by IIS in the Web Role- which is a fair amount of non-value added work. That said, you will have to host in a Worker Role when you want to use a TCP endpoint, and a Web Role when you want to use an HTTP or HTTPS endpoint.&lt;/p&gt;
&lt;p&gt;Hosting non-service Workflows that poll for their tasks is most easily accomplished within a Worker Role. While you can build another mechanism to poll and then call Workflow Services hosted in a Web Role, the Worker Role is designed to support and keep a polling application alive. Moreover, if your Workflow design does not already define a Service, then you should host it in a Worker Role-- as Web Role hosting would require you to modify the Workflow definition to add the appropriate Receive Activities. &lt;/p&gt;
&lt;p&gt;Finally, if you have existing investments in Windows Server AppFabric as hosted Services that need to be called from Azure hosted applications, then taking a hybrid approach is a very viable option. One clear benefit, is that you retain the ability to monitor your system&amp;rsquo;s status through the IIS Dashboard. Of course this approach has to be weighed against the obvious trade-offs of added complexity and bandwidth costs. &lt;/p&gt;
&lt;p&gt;The &lt;a href="http://www.bing.com/search?q=azure+appfabric+pdc+10&amp;amp;src=IE-SearchBox&amp;amp;FORM=IE8SRC"&gt;upcoming release of Azure AppFabric&lt;/a&gt; Composite Applications will enable hosting Workflow Services directly in Azure while providing feature parity to Windows Server AppFabric. Stay tuned for the exciting news and updates on this front.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Sample&lt;/h1&gt;
&lt;p&gt;The sample project attached provides a solution that shows how to host non-durable Workflows, in both Service and non-Service forms. For non-Service Workflows, it shows how to host using a WorkflowInvoker or WorkflowApplication within a Worker Role. For Services, it shows how to host both traditional WCF service alongside Workflow services, in both Web and Worker Roles. &lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:32fd96c2-ec17-4b74-b272-45d8b70f5486" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div class="wlWriterSmartContent" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:32fd96c2-ec17-4b74-b272-45d8b70f5486" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111324" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-11-13-24/Code-for-Blog-Entry-Running-NET4-Windows-Workflows-in-Azure.zip" length="6844709" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Best+Practices/">Best Practices</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/-NET4/">.NET4</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Azure/">Azure</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Windows+Azure/">Windows Azure</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/SurenM/">SurenM</category></item><item><title>StreamInsight: Creating a LINQPad data context</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/05/streaminsight-creating-a-linqpad-data-context.aspx</link><pubDate>Wed, 05 Jan 2011 18:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111824</guid><dc:creator>Mark Simms [MSFT]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10111824</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10111824</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/05/streaminsight-creating-a-linqpad-data-context.aspx#comments</comments><description>&lt;p&gt;This blog post is for those folks comfortable with creating a data stream from an IEnumerable, IObservable or StreamInsight adapter data source.&amp;#160; If you’d like more details on creating those, have a look at this &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/27/creating-a-custom-streaminsight-query-context-for-linqpad-chock-full-of-weathery-goodness.aspx"&gt;blog post&lt;/a&gt;, which covers creating an IEnumerable ‘canned’ data source then wrapping a LINQPad context around it.&lt;/p&gt;  &lt;p&gt;Creating a data context is very straightforward:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create a new C# class library project in Visual Studio 2010 called &lt;strong&gt;SampleContext&lt;/strong&gt;.       &lt;ul&gt;       &lt;li&gt;Ensure that the Framework type is set to .NET Framework 4 (and NOT .NET Framework 4 Client Profile) &lt;/li&gt;        &lt;li&gt;Add a reference to &lt;em&gt;Microsoft.ComplexEventProcessing.dll&lt;/em&gt; &lt;/li&gt;        &lt;li&gt;Add a reference to &lt;em&gt;Microsoft.ComplexEventProcessing.Observable.dll&lt;/em&gt;           &lt;ul&gt;           &lt;li&gt;This is required for the &lt;em&gt;IObservable&amp;lt;T&amp;gt;.ToPointStream &lt;/em&gt;extension method. &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;Add a reference to &lt;em&gt;Microsoft.ComplexEventProcessing.Adapters.dll&lt;/em&gt;           &lt;ul&gt;           &lt;li&gt;Optional – this is only required if you have an adapter embedded inside of your context &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;Add a reference to &lt;em&gt;System.Reactive.dll &lt;/em&gt;          &lt;ul&gt;           &lt;li&gt;Optional – this is only required for creating different types of &lt;em&gt;IObservable &lt;/em&gt;streams. &lt;/li&gt;            &lt;li&gt;Note: System.Reactive.dll is part of the &lt;a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx"&gt;Reactive Extensions&lt;/a&gt; framework, which needs to be downloaded separately. &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Derive a class from &lt;em&gt;StreamInsightContext &lt;/em&gt;in the &lt;em&gt;StreamInsightLinqPad.Samples &lt;/em&gt;assembly (available as part of the &lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2010/11/24/streaminsight-linqpad-driver.aspx"&gt;LINQPad driver for StreamInsight&lt;/a&gt; download). &lt;/li&gt;    &lt;li&gt;Expose your stream as a property of the class. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="494"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="60"&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14785"&gt;&lt;img title="3d Glossy Blue Orbs Business Stacked Document Icon" alt="3d Glossy Blue Orbs Business Stacked Document Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-business/thumbs/thumbs_075754-3d-glossy-blue-orb-icon-business-document4.png" width="64" height="64" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="432"&gt;Download the sample project &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14785"&gt;here&lt;/a&gt;.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;That’s it!&amp;#160; Here’s what this looks like in practice.&amp;#160; First we establish the basic 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:9d93ce11-91e1-44a4-9ec1-c79e67c5b746" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; System;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; System.Linq;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; System.Text;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; StreamInsightLinqPad.Samples;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; Microsoft.ComplexEventProcessing;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; Microsoft.ComplexEventProcessing.Linq;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; StreamInsight.Samples.Adapters.DataGenerator;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Define a sample LINQPad context for StreamInsight&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&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;SampleContext&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;StreamInsightContext&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; SampleContext(&lt;span style="color:#2b91af"&gt;Server&lt;/span&gt; server)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            : &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;(server)&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 we’ll go ahead and expose three types of streams.&amp;#160; The first will be one generated from an IEnumerable.&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:4fba8004-9ae5-435d-a9f9-845357a76cec" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt;[] events = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt;[]&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt; { Timestamp = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;(2011, 1, 5, 12, 0, 0), ID = 5, Message = &lt;span style="color:#a31515"&gt;&amp;quot;Test&amp;quot;&lt;/span&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;SimpleEvent&lt;/span&gt; { Timestamp = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;(2011, 1, 5, 13, 0, 0), ID = 6, Message = &lt;span style="color:#a31515"&gt;&amp;quot;Test2&amp;quot;&lt;/span&gt; },&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt; { Timestamp = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;(2011, 1, 5, 14, 0, 0), ID = 7, Message = &lt;span style="color:#a31515"&gt;&amp;quot;Test3&amp;quot;&lt;/span&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;SimpleEvent&lt;/span&gt; { Timestamp = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;(2011, 1, 5, 15, 0, 0), ID = 5, Message = &lt;span style="color:#a31515"&gt;&amp;quot;Test4&amp;quot;&lt;/span&gt; },&lt;/li&gt; &lt;li&gt;};&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;/li&gt; &lt;li&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Expose a stream created from an IEnumerable&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&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:#2b91af"&gt;CepStream&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt;&amp;gt; SimpleStream&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:#0000ff"&gt;return&lt;/span&gt; events.ToPointStream(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.Application, t =&amp;gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;PointEvent&lt;/span&gt;.CreateInsert&amp;lt;&lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt;&amp;gt;(t.Timestamp, t),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime);&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;Next, we’ll use IObservable (created via Observer.Interval) to generate a “live” stream of events:&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:008d2cf4-a42a-4bb3-adbf-a085a5e6f381" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Expose a stream created from an IObservable&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&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:#2b91af"&gt;CepStream&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt;&amp;gt; ObservableStream&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:#0000ff"&gt;var&lt;/span&gt; rand = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Random&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;// Create a simple observable that returns a random event every&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// 250 ms&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; interval = &lt;span style="color:#2b91af"&gt;Observable&lt;/span&gt;.Interval(&lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromMilliseconds(250))&lt;/li&gt; &lt;li&gt;            .Select(i =&amp;gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SimpleEvent&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                ID = rand.Next(10),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.UtcNow,&lt;/li&gt; &lt;li&gt;                Message = &lt;span style="color:#a31515"&gt;&amp;quot;Observable message!&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;return&lt;/span&gt; interval.ToPointStream(Application, s =&amp;gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;PointEvent&lt;/span&gt;.CreateInsert(s.Timestamp, s),&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime,&lt;/li&gt; &lt;li style="background: #f3f3f3"&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;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Finally, we’ll leverage the DataGenerator sample adapter (from &lt;a title="http://streaminsight.codeplex.com/" href="http://streaminsight.codeplex.com/"&gt;http://streaminsight.codeplex.com/&lt;/a&gt;) to demonstrate creating a LINQPad stream from an adapter.&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:6b000f5f-aa85-466e-a12a-bfb8e8ba2606" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Expose a stream created from an adapter instance&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&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:#2b91af"&gt;CepStream&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;GeneratedEvent&lt;/span&gt;&amp;gt; AdapterStream&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:#0000ff"&gt;var&lt;/span&gt; generatorConfig = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;GeneratorConfig&lt;/span&gt;()&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            CtiFrequency = 1,&lt;/li&gt; &lt;li&gt;            DeviceCount = 3,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            EventInterval = 250,&lt;/li&gt; &lt;li&gt;            EventIntervalVariance = 10,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            MaxValue = 100&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;var&lt;/span&gt; inputStream = &lt;span style="color:#2b91af"&gt;CepStream&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;GeneratedEvent&lt;/span&gt;&amp;gt;.Create(Application,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#a31515"&gt;&amp;quot;inputStream&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;GeneratorFactory&lt;/span&gt;), generatorConfig,&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;EventShape&lt;/span&gt;.Point);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; inputStream;&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;To test, we’ll need to configure LINQPad with our assembly as a data context.&amp;#160; To do this:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Add Connection&lt;/strong&gt;, then select &lt;strong&gt;Microsoft StreamInsight &lt;/strong&gt;from the list of drivers. &lt;/li&gt;    &lt;li&gt;Select &lt;em&gt;Custom Context &lt;/em&gt;from the &lt;strong&gt;Context Kind &lt;/strong&gt;dropdown. &lt;/li&gt;    &lt;li&gt;Click on the ellipsis for Assembly Path (...), then browse to the directory containing &lt;em&gt;SampleContext.dll&lt;/em&gt;. &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;OK &lt;/strong&gt;to finish selecting the new context. &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-38-83-metablogapi/6708.image_5F00_66A9C1EC.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/5488.image_5F00_thumb_5F00_021E9E23.png" width="455" height="300" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The context streams should now be visible in LINQPad, similar to the screenshot below.&amp;#160; Create a new Query, and select &lt;strong&gt;C# Statements &lt;/strong&gt;as the Language, and &lt;strong&gt;StreamInsight: SampleContext &lt;/strong&gt;as the database.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7024.image_5F00_3D425421.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/1134.image_5F00_thumb_5F00_0CEB599E.png" width="644" height="185" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Let’s dump our streams, using this LINQ code:&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:c2c11350-ffc7-43c6-836c-bf4e1913198c" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;// Dump out the enumerable stream.  Since this is an IEnumerable, it &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// will eventually complete and return&lt;/span&gt;&lt;/li&gt; &lt;li&gt;SimpleStream.ToEnumerable().Dump(&lt;span style="color:#a31515"&gt;&amp;quot;Enumerable stream&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:#008000"&gt;// Dump out the observable stream.  As this is an IObservable without&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// an end condition, we will have to stop the query (as it will not&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;// stop on its own)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;ObservableStream.ToObservable().Dump(&lt;span style="color:#a31515"&gt;&amp;quot;Observable stream&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;This will show us our enumerable and observable streams:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7484.image_5F00_08452917.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/7450.image_5F00_thumb_5F00_150F5968.png" width="518" height="594" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Finally, let’s dump out some data from our adapter 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:b1c08e99-cba6-4855-b15f-4ed503fe0c92" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;// Dump out the adapter stream.  As this is an adapter without&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// an end condition, we will have to stop the query (as it will not&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;// stop on its own)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;AdapterStream.ToObservable().Dump(&lt;span style="color:#a31515"&gt;&amp;quot;Adapter stream&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Resulting in:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2335.image_5F00_29D12C1B.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/2620.image_5F00_thumb_5F00_64F4E219.png" width="544" height="367" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="634"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="65"&gt;&lt;img title="Firey Orange Jelly Signs Bomb (Bombs) Icon Style 2" alt="Firey Orange Jelly Signs Bomb (Bombs) Icon Style 2" src="http://icons.mysitemyway.com/wp-content/gallery/firey-orange-jelly-icons-signs/thumbs/thumbs_091400-firey-orange-jelly-icon-signs-bomb1.png" width="64" height="64" /&gt;&lt;/td&gt;        &lt;td valign="top" width="567"&gt;Note – I had to make one change to the adapter code to make it work with &lt;em&gt;ToObservable&lt;/em&gt;.&amp;#160; The GeneratedEvent definition doesn’t define a default constructor (which is needed by ToObservable).&amp;#160;&amp;#160; In GeneratedEvent.cs, on line 23 I added the code:           &lt;br /&gt;          &lt;br /&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:bfe61fa6-d148-4f5d-9427-41072cd8b9c4" 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:#0000ff"&gt;public&lt;/span&gt; GeneratedEvent()&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;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;That’s it – a LINQPad data context in a nutshell.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111824" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/StreamInsight/">StreamInsight</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/CEP/">CEP</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/LINQ/">LINQ</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/LINQPad/">LINQPad</category></item><item><title>StreamInsight: Creating a custom data context for LINQPad, chock full of weathery goodness.</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/04/creating-a-custom-streaminsight-query-context-for-linqpad-chock-full-of-weathery-goodness.aspx</link><pubDate>Wed, 05 Jan 2011 02:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111828</guid><dc:creator>Mark Simms [MSFT]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10111828</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10111828</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2011/01/04/creating-a-custom-streaminsight-query-context-for-linqpad-chock-full-of-weathery-goodness.aspx#comments</comments><description>&lt;p&gt;Following on the heels of my last query pattern blog post, I started to dig into creating a custom data context for use with StreamInsight and LINQPad.&amp;#160; The default contexts supplied out of box with the StreamInsight driver (including the Hitchhiker’s Guide context) are great, but don’t contain a large volume of data.&amp;#160; I wanted to put together a much larger context to have a baseline to play with larger and more complicated query patterns.&amp;#160; My goals for the context/data streams were:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Contain “real” process data, around a &lt;strong&gt;million “real” data records &lt;/strong&gt;with accompanying metadata. &lt;/li&gt;    &lt;li&gt;Be easily transferrable / downloadable &lt;/li&gt;    &lt;li&gt;Be (relatively) human readable &lt;/li&gt;    &lt;li&gt;Be performant (sustain at least 60k events read / sec on my desktop) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Building on the fun I had putting together the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/13/streaminsight-query-patterns-fun-with-process-data-calculating-the-wind-chill-factor.aspx"&gt;windchill sample&lt;/a&gt;, here’s what I decided on:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use weather data from &lt;a href="http://www.weatheroffice.gc.ca/canada_e.html"&gt;Environment Canada&lt;/a&gt;, who has kindly made a great deal of information available for download in XML format.       &lt;ul&gt;       &lt;li&gt;This includes both the “live” weather and reference data about the producing weather stations.&amp;#160; I chose to use airport weather information, as it is a lot more granular than your average weather station. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Create a custom data context which can pull information from &lt;strong&gt;compressed CSV &lt;/strong&gt;files, and expose it as a &lt;a href="http://technet.microsoft.com/en-us/library/microsoft.complexeventprocessing.linq.cepstream.aspx"&gt;CepStream&lt;/a&gt;. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="69"&gt;         &lt;p&gt;&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2011/01/04/streaminsight-creating-a-linqpad-data-context.aspx"&gt;&lt;img title="3d Glossy Green Orbs Transport Travel Ship Wheel (Wheel) Icon" alt="3d Glossy Green Orbs Transport Travel Ship Wheel (Wheel) Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-green-orbs-icons-transport-travel/thumbs/thumbs_104721-3d-glossy-green-orb-icon-transport-travel-ship-wheel.png" width="64" height="64" /&gt;&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="731"&gt;If you’re already comfortable with exposing data via IEnumerable interface, check out this &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2011/01/04/streaminsight-creating-a-linqpad-data-context.aspx"&gt;blog post&lt;/a&gt; that provides a concise summary of creating data contexts.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="69"&gt;         &lt;p&gt;&lt;a href="http://blogs.msdn.com/b/masimms/archive/2010/12/28/adventures-in-performance-tuning.aspx"&gt;&lt;img title="3d Glossy Green Orbs Transport Travel Car Gauge (Gauges) Icon version 1" alt="3d Glossy Green Orbs Transport Travel Car Gauge (Gauges) Icon version 1" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-green-orbs-icons-transport-travel/thumbs/thumbs_104715-3d-glossy-green-orb-icon-transport-travel-car-gauge2.png" width="64" height="64" /&gt;&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="731"&gt;Why did I choose to store the canned data set as a compressed CSV file?&amp;#160; Based on a series of performance explorations, this turned out to be the best choice between file size (being downloadable), and performance (throughput).          &lt;br /&gt;          &lt;br /&gt;For all of the gory performance exploration, check out this &lt;a href="http://blogs.msdn.com/b/masimms/archive/2010/12/28/adventures-in-performance-tuning.aspx"&gt;blog post&lt;/a&gt;.&amp;#160; &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;This blog post walks through the various steps of creating the custom data context:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Preparing a canned data set (Downloading, parsing and formatting). &lt;/li&gt;    &lt;li&gt;Reading back the canned data set &lt;/li&gt;    &lt;li&gt;Creating a LINQPad data context which exposes the data set as a &lt;a href="http://technet.microsoft.com/en-us/library/microsoft.complexeventprocessing.linq.cepstream.aspx"&gt;CepStream&lt;/a&gt;&amp;lt;T&amp;gt;. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you’re comfortable with creating/accessible canned data sets, and you just want to create a custom LINQPad context for use with StreamInsight, skip directly to that section.&amp;#160; &lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="76"&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14736"&gt;&lt;img title="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" alt="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-business/thumbs/thumbs_075750-3d-glossy-blue-orb-icon-business-document.png" width="64" height="64" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="724"&gt;         &lt;p&gt;Before you start reading through the blog, download and follow along with the code samples:            &lt;br /&gt;&lt;/p&gt;          &lt;ul&gt;           &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14736"&gt;Complete package (weather context and LINQ samples)&lt;/a&gt; &lt;/li&gt;         &lt;/ul&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Preparing a canned data set – Downloading &lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.weatheroffice.gc.ca/canada_e.html"&gt;Environment Canada&lt;/a&gt; rocks.&amp;#160; They really do (caveat: I am Canadian &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-38-83-metablogapi/1134.wlEmoticon_2D00_smile_5F00_19A3BE24.png" /&gt;).&amp;#160; They’ve made a great deal of climatic data available for download in their &lt;a href="http://www.climate.weatheroffice.gc.ca/climateData/canada_e.html"&gt;National Climate Archives&lt;/a&gt; On-line.&amp;#160; From the &lt;a href="http://www.climate.weatheroffice.gc.ca/climateData/canada_e.html"&gt;National Climate Archives&lt;/a&gt; site, I chose to download ten year’s worth of information for ten airports in Canada (airport weather stations tend to record and archive data in 30 minute or hourly increments – most “other” weather stations seem to record 2-3x per day).&amp;#160; Since the goal is &lt;strong&gt;lots &lt;/strong&gt;of time-series data to look at weather stations it is (hourly records gives us 8760 records per year per weather station.&amp;#160; 10 stations times 10 years gives us 876k records.. close enough &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-38-83-metablogapi/1134.wlEmoticon_2D00_smile_5F00_19A3BE24.png" /&gt;).&lt;/p&gt;  &lt;p&gt;You can see the available stations in a given area and timeframe by looking at their &lt;a href="http://www.climate.weatheroffice.gc.ca/advanceSearch/searchHistoricData_e.html?timeframe=1&amp;amp;Prov=XX&amp;amp;StationID=9999&amp;amp;Year=2010&amp;amp;Month=12&amp;amp;Day=21"&gt;customized search&lt;/a&gt;.&amp;#160; Being familiar with Canadian airport geography, I selected them by:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.climate.weatheroffice.gc.ca/advanceSearch/searchHistoricData_e.html?timeframe=1&amp;amp;Prov=XX&amp;amp;StationID=9999&amp;amp;Year=2010&amp;amp;Month=12&amp;amp;Day=21"&gt;Searching by province for a specific date&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Selecting the data for an &lt;a href="http://www.climate.weatheroffice.gc.ca/climateData/hourlydata_e.html?timeframe=1&amp;amp;Prov=CA&amp;amp;StationID=6720&amp;amp;Year=2010&amp;amp;Month=12&amp;amp;Day=21"&gt;airport&lt;/a&gt; (I happened to know what they were). &lt;/li&gt;    &lt;li&gt;From the specific screen, there’s a navigation option to download data in either CSV or XML format.&amp;#160; I chose to download in XML (this was before I had settled on using CSV as the store format of choice).      &lt;ul&gt;       &lt;li&gt;The station code and station metadata is also available from the URL for this view (for example, the station code for St. John’s, Newfoundland is 6720. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The web URL for downloading data was of the form:&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:82f45957-9cdd-461f-bb97-5d0b2da256db" 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;var&lt;/span&gt;&lt;span style="color:#000000"&gt; urlQuery = &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;http://www.climate.weatheroffice.gc.ca/climateData/bulkdata_e.html? timeframe=1&amp;amp;Prov=XX&amp;amp;StationID={0}&amp;amp;Year={1}&amp;amp;Month={2}&amp;amp;Day={3}&amp;amp;format={4}&amp;amp;type=hly&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;With the following variables:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;( 0 ) Station ID &lt;/li&gt;    &lt;li&gt;( 1 ) Year &lt;/li&gt;    &lt;li&gt;( 2 ) Month &lt;/li&gt;    &lt;li&gt;( 3 ) Day &lt;/li&gt;    &lt;li&gt;( 4 ) Format (XML, CSV) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Next step was to script up a downloader that pulled down data for 2010 for each of my target weather stations.&amp;#160; Threw something quick together in LINQPad to accomplish this.&amp;#160; Each invocation of this URL will return data for the given &lt;strong&gt;month &lt;/strong&gt;(i.e. the day value is ignored).&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="800"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="76"&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14737"&gt;&lt;img title="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" alt="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-business/thumbs/thumbs_075750-3d-glossy-blue-orb-icon-business-document.png" width="64" height="64" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="724"&gt;Download the LINQ script &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14737"&gt;Download_WeatherData&lt;/a&gt;.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;After running this script, I had available to me roughly 1.0 GB of raw XML weather data.&amp;#160; The contents took the form:&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:4c91a5ad-50f2-4a7f-af69-3fc5f1f47b83" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;stationinformation&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;name&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;OTTAWA MACDONALD-CARTIER INT&lt;span style="color:#ff0000"&gt;&amp;amp;apos;&lt;/span&gt;L  A&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;name&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;province&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;ONTARIO&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;province&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;latitude&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;45.32&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;latitude&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;longitude&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;-75.67&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;longitude&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;elevation&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;114.00&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;elevation&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;climate_identifier&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;6106000&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;climate_identifier&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;wmo_identifier&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;71628&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;wmo_identifier&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;tc_identifier&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;YOW&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;tc_identifier&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;note&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;All times are specified in Local Standard Time (LST). Add 1 hour to adjust for Daylight Saving Time where and when it is observed.&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;note&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;stationinformation&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;stationdata&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;day&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;hour&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;minute&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;month&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;year&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;2010&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;quality&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &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;temp&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Temperature&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;units&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;#176;C&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;-5.30&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;temp&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;dptemp&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Dew Point Temperature&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;units&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;#176;C&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;-6.00&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;dptemp&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;visibility&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Visibility&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;units&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;km&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;4.80&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;visibility&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;relhum&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Relative Humidity&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;units&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;%&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;95.00&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;relhum&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;winddir&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Wind Direction&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;units&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;10&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;amp;apos;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;s deg&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;9.00&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;winddir&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;windspd&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Wind Speed&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;units&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;km/h&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;15.00&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;windspd&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;stnpress&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Station Pressure&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;units&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;kPa&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;100.03&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;stnpress&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;humidex&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Humidex&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;humidex&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;windchill&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Wind Chill&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;-11.00&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;windchill&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;weather&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;description&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Weather&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;Snow&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;weather&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;stationdata&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;Note that we have both the station metadata and the “live” weather data available to us.&amp;#160; The next step will be to render this data into two separate data sets:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Sorted list of weather data across all of the weather stations, saved as a CSV file with headers. &lt;/li&gt;    &lt;li&gt;List of weather station information (one record for each station), saved as a CSV file with headers. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Note that we will also have to shift the timestamp on each data record to the appropriate &lt;a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx"&gt;DateTimeOffset&lt;/a&gt;.&amp;#160; We’ll use another handy little LINQ nugget to do this (I’ve really gotten into using LINQPad as my general purpose C# scratchpad).&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="76"&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14738"&gt;&lt;img title="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" alt="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-business/thumbs/thumbs_075750-3d-glossy-blue-orb-icon-business-document.png" width="64" height="64" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="724"&gt;Download the LINQ script &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14738"&gt;Parse_WeatherData&lt;/a&gt;.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Let’s walk through the main method before diving into the two key functions, &lt;em&gt;ParseWeatherData &lt;/em&gt;and &lt;em&gt;CsvSequenceStore.WriteEvents&amp;lt;T&amp;gt;&lt;/em&gt;.&amp;#160; We grab the list of files from the download directory (in this case we just take 5 to run quickly and work with a smaller amount of data for test purposes).&amp;#160; Next, iterate over the list of files, parsing each and inserting the results into the &lt;strong&gt;weatherData &lt;/strong&gt;and &lt;strong&gt;stations &lt;/strong&gt;lists.&amp;#160; The weatherData list is then sorted before being written into the output file via the &lt;em&gt;CsvSequenceStore.&amp;#160; &lt;/em&gt;Note how we use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx"&gt;GZipStream&lt;/a&gt; to transparently write out a compressed stream.&amp;#160; &lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="76"&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" alt="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067869-3d-glossy-blue-orb-icon-alphanumeric-icon_091.png" width="64" height="64" /&gt;&lt;/td&gt;        &lt;td valign="top" width="724"&gt;         &lt;p&gt;Note that the entire 1 GB worth of data is read into memory before being written out to the destination file.&amp;#160; This isn’t the world’s best coding practice.&amp;#160; What I should have done was:&lt;/p&gt;          &lt;ul&gt;           &lt;li&gt;Written out each weather data file to a common output .CSV file &lt;/li&gt;            &lt;li&gt;Sorted the .CSV file. &lt;/li&gt;            &lt;li&gt;Compressed the .CSV file. &lt;/li&gt;         &lt;/ul&gt;          &lt;p&gt;However, as this was a one-shot, and I have lots of memory on my desktop, I brute-forced it. &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-38-83-metablogapi/1134.wlEmoticon_2D00_smile_5F00_19A3BE24.png" /&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&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:7bebbdab-b536-4298-822f-87f1eac35fd0" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="color:#000000"&gt; Main()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#000000"&gt;{            &lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Get a list of all of the downloaded XML files.&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; fileList = Directory.GetFiles(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;@&amp;quot;C:&amp;#92;temp&amp;#92;weatherdata&amp;#92;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;.Take(&lt;/span&gt;&lt;span style="color:#c81efa"&gt;5&lt;/span&gt;&lt;span style="color:#000000"&gt;) &lt;/span&gt;&lt;span style="color:#008000"&gt;/* Take the first 5 for testing purposes */&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;.Where(d =&amp;gt; d.EndsWith(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;.xml&amp;quot;&lt;/span&gt;&lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Define the output file&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; outputFile = &lt;/span&gt;&lt;span style="color:#dc1414"&gt;@&amp;quot;C:&amp;#92;temp&amp;#92;weather_data_out.csv.gz&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; stationFile = &lt;/span&gt;&lt;span style="color:#dc1414"&gt;@&amp;quot;C:&amp;#92;temp&amp;#92;station_data_out.csv.gz&amp;quot;&lt;/span&gt;&lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Create holding lists for weather data and stations        &lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; weatherData = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; List&amp;lt;WeatherReading&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; stations = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; List&amp;lt;StationData&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Iterate through the file list and parse for weather data&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; fileCount = (&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;)fileList.ToList().Count();            &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; progress = &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0.0&lt;/span&gt;&lt;span style="color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;fileList.ToList().ForEach(fl =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;{                                &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;Console.WriteLine(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;{0:00.0} Parsing file {1}&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;(progress / fileCount * &lt;/span&gt;&lt;span style="color:#c81efa"&gt;100.0&lt;/span&gt;&lt;span style="color:#000000"&gt;), fl);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;ParseWeatherData(fl, weatherData, stations);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;progress++;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Sort the weather data into strict ascending time order&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;weatherData = weatherData.OrderBy(d =&amp;gt; d.Timestamp).ToList();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Use the CSV store&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;CsvSequenceStore store = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; CsvSequenceStore();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Write the data to a compressed file using the GZipStream class.  Way cool.&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;Console.WriteLine(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;Writing {0} events to file {1}&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;weatherData.Count, outputFile);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="color:#000000"&gt; (FileStream fs = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; FileStream(outputFile, FileMode.Create))&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="color:#000000"&gt; (GZipStream zipStream = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; GZipStream(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;          &lt;span style="color:#000000"&gt;fs, CompressionMode.Compress))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Write out the weather data set to the file, using the Timestamp field&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// as the event timestamp&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;store.WriteEvents&amp;lt;WeatherReading&amp;gt;(zipStream, weatherData,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;e =&amp;gt; e.Timestamp);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="color:#000000"&gt; (FileStream fs = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; FileStream(stationFile, FileMode.Create))&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="color:#000000"&gt; (GZipStream zipStream = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; GZipStream(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;          &lt;span style="color:#000000"&gt;fs, CompressionMode.Compress))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Write out the station data set to the file, using a hard coded&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// timestamp&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;store.WriteEvents&amp;lt;StationData&amp;gt;(zipStream, stations,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;e =&amp;gt; DateTime.Parse(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;2010-01-01 00:00:00&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;));&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now to dive into the first of the two key functions being called – &lt;em&gt;ParseWeatherData.&lt;/em&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:cb0278ed-a22e-44c0-a5b4-7b2f5d809604" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Parse through the file, extracting weather and station data      &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="color:#000000"&gt; ParseWeatherData(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt; fileName,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;List&amp;lt;WeatherReading&amp;gt; weatherData, List&amp;lt;StationData&amp;gt; stations)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="color:#000000"&gt; (!System.IO.File.Exists(fileName))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;throw&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; ArgumentException(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;Could not load file&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt; + fileName);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="color:#000000"&gt; (StreamReader sr = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; StreamReader(fileName))&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; xml = XElement.Load(sr);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Parse the station information&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; q = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;from&lt;/span&gt;&lt;span style="color:#000000"&gt; e &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; xml.Elements() &lt;/span&gt;&lt;span style="color:#0000ff"&gt;where&lt;/span&gt;&lt;span style="color:#000000"&gt; e.Name == &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;stationinformation&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt;&lt;span style="color:#000000"&gt; e;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; stationInfo = q.First();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; stationName = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; stationCode = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;wmo_identifier&amp;quot;&lt;/span&gt;&lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; newStation = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; StationData()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;Name = stationName,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;Elevation = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;elevation&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;Latitude = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;latitude&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;Longitude = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;longitude&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;TCID = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;tc_identifier&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;StationCode = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;wmo_identifier&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;Province = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(stationInfo, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;province&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// If this is a new station, add it to the list&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="color:#000000"&gt; (!stations.Where(s =&amp;gt; s.Name == stationName).Any())&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;stations.Add(newStation);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Parse the station data&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; sds = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;from&lt;/span&gt;&lt;span style="color:#000000"&gt; e &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; xml.Elements() &lt;/span&gt;&lt;span style="color:#0000ff"&gt;where&lt;/span&gt;&lt;span style="color:#000000"&gt; e.Name == &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;stationdata&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt;&lt;span style="color:#000000"&gt; e;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;sds.ToList().ForEach((e) =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="color:#000000"&gt; (!String.IsNullOrEmpty(GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;temp&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;)))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Assign the core values&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; wr = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; WeatherReading()&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;StationCode = stationCode,&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;Temperature = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;temp&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;DewpointTemperature = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;dptemp&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;Humidex = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;humidex&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;RelativeHumidity = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;relhum&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;StationPressure = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;stnpress&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;Visibility = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;visibility&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;WindChill = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;windchill&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;WindDirection = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;winddir&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;WindSpeed = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;double&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;windspd&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Convert the timestamp into universal time based&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// on the current station information (lookup based on&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// province                        &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; tzi = tzMap[newStation.Province];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Asemble the timestamp&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; dt = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; DateTimeOffset(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;GetAttribute&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;year&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;GetAttribute&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;month&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;GetAttribute&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;day&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;GetAttribute&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;hour&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;GetAttribute&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;minute&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;, tzi.BaseUtcOffset);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;wr.Timestamp = dt.UtcDateTime;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                                          &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Parse weather conditions - WeatherConditions is an enum&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// flags field&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;[] conditions = GetValue&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt;(e, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;weather&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;.Replace(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span style="color:#000000"&gt;, &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;#39;_&amp;#39;&lt;/span&gt;&lt;span style="color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;.Split(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;char&lt;/span&gt;&lt;span style="color:#000000"&gt;[] { &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style="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="color:#000000"&gt;WeatherConditions cond = WeatherConditions.None;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;WeatherConditions total = WeatherConditions.None;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000"&gt; (&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; s &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; conditions)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="color:#000000"&gt; (Enum.TryParse&amp;lt;WeatherConditions&amp;gt;(s, &lt;/span&gt;&lt;span style="color:#0000ff"&gt;out&lt;/span&gt;&lt;span style="color:#000000"&gt; cond))&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        &lt;span style="color:#000000"&gt;total |= cond;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Add the data to the list                    &lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;weatherData.Add(wr);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;This looks like a lot, but it’s simply an XML parser, leveraging the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.aspx"&gt;XElement&lt;/a&gt; class.&amp;#160; After opening up the file, we pull the file into an XElement object, then pluck out the station and weather (station data) information.&amp;#160; The GetValue&amp;lt;T&amp;gt; and GetAttribute&amp;lt;T&amp;gt; functions are simple helpers to ease extracting typed data from the various nodes and coercing the types.&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="76"&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" alt="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067869-3d-glossy-blue-orb-icon-alphanumeric-icon_091.png" width="64" height="64" /&gt;&lt;/td&gt;        &lt;td valign="top" width="724"&gt;         &lt;p&gt;Note that I use &lt;a href="http://msdn.microsoft.com/en-us/library/system.convert.changetype.aspx"&gt;Convert.ChangeType&lt;/a&gt; in the GetValue&amp;lt;T&amp;gt; and GetAttribute&amp;lt;T&amp;gt; functions.&amp;#160; This is a pretty slow method – I would have been better off using a switch() statement on the data type and &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert.aspx"&gt;XmlConvert&lt;/a&gt; for performance reasons.&amp;#160; &lt;/p&gt;          &lt;p&gt;However, as this is code that only runs once, I didn’t bother to add the performance optimization.&amp;#160; I did spend a lot of time on performance optimizations for &lt;strong&gt;reading &lt;/strong&gt;the data, which we’ll cover in the next section.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;There are only two “custom” operations in &lt;em&gt;ParseWeatherData, &lt;/em&gt;to handle two custom data parsing condtions:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Timezone offset&lt;/strong&gt;.&amp;#160; Each of the timestamps in the file is in local time.&amp;#160; In order to adjust to UTC time we need to determine the time zone (based on the province field in the stations information, which we use to look up a &lt;a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx"&gt;TimeZoneInfo&lt;/a&gt; object from a static dictionary I defined at the bottom of the linq file).&amp;#160; This is used as an argument to &lt;a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx"&gt;DateTimeOffset&lt;/a&gt; to shift the date to UTC. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Weather conditions&lt;/strong&gt;.&amp;#160; The input XML file can define weather conditions as having multiple values.&amp;#160; To support this in StreamInsight in a relatively straightforward fashion, I defined a bitwise [&lt;a href="http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx"&gt;Flags&lt;/a&gt;] enum (WeatherConditions) that I fill in on lines 72-83. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Finally, we have our friendly neighborhood &lt;em&gt;public void WriteEvents&amp;lt;T&amp;gt;(Stream stream, IEnumerable&amp;lt;T&amp;gt; events, Func&amp;lt;T, DateTimeOffset&amp;gt; dtFunc)&lt;/em&gt; method, which writes out each event to a .CSV file.&amp;#160; It takes as arguments:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Stream stream&lt;/strong&gt;.&amp;#160; The destination stream – taking a stream rather than a file name made it easy to substitute the GZipStream writer to easily add in compression. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;IEnumerable&amp;lt;T&amp;gt; events&lt;/strong&gt;.&amp;#160; The list of events to write out to the file. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Func&amp;lt;T,DatetimeOffset&amp;gt; dtFunc&lt;/strong&gt;.&amp;#160; In order to easily stream events into StreamInsight, we need to know the temporal properties of the event (i.e. the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.complexeventprocessing.pointevent.starttime.aspx"&gt;StartTime&lt;/a&gt;).&amp;#160; Since the CsvSequenceStore is generic, we hand in a function that identifies the temporal properties (in our case, returning e.Timestamp). &lt;/li&gt; &lt;/ul&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:3bad9b35-2c3c-4bee-845f-910024e50c83" 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: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="color:#000000"&gt; WriteEvents&amp;lt;T&amp;gt;(Stream stream, IEnumerable&amp;lt;T&amp;gt; events, &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;Func&amp;lt;T, DateTimeOffset&amp;gt; dtFunc)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; encodingArray = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;&lt;span style="color:#000000"&gt;[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;16000&lt;/span&gt;&lt;span style="color:#000000"&gt;];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; fields = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;&lt;span style="color:#000000"&gt;(T).GetProperties();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; lastField = fields.Last();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; sb = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; StringBuilder();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; str = String.Empty;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; byteLen = &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000"&gt; (&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; e &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; events)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;sb.Clear(); str = String.Empty; byteLen = &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// Write out the event kind, start time and end time                &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;sb.Append(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;Point,&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;sb.Append(dtFunc(e).Ticks);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;sb.Append(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;,,&amp;quot;&lt;/span&gt;&lt;span style="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="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000"&gt; (&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; o &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; fields)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#000000"&gt;sb.Append(o.GetValue(e, &lt;/span&gt;&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="color:#000000"&gt;).ToString());&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="color:#000000"&gt; (o != lastField)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#000000"&gt;sb.Append(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;,&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;sb.AppendLine();&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;str = sb.ToString();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;byteLen = Encoding.ASCII.GetBytes(str, &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;, str.Length, encodingArray, &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#000000"&gt;stream.Write(encodingArray, &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;, byteLen);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;This is a very straightforward function.&amp;#160; Using reflection, we obtain the list of public properties for the type (via &lt;a href="http://msdn.microsoft.com/en-us/library/system.type.getproperties.aspx"&gt;GetProperties&lt;/a&gt;()), and use a StringBuilder to assemble the text.&amp;#160; Wanted to avoid using &lt;a href="http://msdn.microsoft.com/en-us/library/57a79xd0.aspx"&gt;String.Join()&lt;/a&gt;, hence remembering &lt;em&gt;lastField&lt;/em&gt;.&amp;#160; Then iterate through the list of properties, and use the reflection method &lt;a href="http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.getvalue.aspx"&gt;GetValue&lt;/a&gt; to write out the string representation to the line.&lt;/p&gt;  &lt;p&gt;As a base Stream class only understands writing out bytes, we convert the line into a byte array and write it out.&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="76"&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" alt="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067869-3d-glossy-blue-orb-icon-alphanumeric-icon_091.png" width="64" height="64" /&gt;&lt;/td&gt;        &lt;td valign="top" width="724"&gt;         &lt;p&gt;Note that I ASCII encoding here.&amp;#160; Really should be using Unicode encoding, but I happen to know that the data is pure ASCII (at least it is &lt;strong&gt;THIS &lt;/strong&gt;time).&amp;#160; Should a future blog feature Unicode data, this line will change &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-38-83-metablogapi/1134.wlEmoticon_2D00_smile_5F00_19A3BE24.png" /&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;After executing the script, I have a compressed .CSV file containing weather data.&amp;#160; Let’s have a look at the contents.&amp;#160; First step will be to unzip it into a plain .csv file (via the &lt;a href="http://gnuwin32.sourceforge.net/packages/gzip.htm"&gt;gzip.exe&lt;/a&gt; utility – I could write a script to do this, but we’ll get to using GzipStream to uncompress in the next section).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2046.image_5F00_072B47A2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/1641.image_5F00_thumb_5F00_0A7CB97D.png" width="674" height="440" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now, we crack open our .CSV files with note and have a look (not that these only have 5 weather files in them, as I left the .Take() method uncommented on line 5).&lt;/p&gt;  &lt;table border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;pre&gt;Point,633979188000000000,,71628,1/1/2010 5:00:00 AM,-5.3,-6,95,9,15,4.8,100.03,0,-11,0&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Excellent – we now have (mostly) human-readable data in a downloadable (i.e. small) format that we can extract quickly.&amp;#160; On to extraction!&lt;/p&gt;

&lt;h3&gt;Reading back the canned data set&lt;/h3&gt;

&lt;p&gt;We’ll stay in LINQPad for the time being (will switch over to Visual Studio when it comes time to create the actual data context – feel free to work through this code in VS.NET if it’s more comfortable).&amp;#160; Now that we have the canned data set (as our compressed .CSV file), we need to be able to read it back out again in a form that can be turned into a CepStream&amp;lt;T&amp;gt;.&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="76"&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14739"&gt;&lt;img title="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" alt="3d Glossy Blue Orbs Business Typed Folded Page Corner Document Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-business/thumbs/thumbs_075750-3d-glossy-blue-orb-icon-business-document.png" width="64" height="64" /&gt;&lt;/a&gt;&lt;/td&gt;

      &lt;td valign="top" width="724"&gt;Download the LINQ script &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14739"&gt;Read_WeatherData&lt;/a&gt;.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;This is very similar, yet a little simpler, than the code which we used in the last section to write the data into the compressed CSV file.&amp;#160; The parsing code is the same (also using the CsvSequenceStore class, only now using the &lt;em&gt;ReadEvent&amp;lt;T&amp;gt; &lt;/em&gt;method in place of the &lt;em&gt;WriteEvents&amp;lt;T&amp;gt; &lt;/em&gt;method.&amp;#160; The new piece that has been introduced is the assign function, which defines how we map from the CSV format into POCO (plain old CLR object) format.&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="76"&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" alt="3d Glossy Blue Orbs Alphanumeric Simple Question Mark Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067869-3d-glossy-blue-orb-icon-alphanumeric-icon_091.png" width="64" height="64" /&gt;&lt;/td&gt;

      &lt;td valign="top" width="724"&gt;
        &lt;p&gt;This doesn’t seem like a terribly generic way of implementing this, and its not.&amp;#160; The reason I’m using a function delegate, not reflection (via PropertyInfo.SetValue() and Convert.ChangeType()) is that we’re now in performance critical code and those two methods were &lt;strong&gt;killing &lt;/strong&gt;performance.&lt;/p&gt;

        &lt;p&gt;I’ll write the code for dynamically generating this function in a later blog, but for now if you’re interested in the performance numbers, head on over to my &lt;a href="http://blogs.msdn.com/b/masimms/archive/2010/12/28/adventures-in-performance-tuning.aspx"&gt;performance blog&lt;/a&gt; on this topic.&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&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:fdf0a752-1236-4f5f-94b7-c70ccd5ad559" 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: #ddd; overflow: auto"&gt;
&lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;void&lt;/span&gt;&lt;span style="color:#000000"&gt; Main()&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;CsvSequenceStore store = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; CsvSequenceStore();&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;     &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;long&lt;/span&gt;&lt;span style="color:#000000"&gt; count = &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="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="color:#000000"&gt;Action&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;[], WeatherReading&amp;gt; assign = (str, e) =&amp;gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;e.StationCode = Int32.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;e.Timestamp = DateTime.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;1&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;e.Temperature = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;2&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;e.DewpointTemperature = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;3&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;e.RelativeHumidity = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;4&lt;/span&gt;&lt;span style="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="color:#000000"&gt;e.WindDirection = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;5&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;e.WindSpeed = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;6&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;e.Visibility = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;7&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;e.Humidex = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;8&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;e.WindChill = Double.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;9&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;e.WeatherConditions = Int32.Parse(str[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;9&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="color:#000000"&gt; (FileStream fs = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; FileStream(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;@&amp;quot;C:&amp;#92;temp&amp;#92;weather_data_out.csv.gz&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;, FileMode.Open))&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt;&lt;span style="color:#000000"&gt; (GZipStream zipStream = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; GZipStream(&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;fs, CompressionMode.Decompress))&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; evts2 = store.ReadEvents&amp;lt;WeatherReading&amp;gt;(zipStream, assign);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; weatherStream = evts2.Select (e =&amp;gt; e.Payload)&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#000000"&gt;.Take(&lt;/span&gt;&lt;span style="color:#c81efa"&gt;50&lt;/span&gt;&lt;span style="color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;weatherStream.Dump(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;weather events&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;);                &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Executing this simple main function gives us the shiny weather events (50 of them, as limited by the Take() method on line 30):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4377.image_5F00_520E92A4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/6765.image_5F00_thumb_5F00_6F343AAE.png" width="867" height="252" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The core of this approach lies in the ReadEvents&amp;lt;T&amp;gt; method, which is remarkably simple given the amount of code we’ve written to get to this point &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-38-83-metablogapi/1134.wlEmoticon_2D00_smile_5F00_19A3BE24.png" /&gt;.&amp;#160; Remembering that each line of CSV consists of the event shape (Point, Interval), the Start and End times, then the payload.&amp;#160; We use a wrapper object, TypedEventPayload&amp;lt;T&amp;gt; to encapsulate the payload along with the event characteristics.&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:070710d3-564d-4725-9f45-02d772b7dbc7" 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: #ddd; overflow: auto"&gt;
&lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="color:#000000"&gt; IEnumerable&amp;lt;TypedEventPayload&amp;lt;T&amp;gt;&amp;gt; ReadEvents&amp;lt;T&amp;gt;(Stream stream,&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;Action&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;[], T&amp;gt; assign) &lt;/span&gt;&lt;span style="color:#0000ff"&gt;where&lt;/span&gt;&lt;span style="color:#000000"&gt; T : &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt;()&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;StreamReader sr = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; StreamReader(stream);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;String line = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; fields = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;&lt;span style="color:#000000"&gt;(T).GetProperties();&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; lastField = fields.Last();&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;while&lt;/span&gt;&lt;span style="color:#000000"&gt; ((line = sr.ReadLine()) != &lt;/span&gt;&lt;span style="color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="color:#000000"&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="color:#000000"&gt; (line.StartsWith(&lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;quot;EventShape,&amp;quot;&lt;/span&gt;&lt;span style="color:#000000"&gt;))&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;continue&lt;/span&gt;&lt;span style="color:#000000"&gt;;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;[] tokens = line.Split(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;char&lt;/span&gt;&lt;span style="color:#000000"&gt;[] { &lt;/span&gt;&lt;span style="color:#dc1414"&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style="color:#000000"&gt; });&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;TypedEventPayload&amp;lt;T&amp;gt; ep = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; TypedEventPayload&amp;lt;T&amp;gt;();&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;ep.Payload = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; T();&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;ep.Shape = (EventShape)Enum.Parse(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;&lt;span style="color:#000000"&gt;(EventShape), tokens[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;]);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;ep.StartTime = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; DateTimeOffset(Int64.Parse(tokens[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;1&lt;/span&gt;&lt;span style="color:#000000"&gt;]), TimeSpan.FromSeconds(&lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;));&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="color:#000000"&gt; (String.IsNullOrEmpty(tokens[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;2&lt;/span&gt;&lt;span style="color:#000000"&gt;]))&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;ep.EndTime = ep.StartTime.AddTicks(&lt;/span&gt;&lt;span style="color:#c81efa"&gt;1&lt;/span&gt;&lt;span style="color:#000000"&gt;);&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;ep.EndTime = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; DateTimeOffset(Int64.Parse(tokens[&lt;/span&gt;&lt;span style="color:#c81efa"&gt;2&lt;/span&gt;&lt;span style="color:#000000"&gt;]), TimeSpan.FromSeconds(&lt;/span&gt;&lt;span style="color:#c81efa"&gt;0&lt;/span&gt;&lt;span style="color:#000000"&gt;));&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;assign(tokens.Skip(&lt;/span&gt;&lt;span style="color:#c81efa"&gt;3&lt;/span&gt;&lt;span style="color:#000000"&gt;).ToArray(), ep.Payload);        &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;yield&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="color:#000000"&gt; ep;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;}&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We now have an IEnumerable&amp;lt;T&amp;gt; which we can convert into a CepStream&amp;lt;T&amp;gt; via use of the &lt;a href="http://msdn.microsoft.com/en-us/library/gg144921.aspx"&gt;ToPointStream&lt;/a&gt; method.&amp;#160; &lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="76"&gt;
        &lt;p&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" alt="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067865-3d-glossy-blue-orb-icon-alphanumeric-exclamation-point1.png" width="64" height="64" /&gt;&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="724"&gt;
        &lt;p&gt;The really critical piece here is returning the events as an IEnumerable&amp;lt;T&amp;gt;, not as an array or list.&amp;#160; If we had to load the entire file into memory before sending a single event to StreamInsight, that wouldn’t be performant from either a memory or a latency perspective.&amp;#160; Instead, as we pull and deserialize events from the CSV file we &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0(VS.80).aspx"&gt;yield&lt;/a&gt; them back.&lt;/p&gt;

        &lt;p&gt;This will allow the CepStream&amp;lt;T&amp;gt; to consume events as they are raised (which we’ll do in the next step).&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Finally, we convert the IEnumerable&amp;lt;T&amp;gt; into a CepStream&amp;lt;T&amp;gt; and run some basic queries over 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:54bbe2be-1f20-4c8d-94b8-264d2ff1c232" 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: #ddd; overflow: auto"&gt;
&lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; evts2 = store.ReadEvents&amp;lt;WeatherReading&amp;gt;(zipStream, assign);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; weatherStream = evts2.Select (e =&amp;gt; e.Payload)                                        &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;.ToPointStream(Application, t =&amp;gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#000000"&gt;PointEvent.CreateInsert(t.Timestamp, t),&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#000000"&gt;AdvanceTimeSettings.IncreasingStartTime);&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="color:#000000"&gt; query = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;from&lt;/span&gt;&lt;span style="color:#000000"&gt; e &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; weatherStream&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#000000"&gt;.TumblingWindow(TimeSpan.FromDays(&lt;/span&gt;&lt;span style="color:#c81efa"&gt;1000&lt;/span&gt;&lt;span style="color:#000000"&gt;), HoppingWindowOutputPolicy.ClipToWindowEnd)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt;&lt;span style="color:#000000"&gt; &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;Count = e.Count()&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Excellent – we now have a CepStream&amp;lt;T&amp;gt; – the only remaining step to having a canned data set is simple packaging &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-38-83-metablogapi/1134.wlEmoticon_2D00_smile_5F00_19A3BE24.png" /&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-38-83-metablogapi/1385.image_5F00_55DF3722.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/2055.image_5F00_thumb_5F00_44AB597F.png" width="575" height="429" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="800"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="79"&gt;&lt;img title="Firey Orange Jelly Signs Bomb (Bombs) Icon Style 2" alt="Firey Orange Jelly Signs Bomb (Bombs) Icon Style 2" src="http://icons.mysitemyway.com/wp-content/gallery/firey-orange-jelly-icons-signs/thumbs/thumbs_091400-firey-orange-jelly-icon-signs-bomb1.png" width="64" height="64" /&gt;&lt;/td&gt;

      &lt;td valign="top" width="721"&gt;Wait!&amp;#160; You’re probably looking at the &lt;em&gt;IEnumerable&amp;lt;UntypedEventPayload&amp;gt; ReadEvents &lt;/em&gt;method and thinking to yourself “Mark.. that’s dumb.&amp;#160; That won’t work, &lt;strong&gt;because of the IEnumerable state machine, and how Dispose is handled!&lt;/strong&gt;”.&amp;#160; And you’d be right. 

        &lt;p&gt;Here’s the problem:&lt;/p&gt;

        &lt;ul&gt;
          &lt;li&gt;The method &lt;strong&gt;ReadEvents &lt;/strong&gt;assumes that someone else is responsible for initializing and &lt;strong&gt;disposing&lt;/strong&gt; of the stream (and any underlying resources – such as the file handle).&amp;#160; &lt;/li&gt;

          &lt;li&gt;&lt;em&gt;IEnumerable&lt;/em&gt;, and the corresponding yield statement, create an internal state machine when compiled (i.e. the enumeration uses &lt;em&gt;deferred execution &lt;/em&gt;– the behavior we want).&amp;#160; The &lt;em&gt;IEnumerable &lt;/em&gt;is not finished with the underlying stream until it has enumerated through all of the available values (in our case read to the end of the file). &lt;/li&gt;

          &lt;li&gt;As such, the lifetime of the Stream needs to be tied to the lifetime of the enumerator (as only the code that manages the enumerator knows when it is complete). &lt;/li&gt;

          &lt;li&gt;Since this design has the stream managed separately from the enumerator, the underlying stream could be closed before the enumerator even begins to evaluate. &lt;/li&gt;
        &lt;/ul&gt;

        &lt;p&gt;Our current code base works, as we force the entire query to complete before exiting the &lt;strong&gt;using &lt;/strong&gt;block that creates the stream.&amp;#160; In a LINQPad context wherein we need to raise the stream from a function and have no direct control over the lifetime of a query this will have the &lt;u&gt;effect of closing the underyling file before any events are read&lt;/u&gt;.&lt;/p&gt;

        &lt;p&gt;We need to redesign our code to encapsulate the file reading into the same &lt;strong&gt;class&lt;/strong&gt; that exposes IEnumerable, and handles stream cleanup correctly.&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h3&gt;Reading back the canned data set – the Right Way!&lt;/h3&gt;

&lt;p&gt;Now, to take the prototype we built out in the last section, and put it in a form suitable for embedding into a library (which the LINQPad context will leverage).&amp;#160; We’ll create a base class, SequenceBase, which encapsulates creating streams from files (including compressed files).&amp;#160; This will allow us to more easily plug in different types of “serializers”.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0211.ClassDiagram1_5F00_28BA2487.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ClassDiagram1" border="0" alt="ClassDiagram1" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6177.ClassDiagram1_5F00_thumb_5F00_25C4BFD4.jpg" width="815" height="485" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SequenceBase &lt;/em&gt;is very straightforward, simply providing a helper function to create a new stream upon demand (to allow the enumerator to wrap it in a using() statement).&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:8c5132c5-276b-4297-a7c2-3c47e037c8a6" 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: #ddd; overflow: auto"&gt;
&lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; 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;abstract&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SequenceBase&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:#0000ff"&gt;string&lt;/span&gt; _fileName;&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;bool&lt;/span&gt; _compress;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; _open;&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:#2b91af"&gt;Stream&lt;/span&gt; GetStream()&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#008000"&gt;// If opening the file,     Open/read data/allow others to read&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// If writing a new file,   Create/write data/deny others access&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#2b91af"&gt;FileMode&lt;/span&gt; fMode = (_open) ? &lt;span style="color:#2b91af"&gt;FileMode&lt;/span&gt;.Open : &lt;span style="color:#2b91af"&gt;FileMode&lt;/span&gt;.Create;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;FileAccess&lt;/span&gt; aMode = (_open) ? &lt;span style="color:#2b91af"&gt;FileAccess&lt;/span&gt;.Read : &lt;span style="color:#2b91af"&gt;FileAccess&lt;/span&gt;.Write;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#2b91af"&gt;FileShare&lt;/span&gt; fShare = (_open) ? &lt;span style="color:#2b91af"&gt;FileShare&lt;/span&gt;.Read : &lt;span style="color:#2b91af"&gt;FileShare&lt;/span&gt;.None;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#008000"&gt;// Set the compression mode&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;CompressionMode&lt;/span&gt; cMode = (_open) ? &lt;span style="color:#2b91af"&gt;CompressionMode&lt;/span&gt;.Decompress&lt;/li&gt;
&lt;li&gt;            : &lt;span style="color:#2b91af"&gt;CompressionMode&lt;/span&gt;.Compress;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#008000"&gt;// Create the base file stream            &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; fs = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;FileStream&lt;/span&gt;(_fileName, fMode, aMode, fShare);&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#2b91af"&gt;Stream&lt;/span&gt; _stream = fs;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#008000"&gt;// If using Gzip compression, wrap the file stream&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (_compress)&lt;/li&gt;
&lt;li&gt;        {&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; zs = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; System.IO.Compression.&lt;span style="color:#2b91af"&gt;GZipStream&lt;/span&gt;(fs, cMode);&lt;/li&gt;
&lt;li&gt;            _stream = zs;&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; _stream;&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; SequenceBase(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; fileName, &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; compress, &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; open)&lt;/li&gt;
&lt;li&gt;    {&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        _fileName = fileName;&lt;/li&gt;
&lt;li&gt;        _compress = compress;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        _open = open;           &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;With this as a foundation, our Csv reader class becomes very straightforward to implement – essentially taking the contents of the ReadEvents&amp;lt;T&amp;gt; method from the previous section, and wrapping them up in a class derived from &lt;em&gt;SequenceBase&lt;/em&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:a6d64037-7390-4d23-a62c-269f7af821b9" 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: #ddd; overflow: auto"&gt;
&lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; 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;CsvSequenceReaderTyped&lt;/span&gt;&amp;lt;T&amp;gt; :&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;SequenceBase&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;IntervalEvent&lt;/span&gt;&amp;lt;T&amp;gt;&amp;gt;&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#0000ff"&gt;where&lt;/span&gt; T : &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;()&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt;
&lt;li&gt;    &lt;span style="color:#0000ff"&gt;protected&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[], T&amp;gt; _assign;&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; CsvSequenceReaderTyped(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; fileName, &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; compress,&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[], T&amp;gt; assign) : &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;(fileName, compress, &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;        _assign = assign;&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;IEnumerator&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;IntervalEvent&lt;/span&gt;&amp;lt;T&amp;gt;&amp;gt; GetEnumerator()&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; stream = GetStream())&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt;
&lt;li&gt;            &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; sr = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;StreamReader&lt;/span&gt;(stream))&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            { &lt;/li&gt;
&lt;li&gt;                &lt;span style="color:#2b91af"&gt;String&lt;/span&gt; line = &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;var&lt;/span&gt; fields = &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(T).GetProperties();&lt;/li&gt;
&lt;li&gt;                &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; lastField = fields.Last();&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;                &lt;span style="color:#0000ff"&gt;while&lt;/span&gt; ((line = sr.ReadLine()) != &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;                    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (line.StartsWith(&lt;span style="color:#a31515"&gt;&amp;quot;EventShape,&amp;quot;&lt;/span&gt;))&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                        &lt;span style="color:#0000ff"&gt;continue&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;                    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] tokens = line.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;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                                                &lt;/li&gt;
&lt;li&gt;                    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; shape = (&lt;span style="color:#2b91af"&gt;EventShape&lt;/span&gt;)&lt;span style="color:#2b91af"&gt;Enum&lt;/span&gt;.Parse(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;EventShape&lt;/span&gt;), tokens[0]);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; startTime = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTimeOffset&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Int64&lt;/span&gt;.Parse(tokens[1]), &lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromSeconds(0));&lt;/li&gt;
&lt;li&gt;                    &lt;span style="color:#2b91af"&gt;DateTimeOffset&lt;/span&gt; endTime;&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; (&lt;span style="color:#2b91af"&gt;String&lt;/span&gt;.IsNullOrEmpty(tokens[2]))&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                        endTime = startTime.AddTicks(1);&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;                        endTime = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTimeOffset&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Int64&lt;/span&gt;.Parse(tokens[2]), &lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromSeconds(0));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; ep = &lt;span style="color:#2b91af"&gt;IntervalEvent&lt;/span&gt;&amp;lt;T&amp;gt;.CreateInsert(&lt;/li&gt;
&lt;li&gt;                        startTime, endTime, &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; T());&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                        &lt;/li&gt;
&lt;li&gt;                   ��_assign(tokens.Skip(3).ToArray(), ep.Payload);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;                    &lt;span style="color:#0000ff"&gt;yield&lt;/span&gt; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; ep;&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;    }&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;    System.Collections.&lt;span style="color:#2b91af"&gt;IEnumerator&lt;/span&gt; System.Collections.&lt;span style="color:#2b91af"&gt;IEnumerable&lt;/span&gt;.GetEnumerator()&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; GetEnumerator();&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;Note that we assume that the assignment &lt;em&gt;Action&amp;lt;string[], T&amp;gt; &lt;/em&gt;is handed in when the reader is created.&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="76"&gt;
        &lt;p&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" alt="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067865-3d-glossy-blue-orb-icon-alphanumeric-exclamation-point1.png" width="64" height="64" /&gt;&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="724"&gt;
        &lt;p&gt;The really critical piece here is creating (via &lt;em&gt;GetStream&lt;/em&gt;()) and disposing of (via the &lt;em&gt;using &lt;/em&gt;statement) of our underlying file resources each time (which required that the resource management code – opening and closing files – be merged with the resource using code).&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;That’s it – now that we have our IEnumerable&amp;lt;T&amp;gt; wrapped up in a class that can close out the underlying file stream on &lt;em&gt;Dispose&lt;/em&gt;(), we are ready to wrap it up in a LINQPad data context.&lt;/p&gt;

&lt;h3&gt;Creating a LINQPad data context which exposes the data set as a CepStream&amp;lt;&amp;gt;&lt;/h3&gt;

&lt;p&gt;Creating the custom data context will be the shortest section of this blog post &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-38-83-metablogapi/1134.wlEmoticon_2D00_smile_5F00_19A3BE24.png" /&gt;.&amp;#160; With a data source (either an IEnumerable&amp;lt;T&amp;gt;, IObservable&amp;lt;T&amp;gt; or a StreamInsight adapter) ready to go, all that stands between you and LINQPad data context goodness is exposing the CepStream&amp;lt;T&amp;gt; object in a class.&lt;/p&gt;

&lt;p&gt;Really – that’s it.&amp;#160; Here are the steps:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Create a class that derives from StreamInsight Context. 
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;StreamInsightContext &lt;/strong&gt;is defined in &lt;strong&gt;StreamInsightLinqPad.Samples.dll&lt;/strong&gt;, which is typically found in &lt;em&gt;C:\ProgramData\LINQPad\Drivers\DataContext\4.0\StreamInsightLinqPad (3d3a4b0768c9178e)&lt;/em&gt; &lt;/li&gt;

      &lt;li&gt;Expose the two streams (weather data and station data), based on the code we explored in the reading back the canned data section). &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or, to look at the code:&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:f4bf51f9-b893-4095-acf4-1ed8630755ec" 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: #ddd; overflow: auto"&gt;
&lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; 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;WeatherContext&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;StreamInsightContext&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:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; weatherFile;&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;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; stationFile;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; WeatherContext()&lt;/li&gt;
&lt;li&gt;    {&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// Look for the data files in the same directory as this assembly&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;        &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; assemblyDir = &lt;span style="color:#2b91af"&gt;Path&lt;/span&gt;.GetDirectoryName(&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;Assembly&lt;/span&gt;.GetExecutingAssembly().Location);&lt;/li&gt;
&lt;li&gt;        weatherFile = &lt;span style="color:#2b91af"&gt;Path&lt;/span&gt;.Combine(assemblyDir, &lt;span style="color:#a31515"&gt;@&amp;quot;weather_data_out.csv.gz&amp;quot;&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        stationFile = &lt;span style="color:#2b91af"&gt;Path&lt;/span&gt;.Combine(assemblyDir, &lt;span style="color:#a31515"&gt;@&amp;quot;station_data_out.csv.gz&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;public&lt;/span&gt; WeatherContext(&lt;span style="color:#2b91af"&gt;Server&lt;/span&gt; server)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;        : &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;(server)&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;CepStream&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;WeatherReading&lt;/span&gt;&amp;gt; SmallWeather&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;/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:#2b91af"&gt;CsvSequenceReaderTyped&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;WeatherReading&lt;/span&gt;&amp;gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                (weatherFile, &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;WeatherReading&lt;/span&gt;.GetFill()).Take(50)&lt;/li&gt;
&lt;li&gt;                    .ToStream(Application, &lt;span style="color:#2b91af"&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime);&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;CepStream&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;WeatherReading&lt;/span&gt;&amp;gt; LargeWeather&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;/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:#2b91af"&gt;CsvSequenceReaderTyped&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;WeatherReading&lt;/span&gt;&amp;gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                (weatherFile, &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;WeatherReading&lt;/span&gt;.GetFill())&lt;/li&gt;
&lt;li&gt;                .ToStream(Application, &lt;span style="color:#2b91af"&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime);&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;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;CepStream&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;StationData&lt;/span&gt;&amp;gt; Stations&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;/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:#2b91af"&gt;CsvSequenceReaderTyped&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;StationData&lt;/span&gt;&amp;gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                (stationFile, &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;StationData&lt;/span&gt;.GetFill())&lt;/li&gt;
&lt;li&gt;                    .ToStream(Application, &lt;span style="color:#2b91af"&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;                    .AlterEventLifetime(e =&amp;gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;(2000, 1, 1, 0, 0, 0, &lt;span style="color:#2b91af"&gt;DateTimeKind&lt;/span&gt;.Utc),&lt;/li&gt;
&lt;li&gt;                        e =&amp;gt; &lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.MaxValue);&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;There are a few changes from the last section, to clean things up a bit in a project:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The assignment functions are returned by static functions on the data types themselves (as opposed to public properties – didn’t want to have a non-StreamInsight compatible data type in the event type definitions). &lt;/li&gt;

  &lt;li&gt;Instead of raising a generic wrapper class and then converting into PointEvent&amp;lt;T&amp;gt;, we instead raise TypedEvent&amp;lt;T&amp;gt; directly from the file (i.e. our enumerator is now &lt;em&gt;IEnumerator&amp;lt;&lt;strong&gt;IntervalEvent&lt;/strong&gt;&amp;lt;T&amp;gt;&amp;gt; GetEnumerator()&lt;/em&gt;.&amp;#160; &lt;/li&gt;

  &lt;li&gt;The file names are inferred to be in the same directory as the context assembly. &lt;/li&gt;

  &lt;li&gt;In the &lt;strong&gt;Stations &lt;/strong&gt;stream, we perform an AlterEventLifetime to convert the list of stations into a reference stream by extending the time from January 1st 2000 (the timestamp of the first record in the data set), to max time. 

    &lt;ul&gt;
      &lt;li&gt;Ordinarily, this would be done with query logic in your application, but for ease of use in LINQPad (i.e. removing an extra step) I did it in the context. &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go ahead and compile the project, to obtain the WeatherData.LinqpadContext.dll.&amp;#160; We’ll load this into LINQPad by &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Add Connection&lt;/strong&gt;, then select &lt;strong&gt;Microsoft StreamInsight &lt;/strong&gt;from the list of drivers. &lt;/li&gt;

  &lt;li&gt;Select &lt;em&gt;Custom Context &lt;/em&gt;from the &lt;strong&gt;Context Kind &lt;/strong&gt;dropdown. &lt;/li&gt;

  &lt;li&gt;Click on the ellipsis for Assembly Path (...), then browse to the directory containing &lt;em&gt;WeatherData.LinqpadContext.dll&lt;/em&gt;. &lt;/li&gt;

  &lt;li&gt;Click &lt;strong&gt;OK &lt;/strong&gt;to finish selecting the new context. &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-38-83-metablogapi/5270.image_5F00_130CEC3C.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/7357.image_5F00_thumb_5F00_7E3AF3BB.png" width="462" height="304" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="76"&gt;
        &lt;p&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" alt="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067865-3d-glossy-blue-orb-icon-alphanumeric-exclamation-point1.png" width="64" height="64" /&gt;&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="724"&gt;
        &lt;p&gt;Our weather context should now be available on the connections list.&amp;#160; Before we can start querying these streams, we will need to take our data files (&lt;strong&gt;weather_data_out.csv.gz&lt;/strong&gt; and &lt;strong&gt;station_data_out.csv.gz &lt;/strong&gt;from our first step) and copy them to the assembly directory (in this case, the bin directory for our project).&lt;/p&gt;

        &lt;p&gt;If you’re not sure which directory you need to place the files in, simply run a query against the data context.&amp;#160; The exception will show you the correct directory.&amp;#160; &lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Now that we have our custom context ready to go, let’s run some queries.&lt;/p&gt;

&lt;h3&gt;Running some Queries&lt;/h3&gt;

&lt;p&gt;With the query context loaded up, let’s go ahead and run some queries against it.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;From LINQPad, click &lt;strong&gt;File&lt;/strong&gt;, &lt;strong&gt;New Query&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;From the Language drop-down, select &lt;strong&gt;C# Statements&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;From the Database drop-down, select &lt;strong&gt;StreamInsight: WeatherContext&lt;/strong&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-38-83-metablogapi/3343.image_5F00_096757E7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/7585.image_5F00_thumb_5F00_65EAB381.png" width="828" height="219" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we’re ready to run some queries.&amp;#160; Let’s start with a couple of basic one to look at the &lt;strong&gt;SmallWeather &lt;/strong&gt;and &lt;strong&gt;Stations &lt;/strong&gt;streams.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3365.image_5F00_3C27388E.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/0825.image_5F00_thumb_5F00_1263BD9B.png" width="783" height="513" /&gt;&lt;/a&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-38-83-metablogapi/0654.image_5F00_4ECC0C78.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/7674.image_5F00_thumb_5F00_52F5E43D.png" width="855" height="565" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;

&lt;p&gt;Excellent!&amp;#160; One last little query to close out our walkthrough of creating a data context – join the reference stream with the small data stream and filter for a specific airport.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7607.image_5F00_1D307916.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; 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-38-83-metablogapi/4370.image_5F00_thumb_5F00_3A562120.png" width="557" height="729" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="76"&gt;
        &lt;p&gt;&lt;img title="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" alt="3d Glossy Blue Orbs Alphanumeric Lucinda Exclamation Point Icon" src="http://icons.mysitemyway.com/wp-content/gallery/3d-glossy-blue-orbs-icons-alphanumeric/thumbs/thumbs_067865-3d-glossy-blue-orb-icon-alphanumeric-exclamation-point1.png" width="64" height="64" /&gt;&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="724"&gt;
        &lt;p&gt;Remember – you can execute just the selected text in LINQPad by highlighting it, then pressing &lt;strong&gt;F5 &lt;/strong&gt;(or clicking &lt;strong&gt;Query &lt;/strong&gt;–&amp;gt; &lt;strong&gt;Execute&lt;/strong&gt;), which is why all of the screenshots show highlighted text.&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111828" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/StreamInsight/">StreamInsight</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/LINQ/">LINQ</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/LINQPad/">LINQPad</category></item><item><title>Running ActiveMQ on Windows Azure: One Man’s Search for a Full Featured Messaging Broker Option in the Cloud</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/21/running-activemq-on-azure-one-man-s-search-for-a-full-featured-messaging-broker-option-in-the-cloud.aspx</link><pubDate>Tue, 21 Dec 2010 20:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10107834</guid><dc:creator>Christian.Martinez</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10107834</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10107834</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/21/running-activemq-on-azure-one-man-s-search-for-a-full-featured-messaging-broker-option-in-the-cloud.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve always enjoyed building systems that utilized flexible messaging platforms. Before joining Microsoft, I was a member of a small ISV team that built a commercial .NET based ESB product (a rare creature in and of itself) that was&amp;nbsp;primarily a WCF based messaging system. We had a number of capabilities that were useful and somewhat unique in their execution but one of my favorites was the ability to provide transactional messaging across multiple platforms by leveraging &lt;a href="http://activemq.apache.org/"&gt;ActiveMQ&lt;/a&gt; in our adapter model. &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve always admired the Apache folks. More often than not they seem to just get it (unless you&amp;rsquo;re talking about docs &amp;hellip; but hey their stuff is free and even us ginormous mega power companies screw the pooch on docs sometimes). And ActiveMQ is no exception. It has pretty much&amp;nbsp; all of the capabilities you&amp;rsquo;d expect from a full featured broker including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://activemq.apache.org/cross-language-clients.html"&gt;Multiple Protocol and Language Support&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html"&gt;Modular and Embeddable Design&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://activemq.apache.org/clustering.html"&gt;Numerous scale out and HA configurations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://activemq.apache.org/persistence.html"&gt;Configurable Quality of Service including Multiple Persistence Options&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://activemq.apache.org/web-console.html"&gt;A Web Console&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The list goes on. But you get it. It&amp;rsquo;s an actual message broker with tons of features, the most important of which is its .NET support via the &lt;a href="http://activemq.apache.org/nms/"&gt;.NET Messaging API&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s only one problem. ActiveMQ like pretty much every other messaging broker was developed pre-cloud. Granted, some of the AMQP brokers such as &lt;a href="http://www.rabbitmq.com/"&gt;RabbitMQ&lt;/a&gt; have caught on with folks who make all of their money &amp;ldquo;off prem&amp;rdquo; but none of the brokers I&amp;rsquo;ve worked with are what I would call cloud friendly. Maybe there&amp;rsquo;s one out there and if there is please add a comment because I&amp;rsquo;d love to check it out.&lt;/p&gt;
&lt;p&gt;So where does that leave us? Well if you&amp;rsquo;re just trying to get some things done in Windows Azure between roles and instances and you don&amp;rsquo;t need a full featured broker, stop right now and run to go see my colleague Valery Mizonov&amp;rsquo;s &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/20/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based-messaging-solutions-on-windows-azure.aspx"&gt;incredible blog&lt;/a&gt; about rolling your own. It&amp;rsquo;s the best thing I&amp;rsquo;ve seen on the subject and it was derived from real folks working on real challenges while deploying on Windows Azure. Valery is a genius though and he was built based on the design of the Cyberyne Systems Model 101 so it&amp;rsquo;s not a surprise that he was able to achieve such a masterpiece of engineering and bloggery.&lt;/p&gt;
&lt;p&gt;If on the other hand you&amp;rsquo;re a simpler life form like me and feel a certain shall we say irritation that 58 billion in revenue and 14 billion in profit occurred without something more &amp;ldquo;out of the box&amp;rdquo; in the cloud for us messaging lovers then read on.&amp;nbsp; But first, a warning:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;"&gt;&lt;strong&gt;WHAT YOU ARE ABOUT TO READ IS NOT IN ANY WAY A &amp;ldquo;BEST PRACTICE&amp;rdquo; OR EVEN SOMETHING NORMAL PEOPLE MIGHT TRY. IT IS AN ENVELOPE PUSHING EXERCISE THAT TURNED OUT PRETTY COOL AND LEFT ME WITH AN APPRECIATION OF THE POWER OF THE WINDOWS AZURE WORKER ROLE AND CONFIRMED MY APPRECIATION OF ACTIVEMQ.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now, that the warning is out of the way let&amp;rsquo;s begin the journey&amp;hellip;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Step 1: Figure Out How To Develop&lt;/h1&gt;
&lt;p&gt;I&amp;rsquo;d seen the posts on running Tomcat in Windows Azure and downloaded the &lt;a href="http://code.msdn.microsoft.com/winazuretomcat"&gt;Tomcat Accelerator&lt;/a&gt;. It gave me hope that what I wanted to do was possible. For what I wanted to do however, I wanted a more &amp;ldquo;integrated&amp;rdquo; experience than all of the cmd files in that project not to mention wanting to avoid having to build my own,. &lt;/p&gt;
&lt;p&gt;So, I decided to use the technique I had used long ago as a Java Developer dealing with classpaths and a bazillion jar files: sheer brute force.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8585.image_5F00_7EFCA3CD.png"&gt;&lt;img height="398" width="282" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7870.image_5F00_thumb_5F00_3F8ECA70.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, that is really is a JRE and ActiveMQ embedded with the files set to be copied into the project. It took a few monotonous minutes to set up but it was well worth it in the long run.&lt;/p&gt;
&lt;h1&gt;Step 2: Figure Out How Deal With Local Storage and Dynamic IP&amp;rsquo;s&lt;/h1&gt;
&lt;p&gt;Anyone who has spent time with Azure knows they need to deal with the rules of Local Storage and the way endpoints are assigned. When you&amp;rsquo;re dealing with something like starting a JVM and running something like ActiveMQ that has a lot of startup options&amp;nbsp;then things get even more harrowing. &lt;/p&gt;
&lt;p&gt;My first goal was then figuring out to get all the things I needed over to the Local Storage and to edit the config files so that when ActiveMQ started up the dynamically assigned ports were used. &lt;/p&gt;
&lt;p&gt;This problem is ugly no matter how you slice it (the tomcat example I downloaded had robocopy in a .bat) but after I was done I didn&amp;rsquo;t feel too bad. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt; private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ConfigureDirectories()
 {
            workingDir = Environment.GetEnvironmentVariable(&lt;span class="str"&gt;"RoleRoot"&lt;/span&gt;) + &lt;span class="str"&gt;@"\approot"&lt;/span&gt;;
            javaHome = workingDir + &lt;span class="str"&gt;@"\jre6"&lt;/span&gt;;
            var activeMqFiles = workingDir + &lt;span class="str"&gt;@"\activemq"&lt;/span&gt;;
            runtimeDir = RoleEnvironment.GetLocalResource(&lt;span class="str"&gt;"Storage"&lt;/span&gt;).RootPath + &lt;span class="str"&gt;"activemq"&lt;/span&gt;;
            Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(activeMqFiles, runtimeDir, &lt;span class="kwrd"&gt;true&lt;/span&gt;);
  }&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;
&lt;h1&gt;&amp;nbsp;&lt;/h1&gt;
&lt;p&gt;The awesomeness of the CLR shows up here as I leverage VB.NET for a little recursive copy assist.&lt;/p&gt;
&lt;p&gt;Once everything was copied over then it was just a matter of setting up the environment and writing the IP&amp;rsquo;s to the respective config files&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ConfigureEnvironment(Process proc)
{
            proc.StartInfo.EnvironmentVariables.Remove(&lt;span class="str"&gt;"JAVA_HOME"&lt;/span&gt;);
            proc.StartInfo.EnvironmentVariables.Remove(&lt;span class="str"&gt;"ACTIVEMQ_HOME"&lt;/span&gt;);
            proc.StartInfo.EnvironmentVariables.Add(&lt;span class="str"&gt;"JAVA_HOME"&lt;/span&gt;, javaHome);
            proc.StartInfo.EnvironmentVariables.Add(&lt;span class="str"&gt;"ACTIVEMQ_HOME"&lt;/span&gt;, runtimeDir);
            ManipulateIpAdresses();
 }&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;
&lt;h1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/h1&gt;
&lt;p&gt;The rest of the set up is just Xpath boiler plate and &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx"&gt;Process&lt;/a&gt; set up so I won&amp;rsquo;t go into it here. One note, as of SDK 1.3 you have more options re: pinning the IP.&lt;/p&gt;
&lt;p&gt;The important thing is after this part was done I had a broker firing up in dev fabric!&lt;/p&gt;
&lt;h1&gt;Step 3: Writing the Demo Code &lt;/h1&gt;
&lt;p&gt;This part was the easiest because the Apache guys have pretty much written everything hard which at the end of the day was the reason for trying to do this in the first place. I also wanted to try and use the durable and guaranteed features of ActiveMQ because there are already plenty of non durable, non guaranteed, multiple delivery options available without going to the pain of installing a 3rd part message broker. &lt;/p&gt;
&lt;p&gt;My producer used the following simple driver logic and ran in one instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;                    AttemptConnection();
                    &lt;span class="kwrd"&gt;using&lt;/span&gt; (var &lt;a href="http://activemq.apache.org/nms/ndoc/ActiveMQ.SessionMembers.html"&gt;session&lt;/a&gt; = &lt;a href="http://activemq.apache.org/nms/ndoc/ActiveMQ.ConnectionMembers.html"&gt;con&lt;/a&gt;.CreateSession(AcknowledgementMode.Transactional))
                    {
                        ITopic topic = session.GetTopic(&lt;span class="str"&gt;"AzureHostedTest"&lt;/span&gt;);
                        var &lt;a href="http://activemq.apache.org/nms/ndoc/ActiveMQ.MessageProducerMembers.html"&gt;producer&lt;/a&gt; = session.CreateProducer(topic);
                        var start = DateTime.Now;
                        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; messageCount; i++)
                        {
                            ITextMessage msg = producer.CreateTextMessage(&lt;span class="str"&gt;"Hello world "&lt;/span&gt;+ msgNumber++);
                            producer.Send(msg);
                        }
                        session.Commit();
                        Thread.Sleep(sleepTime);
                    }&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I just used the NMS libraries directly and didn&amp;rsquo;t use any of the &lt;a href="http://www.springsource.org/"&gt;Spring&lt;/a&gt; overlays. &lt;/p&gt;
&lt;p&gt;My consumer logic was similarly simple
&lt;pre class="csharpcode"&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; var topic = &lt;span class="kwrd"&gt;new&lt;/span&gt; ActiveMQTopic(&lt;span class="str"&gt;"AzureHostedTest"&lt;/span&gt;);
                        var mySession = session.CreateDurableConsumer(topic, con.ClientId, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
                        mySession.Listener += (message) =&amp;gt; {
                            ITextMessage msg = message &lt;span class="kwrd"&gt;as&lt;/span&gt; ITextMessage;
                            Trace.WriteLine(message.NMSMessageId + &lt;span class="str"&gt;" "&lt;/span&gt; + msg.Text);
                            session.Commit();
                        };&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/pre&gt;

&lt;/p&gt;
&lt;p&gt;Again, what I was aiming for was the durable options not perf. Like everything else with the product you have a ton of &lt;a href="http://activemq.apache.org/performance.html"&gt;options&lt;/a&gt; in terms of perf tuning. &lt;/p&gt;
&lt;p&gt;Much of the logic in the solution was concerned with attaining a connection. In a cloud world you need to be very concerned with things spinning up out of order or disappearing.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Ok. What are the odds of this running at this point. Pretty good actually, provided you wanted to use Local Storage as your durability option. &lt;/p&gt;
&lt;p&gt;But we all know that&amp;rsquo;s just crazy. Nope you need something enterprise. Something serious. You need SQL Azure!&lt;/p&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;Step 4: Fighting Through the Topology Deployment Options &lt;/h1&gt;
&lt;p&gt;Once again ActiveMQ shines here in the features and flexibility department. However, this was also the part of the project where I knew the path that led me from being a pure open source guy to working for the evil empire was not out of naked greed or any malicious desire but was instead the need to get something @#$#$%#$$%^$ done! We have a lot of great products that let you actually do stuff. Sometimes the other nerd ecosystems out there seem to place productivity a distant second to coolness or &amp;ldquo;elegance&amp;rdquo; or their consultant friendly version of &amp;ldquo;enterprise&amp;rdquo; which results in a miserable experience for anyone outside of the tiny of circle of wonder nerds who grok/exploit their systems and style.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Oh, it looks like an innocuous enough exercise if you read &lt;a href="http://activemq.apache.org/jdbc-support.html"&gt;this&lt;/a&gt; or &lt;a href="http://activemq.apache.org/sqlserver.html"&gt;this&lt;/a&gt; except for the pesky fact that if you use those pages as a guide with the latest ActiveMQ bits and the latest SQL Server JDBC drivers your chances of it working are nothing. Thus, I put myself&amp;nbsp;into the mindset I use to live in 24/7&amp;nbsp;back in the old days and started to dig my way through bug lists and blogs and forums and experimentation until finally eureka! Or as I tend to think of it now &lt;em&gt;for #$%#$%#$ sake&lt;/em&gt;!&lt;/p&gt;
&lt;p&gt;Before sharing the tricks and tidbits however, let&amp;rsquo;s take a short break to describe the deployment I planned on. The topology I chose to deploy was what ActiveMQ calls &lt;a href="http://activemq.apache.org/jdbc-master-slave.html"&gt;JDBC Master Slave&lt;/a&gt;. This topology uses a sophisticated algorithm that basically says if I get the lock first then I&amp;rsquo;m the Master otherwise you are. I know I know. I should back off the rocket science a little bit here and make things a little easier to understand by means of a&amp;nbsp;salient and powerful diagram!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3683.image_5F00_63A3FF32.png"&gt;&lt;img height="195" width="459" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7180.image_5F00_thumb_5F00_6BF7AEBC.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My favorite part of this choice was this quote &lt;/p&gt;
&lt;p&gt;&amp;ldquo;&lt;span style="font-size: xx-small;"&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;By default if you use the &amp;lt;jdbcPersistenceAdapter/&amp;gt; to avoid the high performance journal you will be using JDBC Master Slave by default. You just need to run more than one broker and point the client side URIs to them to get master/slave. This works because they both try an acquire an exclusive lock on a shared table in the database and only one will succeed&lt;/strong&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Heck, it practically springs off the page as the right option. Now, before I go on I would be remiss if I didn&amp;rsquo;t mention the &amp;ldquo;high performance journal&amp;rdquo; referred to in the quote. In order to take advantage of them in Windows Azure however, you&amp;rsquo;re going to have to likely use a complex topology that works around the limitations of Windows Azure Drives and multiple instances. That&amp;rsquo;s the kind of thing done in our team&amp;rsquo;s Design Wins program though and is beyond the scope of this effort. &lt;/p&gt;
&lt;p&gt;Besides, doing it this way you can use SQL Azure (of course in true open source fashion you &lt;em&gt;could&lt;/em&gt; combine journals and JDBC..all you have to do is get through the docs etc &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4353.wlEmoticon_2D00_smile_5F00_66E54B40.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" /&gt;&amp;nbsp;). &lt;/p&gt;
&lt;p&gt;SQL Azure is an oasis of comfort and predictability in an otherwise turbulent world. It&amp;rsquo;s your solid and reliable friend in a cloud universe where we&amp;rsquo;re told that you might as well throw state out the window, abandon the thought of any guarantees and make everything idempotent because&amp;hellip; well things are just going to happen in a way you don&amp;rsquo;t want them to &amp;hellip;.so you need to be prepared. Granted, there&amp;rsquo;s some folks who have said&amp;nbsp;people developing distributed systems should have been doing that all along even&amp;nbsp;when they used on&amp;nbsp;premises technologies, but just because they were right doesn&amp;rsquo;t mean we should have listened to them!&lt;/p&gt;
&lt;p&gt;Now onto the secrets. After downloading the latest &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a737000d-68d0-4531-b65d-da0f2a735707&amp;amp;displaylang=en"&gt;JDBC drivers&lt;/a&gt; I promptly waded through the xml docs and arrived at the following for my JDBC related settings:&lt;/p&gt;
&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;persistenceAdapter&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;jdbcPersistenceAdapter&lt;/span&gt; &lt;span class="attr"&gt;createTablesOnStartup&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;  &lt;span class="attr"&gt;dataDirectory&lt;/span&gt;&lt;span class="kwrd"&gt;="${activemq.base}/data"&lt;/span&gt; &lt;span class="attr"&gt;dataSource&lt;/span&gt;&lt;span class="kwrd"&gt;="#mssql-ds"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;persistenceAdapter&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bean&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="mssql-ds"&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="org.apache.commons.dbcp.BasicDataSource"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="driverClassName"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="com.microsoft.sqlserver.jdbc.SQLServerDriver"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="url"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="jdbc:sqlserver://[replace].database.windows.net;databaseName=ActiveMQ;"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="username"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="[replace]@[replace].database.windows.net"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="password"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="[replace]"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="maxActive"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="200"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="poolPreparedStatements"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="true"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bean&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;

I set createTablesOnStartup to true initially then false after they were created which seemed logical. Once you get past the unintuitive choice of class for datasource that&amp;rsquo;s not so bad. Unfortunately,when you start ActiveMQ&amp;nbsp;that won&amp;rsquo;t work because you&amp;rsquo;ll run into bug similar to &lt;a href="https://issues.apache.org/jira/browse/AMQ-2496"&gt;this one&lt;/a&gt; but with the added fun that the recommendations on the page don&amp;rsquo;t work for the 5.4.2 broker. &lt;/p&gt;
&lt;p&gt;The answer to the issue is hinted at in this &lt;a href="https://issues.apache.org/jira/browse/AMQ-1109"&gt;bug report&lt;/a&gt;. I&amp;rsquo;ll leave finding the hint to you gentle reader and skip right to its actual implementation because the hint will not help in isolation. You would need to carefully read the resulting stack trace after applying the hint and pair it with the knowledge gleaned to fully get the answer.&lt;/p&gt;
&lt;p&gt;Here it is in a nutshell courtesy of &lt;a href="http://www.7-zip.org/"&gt;7-zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&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-38-83-metablogapi/7506.image_5F00_546CD4BE.png"&gt;&lt;img height="325" width="489" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1122.image_5F00_thumb_5F00_5C545153.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0045.image_5F00_7B86D259.png"&gt;&lt;img height="164" width="473" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3362.image_5F00_thumb_5F00_675D9003.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;See those files that are named slightly different than the ones that have the exact same content inside them&amp;nbsp;as the highlighted ones. That&amp;rsquo;s the key. All&amp;nbsp;you have to do is copy one of the&amp;nbsp;files&amp;nbsp;you need to&amp;nbsp;base&amp;nbsp;your new file&amp;nbsp;on out of the&amp;nbsp;jar,&amp;nbsp;rename it&amp;nbsp;using a slightly different convention,&amp;nbsp;then stuff the renamed files&amp;nbsp;back into the jar and away you go! What could be more natural?&lt;/p&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Step 5: Deploy and Savor the Payoff&lt;/h1&gt;
&lt;p&gt;Once all the above was figured out all that was left was to grow a tree from an acorn while I waited for the project to upload to Windows&amp;nbsp;Azure. Once it landed I monitored things with SSMS and a simple query&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0121.image_5F00_091942C8.png"&gt;&lt;img height="357" width="578" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6318.image_5F00_thumb_5F00_72967E73.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then I got real brave and decided to cycle instance 0. Sure enough the pause in activity told me it was the master. When things picked up again after a few seconds I knew that the scruffy demo code had actually worked with failover. After that I forget because of the tears and the bourbon.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14703"&gt; the code&lt;/a&gt; (be warned it&amp;rsquo;s fairly large because of the embedding).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Special thanks to Steve Marx, Paolo Salvatori and James Podgorski for their feedback and review.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10107834" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Azure/">Azure</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Windows+Azure/">Windows Azure</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/how+to/">how to</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/SQL+Azure/">SQL Azure</category></item><item><title>Best Practices for Maximizing Scalability and Cost Effectiveness of Queue-Based Messaging Solutions on Windows Azure</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/20/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based-messaging-solutions-on-windows-azure.aspx</link><pubDate>Mon, 20 Dec 2010 08:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10094033</guid><dc:creator>Valery M</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10094033</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10094033</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/20/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based-messaging-solutions-on-windows-azure.aspx#comments</comments><description>&lt;p align="justify"&gt;This post has been moved to a new location. Please follow the link below. Thank you.&lt;/p&gt;
&lt;p align="justify"&gt;&lt;a href="http://windowsazurecat.com/2010/12/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based-messaging-solutions-on-windows-azure/"&gt;http://windowsazurecat.com/2010/12/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based-messaging-solutions-on-windows-azure/&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=10094033" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Best+Practices/">Best Practices</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Windows+Azure/">Windows Azure</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric+Service+Bus/">AppFabric Service Bus</category></item><item><title>How to use Duplex MEP to communicate with BizTalk from a .NET application or a WF workflow running inside AppFabric Part 2</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/15/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-2.aspx</link><pubDate>Wed, 15 Dec 2010 05:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10104176</guid><dc:creator>Paolo Salvatori</dc:creator><slash:comments>0</slash:comments><description>&lt;h3 align="justify"&gt;Introduction&lt;/h3&gt;  &lt;p align="justify"&gt;In the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/11/23/how-using-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-1.aspx"&gt;first article&lt;/a&gt; of the series we discussed how to exchange messages with an orchestration via a two-way WCF Receive Location using the &lt;a href="http://msdn.microsoft.com/en-us/library/ms731184.aspx"&gt;Duplex Message Exchange Pattern&lt;/a&gt;. This form of bi-directional communication is characterized by the ability of both the service and the client to send messages to each other independently either using one-way or request/reply messaging. In a service-oriented architecture or a service bus composed of multiple, heterogeneous systems, interactions between autonomous client and service applications are asynchronous and loosely-coupled. All communications require published and discoverable service contracts, well-known data formats and a shared communication infrastructure. In this context, the use of asynchronous message patterns allows to increase the agility, scalability and flexibility of the overall architecture and helps decreasing the loose coupling of individual systems. In the second part of the article&amp;#160; I’ll show you how to implement an asynchronous communication between a client application and a &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx"&gt;WCF Workflow Service&lt;/a&gt; running within IIS\&lt;a href="http://msdn.microsoft.com/en-us/rampup/gg296345.aspx"&gt;AppFabric Hosting Services&lt;/a&gt; using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt; provided by WF 4.0. Besides, I’ll demonstrate how to create a custom Activity for extending &lt;strong&gt;AppFabric Tracking&lt;/strong&gt; with user-defined events and how to exploit the XML-based data transformation capabilities provided by the new &lt;a href="http://blogs.msdn.com/b/biztalk_server_team_blog/archive/2010/08/24/improved-productivity-with-biztalk-server-2010-mapper.aspx"&gt;BizTalk Server Mapper&lt;/a&gt; directly in a WF project thanks to the new &lt;strong&gt;Mapper&lt;/strong&gt; Activity contained in the &lt;a href="http://www.microsoft.com/biztalk/en/us/appfabricconnect.aspx"&gt;AppFabric Connect&lt;/a&gt;. The latter combines rich proven features of &lt;strong&gt;BizTalk Server 2010&lt;/strong&gt; with the flexible development experience of .NET to allow users to easily develop simple integration applications. Besides, AppFabric Connect allows you to extend the reach of your on-premise applications and services into &lt;strong&gt;Windows Azure AppFabric&lt;/strong&gt;. In the future I’ll show you how to get advantage of the functionality offered by the &lt;strong&gt;AppFabric Connect&lt;/strong&gt; to expose or move your BizTalk applications to the cloud using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee732537.aspx"&gt;Windows Azure AppFabric Service Bus&lt;/a&gt;. If you are interested in this subject, you can read the following articles:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://blogs.msdn.com/b/biztalk_server_team_blog/archive/2010/06/10/biztalk-appfabric-an-introduction.aspx"&gt;BizTalk AppFabric Connect: An Introduction&lt;/a&gt;&amp;quot; on the BizTalk Server Team Blog.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/working-with-biztalk-appfabric-connect.aspx"&gt;“Introducing BizTalk Server 2010 AppFabric Connect&lt;/a&gt;” article on TechNet.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/exposing-biztalk-applications-on-the-cloud-using-appfabric-connect-for-services.aspx"&gt;Exposing BizTalk Applications on the Cloud using AppFabric Connect for Services&lt;/a&gt;&amp;quot; article on TechNet.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&amp;quot;&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/exposing-lob-services-on-the-cloud-using-appfabric-connect-for-services.aspx"&gt;Exposing LOB Services on the Cloud Using AppFabric Connect for Services&lt;/a&gt;&amp;quot; article on TechNet&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;Before explaining the architecture of the demo, let me briefly introduce and discuss some of the techniques that I used to implement my solution.&lt;/p&gt;  &lt;h3 align="justify"&gt;Correlation in WF 4.0&lt;/h3&gt;  &lt;p align="justify"&gt;If you are a WF or a BizTalk developer, you are surely familiar with the concept of correlation. Typically, at runtime workflows or orchestrations have multiple instances executing simultaneously. Therefore, when a workflow service implements an asynchronous communication pattern to exchange messages with other services, correlation provides the mechanism to ensure that messages are sent to the appropriate workflow instance. &lt;a href="http://msdn.microsoft.com/en-us/library/dd456784.aspx"&gt;Correlation&lt;/a&gt; enables relating workflow service messages to each other or to the application instance state, such as a reply to an initial request, or a particular order ID to the persisted state of an order-processing workflow. Workflow Foundation 4.0 provides 2 different categories of correlation called, respectively, &lt;strong&gt;Protocol-Based Correlation&lt;/strong&gt; and &lt;strong&gt;Content-Based Correlation&lt;/strong&gt;. Protocol-based correlations use data provided by the message delivery infrastructure to provide the mapping between messages. Messages that are correlated using protocol-based correlation are related to each other using an object in memory, such as a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.requestcontext.aspx"&gt;RequestContext&lt;/a&gt;, or by a token provided by the transport protocol. Content-based correlations relate messages to each other using application-specified data. Messages that are correlated using content-based correlation are related to each other by some application-defined data in the message, such as a customer number. &lt;/p&gt;  &lt;h4 align="justify"&gt;Protocol-Based Correlation&lt;/h4&gt;  &lt;p align="justify"&gt;Protocol-based correlation uses the transport mechanism to relate messages to each other and the appropriate workflow instance. Some system-provided protocol correlation mechanisms include &lt;a href="http://msdn.microsoft.com/en-us/library/ee358750.aspx"&gt;Request-Reply&lt;/a&gt; correlation and &lt;a href="http://msdn.microsoft.com/en-us/library/ee358724.aspx"&gt;Context-Based&lt;/a&gt; correlation. A Request-Reply correlation is used to correlate a single pair of messaging activities to form a two-way synchronous inbound or outbound operation, such as a &lt;strong&gt;Send&lt;/strong&gt; paired with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receivereply.aspx"&gt;ReceiveReply&lt;/a&gt;, or a &lt;strong&gt;Receive&lt;/strong&gt; paired with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.sendreply.aspx"&gt;SendReply&lt;/a&gt;. The Visual Studio 2010 Workflow Designer also provides a set of activity templates to quickly implement this pattern. A context-based correlation is based on the context exchange mechanism described in the &lt;a href="http://go.microsoft.com/fwlink/?LinkID=166059"&gt;.NET Context Exchange Protocol Specification&lt;/a&gt;. To use context-based correlation, a context-based binding such as &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpcontextbinding.aspx"&gt;BasicHttpContextBinding&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpcontextbinding.aspx"&gt;WSHttpContextBinding&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpcontextbinding.aspx"&gt;NetTcpContextBinding&lt;/a&gt; must be used on the endpoint. &lt;/p&gt;  &lt;p align="justify"&gt;For more information about protocol correlation, see the following topics on MSDN:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee358724.aspx"&gt;Context Exchange Correlation&lt;/a&gt; &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee358750.aspx"&gt;Request-Reply Correlation&lt;/a&gt;&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;For more information about using the Visual Studio 2010 Workflow Designer activity templates, see &lt;a href="http://msdn.microsoft.com/en-us/library/ee358739.aspx"&gt;Messaging Activities&lt;/a&gt;. For sample code, see the &lt;a href="http://msdn.microsoft.com/en-us/library/ee662960.aspx"&gt;Durable Duplex&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ee662963.aspx"&gt;NetContextExchangeCorrelation&lt;/a&gt; samples.&lt;/p&gt;  &lt;h4 align="justify"&gt;Content-Based Correlation&lt;/h4&gt;  &lt;p align="justify"&gt;Content-based correlation uses data in the message to associate it to a particular workflow instance. Unlike protocol-based correlation, content-based correlation requires the application developer to explicitly state where this data can be found in each related message. Activities that use content-based correlation specify this message data by using a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.messagequeryset.aspx"&gt;MessageQuerySet&lt;/a&gt;. Content-based correlation is useful when communicating with services that do not use one of the context bindings such as &lt;strong&gt;BasicHttpContextBinding&lt;/strong&gt;. For more information about content-based correlation, see &lt;a href="http://msdn.microsoft.com/en-us/library/ee358755.aspx"&gt;Content Based Correlation&lt;/a&gt;. For sample code, see the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/dd807391.aspx"&gt;Correlated Calculator&lt;/a&gt; samples.&lt;/p&gt;  &lt;p align="justify"&gt;In my demo I used 2 different types of protocol-based correlation, respectively, the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358750.aspx"&gt;Request-Reply Correlation&lt;/a&gt; and the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt;. In the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2011/01/20/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-3.aspx"&gt;third part&lt;/a&gt; of this article I’ll show you how to use the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; to implement an asynchronous communication between the WF workflow service and the underlying BizTalk orchestration. &lt;/p&gt;  &lt;h3 align="justify"&gt;AppFabric Monitoring and User-Defined Events&lt;/h3&gt;  &lt;p align="justify"&gt;AppFabric provides new options and tools to monitor and troubleshoot the health of WCF and WF services running on IIS. The monitoring features support centralized event collection and analysis for WCF and WF services running on a single server. The monitoring features include the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;A monitoring infrastructure that collects events from WCF and WF services and stores them in a &lt;strong&gt;Monitoring database&lt;/strong&gt;. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;A Monitoring database schema for instrumentation data. The &lt;strong&gt;Monitoring database&lt;/strong&gt; stores tracked events from WCF and WF services in one unified data store. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;A Windows Service called &lt;strong&gt;AppFabric Event Collection Service&lt;/strong&gt; that, acting as an ETW consumer, collects and stores track events to the AppFabric Monitoring database. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;An &lt;a href="http://msdn.microsoft.com/en-us/library/ee677341.aspx"&gt;ApplicationServer&lt;/a&gt; module for Windows PowerShell that exposes monitoring &lt;strong&gt;cmdlets&lt;/strong&gt; used to manage the Monitoring database and event collector sources.         &lt;br /&gt;An &lt;a href="http://msdn.microsoft.com/en-us/library/ee677341.aspx"&gt;ApplicationServer&lt;/a&gt; module for Windows PowerShell that exposes tracing cmdlets, which you can use to configure tracing profiles, enable or disable tracing, and query trace logs.         &lt;br /&gt;A &lt;strong&gt;Monitoring Dashboard&lt;/strong&gt; and other extensions to the IIS Manager console. You can use the &lt;strong&gt;Monitoring Dashboard&lt;/strong&gt; to view selected metrics from the Monitoring database. You can use the IIS Manager extensions to manage monitoring databases, set the monitoring level, and query and analyze tracked events. &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;In a nutshell, here’s how &lt;strong&gt;AppFabric Monitoring&lt;/strong&gt; works: event data is emitted from WCF and WF services and is sent to a high-performance Event Tracing for Windows (&lt;strong&gt;ETW&lt;/strong&gt;) session. The data sent to an ETW session includes WCF analytic trace events and WF tracking record events emitted by using the ETW Tracking Participant. The &lt;strong&gt;AppFabric Event Collector Service&lt;/strong&gt; harvests this event data from the above ETW session and stores this information in the &lt;strong&gt;Monitoring database&lt;/strong&gt;. AppFabric monitoring tools can be used to analyze these events when they are persisted in the database. The &lt;strong&gt;AppFabric Monitoring&lt;/strong&gt; features are fully documented on MSDN, so I will not cover this subject in detail.&amp;#160; For more information on AppFabric Monitoring and ETW, see the following articles:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee677325.aspx"&gt;Monitoring Architecture&lt;/a&gt;” topic on MSDN.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee677276.aspx"&gt;Monitoring Applications&lt;/a&gt;” topic on MSDN.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee677236.aspx"&gt;Windows Server AppFabric Dashboard Page&lt;/a&gt;” topic on MSDN.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://msdnstage.redmond.corp.microsoft.com/en-us/library/ee513992.aspx"&gt;Workflow Tracking and Tracing&lt;/a&gt;” topic on MSDN.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163437.aspx"&gt;Improve Debugging And Performance Tuning With ETW&lt;/a&gt;” article on MSDN Magazine.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;&lt;strong&gt;AppFabric Monitoring&lt;/strong&gt; and &lt;strong&gt;Windows Workflow Tracking&lt;/strong&gt; provide visibility into workflow execution. They provide the necessary infrastructure to track the execution of a workflow instance. The WF tracking infrastructure transparently instruments a workflow to emit records reflecting key events during the execution. In particular, AppFabric allows to &lt;a href="http://msdn.microsoft.com/en-us/library/ee677267.aspx"&gt;configure&lt;/a&gt;, at a service level, a built-in or custom &lt;a href="http://msdnstage.redmond.corp.microsoft.com/en-us/library/ee513989.aspx"&gt;Tracking Profile&lt;/a&gt; to filter tracked data. Besides, WF provides the infrastructure and components to emit user-defined events to track custom application data. This brings us to the next topic.&lt;/p&gt;  &lt;h3 align="justify"&gt;Custom Activity for tracking User-Defined Events&lt;/h3&gt;  &lt;p align="justify"&gt;While the base activity library includes a rich palette of activities for interacting with services, objects, and collections, it does not provide any activities for tracking user-defined events. Therefore, I decided to create a reusable WF custom activity to track user-defined events within any WF workflow service. This allows me to use the &lt;strong&gt;AppFabric Dashboard&lt;/strong&gt; to analyze user events emitted at runtime by my WF services using my component. WF 4.0 provides a hierarchy of activity base classes from which you can choose from when building a custom activity. At a high level, the four base classes can be described as follows:&amp;#160; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.activity.aspx"&gt;Activity&lt;/a&gt; – used to model activities by composing other activities, usually defined using XAML. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.codeactivity.aspx"&gt;CodeActivity&lt;/a&gt; – a simplified base class when you need to write some code to get work done. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.asynccodeactivity.aspx"&gt;AsyncCodeActivity&lt;/a&gt; – used when your activity perform some work asynchronously. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.nativeactivity.aspx"&gt;NativeActivity&lt;/a&gt; – when your activity needs access to the runtime internals, for example to schedule other activities or create bookmarks &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;For more information on WF and custom activities, see the following article:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee342461.aspx"&gt;A Developer's Introduction to Windows Workflow Foundation (WF) in .NET 4&lt;/a&gt;” by Matt Milner available. &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;The following table shows the code of my &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt; class.&lt;/p&gt;  &lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="900"&gt;         &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; Using Directives
&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Activities;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Activities.Tracking;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ComponentModel;
&lt;span class="preproc"&gt;#endregion&lt;/span&gt;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.WorkflowActivities
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// This class can be used in any WF workflow to track&lt;/span&gt;
    &lt;span class="rem"&gt;/// user-defined events to any registered tracking providers&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    [Designer(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CustomTrackingActivityDesigner))]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomTrackingActivity : CodeActivity
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Activity Arguments
        &lt;span class="rem"&gt;// Text Argument&lt;/span&gt;
        [DefaultValue(&lt;span class="kwrd"&gt;null&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; InArgument&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Text { get; set; } 
        
        &lt;span class="rem"&gt;// TraceLevel Property&lt;/span&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; TraceLevel TraceLevel { get; set; }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Protected Methods
        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// Tracks the text message contained in the Text argument.&lt;/span&gt;
        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// &amp;lt;param name=&amp;quot;context&amp;quot;&amp;gt;The execution context under which the activity executes.&amp;lt;/param&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute(CodeActivityContext context)
        {
            &lt;span class="rem"&gt;// Obtain the runtime value of the Text and TraceLevel input arguments&lt;/span&gt;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; text = context.GetValue(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Text);

            &lt;span class="rem"&gt;// Create and initialize a custom tracking record &lt;/span&gt;
            CustomTrackingRecord record = &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomTrackingRecord(text, &lt;span class="kwrd"&gt;this&lt;/span&gt;.TraceLevel);

            &lt;span class="rem"&gt;// Sends the specified custom tracking record to any registered tracking providers&lt;/span&gt;
            context.Track(record);
        } 
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt; class is derived from the &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.codeactivity.aspx"&gt;CodeActivity&lt;/a&gt; base class and overrides the &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.codeactivity.execute.aspx"&gt;Execute&lt;/a&gt;. The latter has a single parameter of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.codeactivitycontext.aspx"&gt;CodeActivityContext&lt;/a&gt; which represents the execution context under which the activity executes. In particular, the context object exposes a method called Track that can be used to send a custom tracking record to any registered tracking providers. The tracking provider used by AppFabric is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.tracking.etwtrackingparticipant.aspx"&gt;EtwTrackingParticipant&lt;/a&gt;. For more information, see the following article:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/dd807395.aspx"&gt;Tracking Events into Event Tracing in Windows&lt;/a&gt;” on MSDN. &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;The &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt; class exposes 2 properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;Text&lt;/strong&gt;: contains the message to track at runtime. This latter can be declaratively set using Workflow Designer. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;TraceLevel&lt;/strong&gt;: specifies the intended trace level for the message.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;The code of the custom activity is very straightforward and self-explaining. First, the method invokes the &lt;a href="http://msdn.microsoft.com/en-us/library/dd641933.aspx"&gt;GetValue&lt;/a&gt; method exposed by the context to retrieve the value of the &lt;strong&gt;Text&lt;/strong&gt; property, next it creates a new instance of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.tracking.customtrackingrecord.aspx"&gt;CustomTrackingRecord&lt;/a&gt; class and finally it calls the &lt;a href="http://msdn.microsoft.com/en-us/library/dd988109.aspx"&gt;Track&lt;/a&gt; method on the context object to track the user-defined event. This activity can surely be extended to extract and track business relevant data associated with the workflow variables.&lt;/p&gt;

&lt;p align="justify"&gt;To control the look and feel of the custom Activity, I added an &lt;a href="http://msdn.microsoft.com/en-us/library/dd489419.aspx"&gt;Activity Designer&lt;/a&gt; item to my project. In particular, this allowed me to perform the following customizations:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Specify a custom icon in the top-left corner of the Activity &lt;/li&gt;

  &lt;li&gt;Create an &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.presentation.view.expressiontextbox.aspx"&gt;ExpressionTextBox&lt;/a&gt; control and bind it to the &lt;strong&gt;Text&lt;/strong&gt; property of the custom activity. &lt;/li&gt;

  &lt;li&gt;Create a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox.aspx"&gt;ComboBox&lt;/a&gt; control and bind it to the &lt;strong&gt;TraceLevel&lt;/strong&gt; property of the custom activity. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2577.Quotes_5F00_Icon_5F00_1007A262.gif"&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="Quotes_Icon" border="0" alt="Quotes_Icon" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6523.Quotes_5F00_Icon_5F00_thumb_5F00_7CB6C5F5.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note 
          &lt;br /&gt;&lt;/strong&gt;To associate the &lt;strong&gt;Activity Designer&lt;/strong&gt; with the custom activity I decorated this with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.designerattribute.aspx"&gt;DesignerAttribute&lt;/a&gt; and I specified the type of the Designer class as argument.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;The following table contains the XAML code for the designer. I’m certainly not a WPF expert, so even if there’s probably a better way to achieve the same result, the code below perfectly fits my needs.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sap:ActivityDesigner&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.AppFabric.CAT.Samples.DuplexMEP.WorkflowActivities.CustomTrackingActivityDesigner&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:sys&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;clr-namespace:System;assembly=mscorlib&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:diag&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;clr-namespace:System.Diagnostics;assembly=system&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:sap&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:sapv&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sap:ActivityDesigner.Resources&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ObjectDataProvider&lt;/span&gt; &lt;span class="attr"&gt;MethodName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;GetValues&amp;quot;&lt;/span&gt;
                        &lt;span class="attr"&gt;ObjectType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{x:Type sys:Enum}&amp;quot;&lt;/span&gt;
                        &lt;span class="attr"&gt;x:Key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TraceLevelValues&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ObjectDataProvider.MethodParameters&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;x:Type&lt;/span&gt; &lt;span class="attr"&gt;TypeName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;diag:TraceLevel&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ObjectDataProvider.MethodParameters&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ObjectDataProvider&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;sap:ActivityDesigner.Resources&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sap:ActivityDesigner.Icon&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DrawingBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DrawingBrush.Drawing&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ImageDrawing&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ImageDrawing.Rect&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rect&lt;/span&gt; &lt;span class="attr"&gt;Location&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0,0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Size&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;25,25&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Rect&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ImageDrawing.Rect&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ImageDrawing.ImageSource&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;BitmapImage&lt;/span&gt; &lt;span class="attr"&gt;UriSource&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Resources/ActivityIcon.gif&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ImageDrawing.ImageSource&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ImageDrawing&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DrawingBrush.Drawing&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DrawingBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;sap:ActivityDesigner.Icon&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;30&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;30&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; 
               &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;
               &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Text:&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sapv:ExpressionTextBox&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; 
                                &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;
                                &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;expText&amp;quot;&lt;/span&gt;
                                &lt;span class="attr"&gt;OwnerActivity&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding Path=ModelItem, Mode=TwoWay}&amp;quot;&lt;/span&gt;
                                &lt;span class="attr"&gt;Expression&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding Path=ModelItem.Text.Expression, Mode=TwoWay}&amp;quot;&lt;/span&gt;
                                &lt;span class="attr"&gt;ExpressionType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{x:Type TypeName=sys:String}&amp;quot;&lt;/span&gt;
                                &lt;span class="attr"&gt;HintText&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Message Text&amp;quot;&lt;/span&gt;
                                &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt;
                              &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; 
               &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;
               &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;TraceLevel:&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ComboBox&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;myComboBox&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding Source={StaticResource TraceLevelValues}}&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;SelectedValue&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding Path=ModelItem.TraceLevel, Mode=TwoWay}&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;sap:ActivityDesigner&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;To develop my custom activity, I used the following resources:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/dd489425.aspx"&gt;Designing and Implementing Custom Activities&lt;/a&gt;” topic on MSDN.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ff602408.aspx"&gt;Using Custom Activity Designers and Templates&lt;/a&gt;” topic on MSDN.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee342461.aspx"&gt;A Developer's Introduction to Windows Workflow Foundation (WF) in .NET 4&lt;/a&gt;” by Matt Milner available. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://channel9.msdn.com/Blogs/jbienz/From-Code-Activity-to-Custom-Activity"&gt;From Code Activity to Custom Activity&lt;/a&gt;” video on Channel9.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://www.cloudcasts.net/ViewWebcast.aspx?webcastid=2521361617430999695"&gt;WF 4.0 Custom Activities Part 3 Activity Designers&lt;/a&gt;” video in CloudCasts site.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://mstecharchitect.blogspot.com/2010/02/wf-40-custom-activity-designer.html"&gt;WF 4.0 Custom Activity Designer&lt;/a&gt;” post on Sreeni.NET Blog.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;“&lt;a href="http://blogs.msdn.com/b/tilovell/archive/2010/03/08/the-workflow-4-0-custom-activity-icon-and-toolbox-icon-faq.aspx"&gt;The Workflow 4.0 Custom Activity Icon (and Toolbox Icon) FAQ&lt;/a&gt;“ post on the Activity Designer blog.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are interested in how to track user-defined events in a WCF service running within AppFabric, you can review the following article:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;“&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/11/02/getting-the-most-out-of-user-events-and-windows-server-appfabric-monitoring.aspx"&gt;Getting the most out of user events and Windows Server AppFabric Monitoring&lt;/a&gt;” by Emil Velinov on the AppFabric CAT blog. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Transforming Messages within a WF Workflow using the Mapper Activity&lt;/h3&gt;

&lt;p align="justify"&gt;As you will see in the next section, my demo is composed of 3 major tiers:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;A Windows Forms client application.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;A WCF Workflow Service running in Windows Server AppFabric.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;A BizTalk Application composed of an orchestration and a request-response WCF Receive Location.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;In a few words, the WCF Workflow Service receives a request from the client application and invokes the downstream orchestration via a WCF Receive Location. The format of the request and response messages exchanged by the WCF workflow service, respectively, with the client and BizTalk applications is obviously different to reflect real-world EAI scenarios where heterogeneous systems use different schemas to represent the same entities. Now, in this case, message transformation could be configured in a declarative way to run on the BizTalk receive location that receives requests and returns related responses.&amp;#160; Nevertheless, since one of the objectives of this article was introducing the new &lt;strong&gt;Mapper&lt;/strong&gt; activity available in &lt;strong&gt;AppFabric Connect&lt;/strong&gt;, I decided to implement message transformation within my WCF workflow service. &lt;strong&gt;AppFabric Connect&lt;/strong&gt; provides WF developers access to both the &lt;strong&gt;BizTalk Mapper&lt;/strong&gt; and the BizTalk Adapter Pack 2010. Utilizing the &lt;strong&gt;Mapper&lt;/strong&gt; activity, developers can exploit the features supplied by the &lt;a href="http://blogs.msdn.com/b/biztalk_server_team_blog/archive/2010/08/24/improved-productivity-with-biztalk-server-2010-mapper.aspx"&gt;BizTalk Server 2010 Mapper&lt;/a&gt; to design and use transformation maps in a WF workflow service hosted in IIS\AppFabric. &lt;/p&gt;

&lt;p align="justify"&gt;Using the &lt;strong&gt;Mapper&lt;/strong&gt; activity in a WF workflow is quite straightforward: first of all, you have to define the WCF data contract classes that model the source and destination messages. Thus, in my solution I created 5 data contract classes to model the messages exchanged by WCF workflow service, respectively, with the client and BizTalk applications:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;WFRequest: &lt;/strong&gt;defines the request message&amp;#160; sent by the client application to the WCF workflow service.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;WFAck&lt;/strong&gt;: specifies the structure of the acknowledgement message sent by the WCF workflow service to the client application.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;WFResponse&lt;/strong&gt;: represents the the response message returned by the WCF workflow service to the client application.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;BizTalkRequest&lt;/strong&gt;: defines the request message sent by the WCF workflow service to the BizTalk application.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;BizTalkResponse&lt;/strong&gt;: represents the the response message returned by the BizTalk application to the WCF workflow service&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;These 5 data classes belong to the same Class Library project called &lt;strong&gt;DataContracts&lt;/strong&gt;. For your convenience, below I included the code of these components.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;WFRequest Class&lt;/strong&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.DataContracts
{
    [DataContract(Name=&lt;span class="str"&gt;&amp;quot;Request&amp;quot;&lt;/span&gt;, Namespace=&lt;span class="str"&gt;&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep/wf&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WFRequest : IExtensibleDataObject
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; ExtensionDataObject extensionData;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; id;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; question;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; delay;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; WFRequest()
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.question = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay = 0;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; WFRequest(&lt;span class="kwrd"&gt;string&lt;/span&gt; question, &lt;span class="kwrd"&gt;int&lt;/span&gt; delay)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = Guid.NewGuid().ToString();
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.question = question;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay = delay;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ExtensionDataObject ExtensionData
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMember(Name = &lt;span class="str"&gt;&amp;quot;Id&amp;quot;&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 1, EmitDefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Id
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.id;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMember(Name = &lt;span class="str"&gt;&amp;quot;Question&amp;quot;&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 2, EmitDefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Question
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.question;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.question = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMember(Name = &lt;span class="str"&gt;&amp;quot;Delay&amp;quot;&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 3, EmitDefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Delay
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;WFAck&lt;/strong&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.DataContracts
{
    [DataContract(Name = &lt;span class="str"&gt;&amp;quot;Ack&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep/wf&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WFAck : IExtensibleDataObject
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; ExtensionDataObject extensionData;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; id;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ack;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; WFAck()
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.ack = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; WFAck(&lt;span class="kwrd"&gt;string&lt;/span&gt; id, &lt;span class="kwrd"&gt;string&lt;/span&gt; question)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = id;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.ack = question;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ExtensionDataObject ExtensionData
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMember(Name = &lt;span class="str"&gt;&amp;quot;Id&amp;quot;&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 1, EmitDefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Id
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.id;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMember(Name = &lt;span class="str"&gt;&amp;quot;Ack&amp;quot;&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 2, EmitDefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Ack
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.ack;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.ack = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;WFResponse&lt;/strong&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.DataContracts
{
    [DataContract(Name = &lt;span class="str"&gt;&amp;quot;Response&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep/wf&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WFResponse : IExtensibleDataObject
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; ExtensionDataObject extensionData;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; id;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; answer;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; WFResponse()
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.answer = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; WFResponse(&lt;span class="kwrd"&gt;string&lt;/span&gt; id, &lt;span class="kwrd"&gt;string&lt;/span&gt; question)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = id;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.answer = question;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ExtensionDataObject ExtensionData
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMember(Name = &lt;span class="str"&gt;&amp;quot;Id&amp;quot;&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 1, EmitDefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Id
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.id;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMember(Name = &lt;span class="str"&gt;&amp;quot;Answer&amp;quot;&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 2, EmitDefaultValue = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Answer
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.answer;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.answer = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;BizTalkRequest&lt;/strong&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.DataContracts
{
    [DataContract(Name=&lt;span class="str"&gt;&amp;quot;Request&amp;quot;&lt;/span&gt;, Namespace=&lt;span class="str"&gt;&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BizTalkRequest : IExtensibleDataObject
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; ExtensionDataObject extensionData;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; id;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; question;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; delay;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; BizTalkRequest()
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = Guid.NewGuid().ToString();
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.question = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay = 0;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; BizTalkRequest(&lt;span class="kwrd"&gt;string&lt;/span&gt; question, &lt;span class="kwrd"&gt;int&lt;/span&gt; delay)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = Guid.NewGuid().ToString();
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.question = question;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay = delay;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ExtensionDataObject ExtensionData
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMemberAttribute(IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 1)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Id
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.id;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMemberAttribute(IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 2)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Question
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.question;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.question = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMemberAttribute(IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 3)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Delay
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.delay = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        } 
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;BizTalkResponse&lt;/strong&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.DataContracts
{
    [DataContract(Name = &lt;span class="str"&gt;&amp;quot;Response&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BizTalkResponse : IExtensibleDataObject
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; ExtensionDataObject extensionData;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; id;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; answer;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ExtensionDataObject ExtensionData
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.extensionData = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMemberAttribute(IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 1)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Id
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.id;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.id = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [DataMemberAttribute(IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Order = 2)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Answer
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.answer;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.answer = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The next step was to define a variable for each of the messages exchanged by the WCF workflow service with the client and the BizTalk application. The picture below shows the 5 data contract variables that I created within the outermost &lt;strong&gt;Sequential&lt;/strong&gt; activity within my WCF workflow service. This activity contains also&amp;#160; the correlation handle used by the workflow to correlate the request message sent by the client application with the corresponding response message. We will expand on this point later.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5164.WorkflowServiceVariables_5F00_266A1B1C.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WorkflowServiceVariables" border="0" alt="WorkflowServiceVariables" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8713.WorkflowServiceVariables_5F00_thumb_5F00_3EE9929F.jpg" width="801" height="910" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;Then I created a map to transform a &lt;strong&gt;WFRequest&lt;/strong&gt; object into a &lt;strong&gt;BizTalkRequest&lt;/strong&gt; object and another map to transform a &lt;strong&gt;BizTalkResponse&lt;/strong&gt; object into an instance of the &lt;strong&gt;WFResponse&lt;/strong&gt; class. In a nutshell, these are the steps I followed to create the first of the 2 transformation maps. After installing the BizTalk Server 2010 developer tools and the &lt;strong&gt;WCF LOB Adapter SDK&lt;/strong&gt;, you can see the &lt;strong&gt;Mapper&lt;/strong&gt; activity on the &lt;strong&gt;Windows Workflow Activity Palette&lt;/strong&gt; under a tab called &lt;strong&gt;BizTalk&lt;/strong&gt;, shown in the picture below.&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4428.MapperActivity_5F00_420B54BA.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="MapperActivity" border="0" alt="MapperActivity" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8625.MapperActivity_5F00_thumb_5F00_63C7077E.jpg" width="236" height="385" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;When you drag the &lt;strong&gt;Mapper&lt;/strong&gt; activity onto a workflow, it prompts you for the data types of the source and destination message.&amp;#160; The dialog&amp;#160; allows you to choose primitive types, or custom types. To create the first map, I chose the &lt;strong&gt;WFRequest&lt;/strong&gt; type as &lt;strong&gt;InputDataContractType&lt;/strong&gt; and the &lt;strong&gt;BizTalkRequest&lt;/strong&gt; as &lt;strong&gt;OutputDataContractType&lt;/strong&gt; as shown in the picture below.&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0714.SelectTypes_5F00_5795678A.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SelectTypes" border="0" alt="SelectTypes" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1212.SelectTypes_5F00_thumb_5F00_258DA133.jpg" width="461" height="325" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;When I clicked the OK button, an un-configured &lt;strong&gt;Mapper&lt;/strong&gt; activity appeared in my workflow. After setting the explicit names of my source (&lt;strong&gt;WFRequest&lt;/strong&gt;) and destination variables (&lt;strong&gt;BizTalkRequest&lt;/strong&gt;) in the &lt;strong&gt;Mapper&lt;/strong&gt; activity’s Property window, I clicked the &lt;strong&gt;Edit&lt;/strong&gt; button and chose to create a new map. &lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5025.SelectAMap_5F00_7149521F.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SelectAMap" border="0" alt="SelectAMap" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8168.SelectAMap_5F00_thumb_5F00_7A756793.jpg" width="423" height="200" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The &lt;strong&gt;Select a map&lt;/strong&gt; dialog allows to create a new map or select an existing one based on data contract types chosen at the previous step. If you are creating a new map, the activity will generate the XML schemas for the selected input and output data contract types and a new BizTalk map (.btm) file. Differently than in BizTalk Server, XML schemas and map files don’t need to published to a centralized database, but they become an integral part of the project. You can eventually define your maps in a separate project from your workflows to increase the reusability and maintenance level of these artifacts.&lt;/p&gt;

&lt;p align="justify"&gt;Upon clicking the &lt;strong&gt;OK &lt;/strong&gt;button, the &lt;strong&gt;BizTalk Mapper&lt;/strong&gt; &lt;strong&gt;Designer&lt;/strong&gt; appeared and I could create my transformation map as shown in the picture below. When using the &lt;strong&gt;BizTalk Mapper&lt;/strong&gt; &lt;strong&gt;Designer&lt;/strong&gt; within a WF workflow application, you have full access to all the features and functoids that BizTalk developers normally use in their solution. &lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3806.Map_5F00_07ABCADA.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Map" border="0" alt="Map" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2804.Map_5F00_thumb_5F00_16B283E7.jpg" width="830" height="276" /&gt;&lt;/a&gt;At runtime, the input data is first serialized into XML and then transformed using the XSLT generated from the map file. The message resulting from the transformation is finally de-serialized back into an object of the output type. At this regard, the &lt;strong&gt;Mapper&lt;/strong&gt; activity decides to use the &lt;strong&gt;XmlSerializer&lt;/strong&gt; only if the type is annotated with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmltypeattribute.aspx"&gt;XmlTypeAttribute&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlrootattribute.aspx"&gt;XmlRootAttribute&lt;/a&gt;. If the activity is an array type, the attribute check will be performed on the array element type as well. In all other cases, &lt;strong&gt;DataContractSerializer&lt;/strong&gt; is used.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6052.Quotes_5F00_Icon_5F00_69F9A440.gif"&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="Quotes_Icon" border="0" alt="Quotes_Icon" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4863.Quotes_5F00_Icon_5F00_thumb_5F00_5F0C9D2B.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note 
            &lt;br /&gt;&lt;/strong&gt;When creating a map it is possible to use &lt;strong&gt;Advanced Options&lt;/strong&gt; to change the &lt;strong&gt;Serializer to use for Input&lt;/strong&gt; and the &lt;strong&gt;Serializer to use for Result&lt;/strong&gt; from &lt;strong&gt;Auto&lt;/strong&gt; to &lt;strong&gt;DataContractSerializer&lt;/strong&gt; or &lt;strong&gt;XMLSerializer&lt;/strong&gt;. Manually setting the serializer is not recommended however and extreme caution should be exercised when doing this because specifying the wrong serializer will cause serialization to fail at runtime. &lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;For more information on the Mapper Activity, see the following articles by Trace Young: &lt;/p&gt;

&lt;ul type="circle"&gt;
  &lt;li&gt;”&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/biztalk-server-2010-appfabric-connect-feature-frequently-asked-questions-faq.aspx"&gt;BizTalk Server 2010 AppFabric Connect feature Frequently Asked Questions (FAQ)&lt;/a&gt;” article on TechNet. &lt;/li&gt;

  &lt;li&gt;”&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/installing-the-biztalk-server-2010-appfabric-connect-feature.aspx#instDev"&gt;Installing the BizTalk Server 2010 AppFabric Connect feature&lt;/a&gt;” article on TechNet. &lt;/li&gt;

  &lt;li&gt;“&lt;a href="http://seroter.wordpress.com/2010/05/24/using-the-new-biztalk-mapper-shape-in-a-windows-workflow-service/"&gt;Using the New BizTalk Mapper Shape in a Windows Workflow Service&lt;/a&gt;” article on Richard Seroter’s blog. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After stacking the necessary (LEGO) bricks,&amp;#160; we are now ready to build our solution, so let’s get started.&lt;/p&gt;

&lt;h3&gt;Using a Durable Duplex Correlation to communicate with a WF Workflow&lt;/h3&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the use case. The idea behind the application is quite straightforward: a Windows Forms application submits a question to a WCF workflow service hosted in IIS\AppFabric and asynchronously waits for the related answer. The WCF workflow service uses the &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the incoming request in a format suitable to be consumed by the underlying BizTalk application and synchronously invokes the &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; orchestration via a WCF-NetTcp Receive Location. The orchestration is a BizTalk version of the notorious &lt;a href="http://en.wikipedia.org/wiki/Magic_8-Ball"&gt;Magic 8 Ball&lt;/a&gt; toy and it randomly returns one of 20 standardized answers.&amp;#160; Upon receiving the response message from BizTalk, the WCF workflow service applies another map using the &lt;strong&gt;Mapper&lt;/strong&gt; activity and returns the resulting message to the client application. In this version, the client application communicates with the WCF workflow service using a pattern called &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt;, whereas the WCF workflow service communicates with the BizTalk application using a synchronous message exchange pattern. In the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2011/01/20/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-3.aspx"&gt;next and final article&lt;/a&gt; of the series, I’ll show you how to use the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; to implement an asynchronous message exchange between the WCF workflow service and the downstream BizTalk orchestration. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5164.SyncMagic8BallUseCase_5F00_642164B3.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SyncMagic8BallUseCase" border="0" alt="SyncMagic8BallUseCase" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7635.SyncMagic8BallUseCase_5F00_thumb_5F00_1E3D0508.jpg" width="880" height="660" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-weight: bold"&gt;Message Flow&lt;/span&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;The&amp;#160; &lt;strong&gt;Windows Forms Client Application &lt;/strong&gt;enables a user to specify a question and a delay in seconds. When the user presses the &lt;strong&gt;Ask &lt;/strong&gt;button, a new request message containing the question and the delay is created and sent to a the WCF workflow service. Before sending the first message, the client application creates and opens a service host to expose a callback endpoint that the workflow can invoke to return the response message. In particular, the binding used to expose this callback contract is the &lt;strong&gt;NetTcpBinding&lt;/strong&gt;, whereas the binding used to send the request message to the WCF workflow service is the &lt;strong&gt;NetTcpContextBinding&lt;/strong&gt;. We will expand on this point in the next sections when we’ll analyze the client-side code.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The WCF workflow service receives the request message of type &lt;strong&gt;WFRequest&lt;/strong&gt; using the &lt;strong&gt;Receive&lt;/strong&gt; activity of a &lt;strong&gt;ReceiveAndSendReply&lt;/strong&gt; composed activity. Then it uses this activity to initialize the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;callback correlation&lt;/a&gt; handle.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The WCF workflow service uses the &lt;strong&gt;CustomTrackingActivity &lt;/strong&gt;to keep track of individual processing steps and uses an instance of the &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the &lt;strong&gt;WFRequest &lt;/strong&gt;object into an instance of the &lt;strong&gt;BizTalkRequest&lt;/strong&gt; class.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The WCF workflow service uses a &lt;strong&gt;WCF proxy activity&lt;/strong&gt; to send the &lt;strong&gt;BizTalkRequest&lt;/strong&gt; message to the &lt;strong&gt;WCF-NetTcp&lt;/strong&gt; receive location exposed by the BizTalk application.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The WCF receive location receives the request message and the &lt;strong&gt;XmlReceive &lt;/strong&gt;pipeline promotes the &lt;strong&gt;MessageType&lt;/strong&gt; context property.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The &lt;strong&gt;Message Agent&lt;/strong&gt; submits the request message to the MessageBox (BizTalkMsgBoxDb).&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;A new instance of the &lt;strong&gt;SyncMagic8Ball &lt;/strong&gt;orchestration receives the request message via a two-way logical port and uses a custom helper component called &lt;strong&gt;XPathHelper&lt;/strong&gt; to read the value of the &lt;strong&gt;Question&lt;/strong&gt; and &lt;strong&gt;Delay&lt;/strong&gt; elements from the inbound message.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The &lt;strong&gt;SyncMagic8Ball &lt;/strong&gt;orchestration invokes the &lt;strong&gt;SetResponse&lt;/strong&gt; static method exposed by the &lt;strong&gt;ResponseHelper&lt;/strong&gt; class to build the response message containing the answer to this question contained in the request message. The response message is then published to the MessageBox (BizTalkMsgBoxDb) by the &lt;strong&gt;Message Agent&lt;/strong&gt;.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The response message is retrieved by the WCF-NetTcp Receive Location. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The &lt;strong&gt;PassThruTransmit&lt;/strong&gt; send pipeline is executed by the WCF-NetTcp Receive Location.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The response message is returned to the WCF workflow service. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The WCF workflow service uses a &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the &lt;strong&gt;BizTalkResponse&lt;/strong&gt; object into an instance of the &lt;strong&gt;WFRequest&lt;/strong&gt; class.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;The WCF workflow service uses a &lt;strong&gt;Send&lt;/strong&gt; activity to send back the response message to the client application. The &lt;strong&gt;Send&lt;/strong&gt; activity is configured to use the callback correlation that contains the URI of the callback endpoint exposed by the client application.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&amp;#160;&lt;/h3&gt;

&lt;h3&gt;Durable Duplex&lt;/h3&gt;

&lt;p align="justify"&gt;One of the objective of this post is demonstrating how to use a duplex communication pattern to exchange messages between a client application and a WCF workflow service running within IIS\AppFabric. However, WF 4.0 doesn't directly support WCF &lt;a href="http://msdn.microsoft.com/en-us/library/ms752216.aspx"&gt;Duplex&lt;/a&gt; communication, but it supports a different pattern called &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex&lt;/a&gt;. This pattern requires the client and server applications to use a separate WCF channel to exchange, respectively, the request and response message and this enables them to use a different binding on the callback channel than the one used to send the original request. Since the channels used to exchange the request and response message are independent, the callback can happen at any time in the future. The only requirement for the caller is to have an active endpoint listening for the callback message. The Durable Duplex pattern allows a client application to communicate with a WCF workflow service in a long-running conversation. 

  &lt;br /&gt;To use durable duplex correlation, the client&amp;#160; application and the WCF workflow service must use a context-enabled binding that supports two-way operations, such as &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpcontextbinding.aspx"&gt;NetTcpContextBinding&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpcontextbinding.aspx"&gt;WSHttpContextBinding&lt;/a&gt;. This requirement applies only to the WCF channel used to exchange the initial request, whereas any binding can be used by the WCF channel used by the callback. Before sending a request message, the client application registers a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpcontextbinding.clientcallbackaddress.aspx"&gt;ClientCallbackAddress&lt;/a&gt; with the URI of the callback &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.endpoint.aspx"&gt;Endpoint&lt;/a&gt;. The WCF workflow service receives this data with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.aspx"&gt;Receive&lt;/a&gt; activity and then uses it on its own &lt;strong&gt;Endpoint&lt;/strong&gt; in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.aspx"&gt;Send&lt;/a&gt; activity to send a response or a notification message back to the caller. For more information on the Durable Duplex Correlation, see the following topic on MSDN:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt;” topic in the WF online documentation.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 align="justify"&gt;Client Code&lt;/h3&gt;

&lt;p align="justify"&gt;The following table contains code used by the client application to invoke the WCF workflow service using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex&lt;/a&gt; communication pattern.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnAsk_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        &lt;span class="kwrd"&gt;int&lt;/span&gt; delay = 0;
        &lt;span class="rem"&gt;//  Question Validation&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(txtQuestion.Text))
        {
            WriteToLog(QuestionCannotBeNull);
            txtQuestion.Focus();
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }
        &lt;span class="rem"&gt;//  Delay Validation&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(txtDelay.Text) ||
            !&lt;span class="kwrd"&gt;int&lt;/span&gt;.TryParse(txtDelay.Text, &lt;span class="kwrd"&gt;out&lt;/span&gt; delay))
        {
            WriteToLog(DelayMustBeANumber);
            txtDelay.Focus();
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }
        &lt;span class="rem"&gt;// Endpoint Validation&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(cboEndpoint.Text))
        {
            WriteToLog(NoEndpointsFound);
        }

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (serviceHost == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                &lt;span class="rem"&gt;// Find a free TCP port&lt;/span&gt;
                &lt;span class="kwrd"&gt;int&lt;/span&gt; port = FreeTcpPort();
                &lt;span class="rem"&gt;// Set the value of the static MainForm property&lt;/span&gt;
                Magic8BallWFCallback.MainForm = &lt;span class="kwrd"&gt;this&lt;/span&gt;;
                &lt;span class="rem"&gt;// Create the service host that will be used to &lt;/span&gt;
                &lt;span class="rem"&gt;// receive the response from the WCF Workflow Service&lt;/span&gt;
                serviceHost = &lt;span class="kwrd"&gt;new&lt;/span&gt; ServiceHost(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Magic8BallWFCallback));
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (serviceHost.Description.Endpoints.Count &amp;gt; 0)
                {
                    &lt;span class="rem"&gt;// Read the URI from the configuration file and&lt;/span&gt;
                    &lt;span class="rem"&gt;// change it to use the TCP port found at the previous step&lt;/span&gt;
                    Uri oldUri = serviceHost.Description.Endpoints[0].Address.Uri;
                    listenUri = &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(URIFormat, oldUri.Scheme, 
                                                        oldUri.Host, port, 
                                                        oldUri.AbsolutePath));
                    serviceHost.Description.Endpoints[0].Address = &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(listenUri);
                    serviceHost.Open();
                    &lt;span class="rem"&gt;// Log the URI&lt;/span&gt;
                    WriteToLog(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(Magic8BallWFCallbackServiceOpened, listenUri.AbsoluteUri));
                }
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                {
                    &lt;span class="rem"&gt;// Log error message&lt;/span&gt;
                    WriteToLog(NoValidEndpointsForMagic8BallWFCallbackServiceOpened);
                }
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                &lt;span class="rem"&gt;// Log Exception and InnerException&lt;/span&gt;
                WriteToLog(ex.Message);
                WriteToLog(ex.InnerException.Message);
            }
        }
        Magic8BallWFClient proxy = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (serviceHost != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; serviceHost.State == CommunicationState.Opened)
            {
                &lt;span class="rem"&gt;// Create the client proxy to send the question to the WCF Workflow Service&lt;/span&gt;
                proxy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Magic8BallWFClient(cboEndpoint.Text);
                &lt;span class="rem"&gt;// Create a new request message&lt;/span&gt;
                WFRequest request = &lt;span class="kwrd"&gt;new&lt;/span&gt; WFRequest();
                request.Id = Guid.NewGuid().ToString();
                request.Question = txtQuestion.Text;
                request.Delay = delay;
                WriteToLog(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(CultureInfo.CurrentCulture, 
                                            RequestFormat, 
                                            cboEndpoint.Text, 
                                            request.Id, 
                                            request.Question));
                &lt;span class="kwrd"&gt;using&lt;/span&gt; (&lt;span class="kwrd"&gt;new&lt;/span&gt; OperationContextScope((IContextChannel)proxy.InnerChannel))
                {
                    &lt;span class="rem"&gt;// You can use the context to send pairs of keys and values, &lt;br /&gt;                    // stored implicitly in the message headers,&lt;/span&gt;
                    IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; dictionary = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();
                    dictionary[&lt;span class="str"&gt;&amp;quot;MachineName&amp;quot;&lt;/span&gt;] = Environment.MachineName;
                    &lt;br /&gt;                    &lt;span class="rem"&gt;// Add the URI of the callback endpoint to the callback context&lt;/span&gt;
                    &lt;span class="rem"&gt;// This information is used by the WCF workflow service to initialize&lt;/span&gt;
                    &lt;span class="rem"&gt;// the callback correlation handle used to implement the Durable Duplex pattern.&lt;/span&gt;
                    var context = &lt;span class="kwrd"&gt;new&lt;/span&gt; CallbackContextMessageProperty(listenUri, dictionary);
                    OperationContext.Current.OutgoingMessageProperties.Add(CallbackContextMessageProperty.Name,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; context);
                    &lt;span class="rem"&gt;// Invoke the WF Workflow Service&lt;/span&gt;
                    WFAck ack = proxy.AskQuestion(request);
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (ack != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                        !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(ack.Ack))
                    {
                        WriteToLog(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(AckFormat, ack.Id, ack.Ack));
                    }
                }
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (FaultException ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (proxy != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                proxy.Abort();
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (CommunicationException ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (proxy != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                proxy.Abort();
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (TimeoutException ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (proxy != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                proxy.Abort();
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (proxy != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                proxy.Abort();
            }
        }
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
    {
        WriteToLog(ex.Message);
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;
  &lt;br /&gt;In detail, the code performs the following steps:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Upon the dispatch of the first message, the client application creates the service host that will be used to asynchronously receive the response message from the WCF workflow service. In particular, it individuates a free TCP port, then reads the configuration of the callback service endpoint from the configuration file and finally modifies the URI of the endpoint to use the TCP port found. The WCF callback service exposed by the client application is defined by the &lt;strong&gt;Magic8BallWFCallback&lt;/strong&gt; class that implements the &lt;strong&gt;IMagic8BallWFCallback&lt;/strong&gt; service interface. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Creates a new instance of the &lt;strong&gt;Magic8BallWFClient&lt;/strong&gt; proxy class. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Creates and initializes a new &lt;strong&gt;WFRequest&lt;/strong&gt; object. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontextscope.aspx"&gt;OperationContextScope&lt;/a&gt; to access the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontext.aspx"&gt;OperationContext&lt;/a&gt; within a scope. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Uses the current &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontext.aspx"&gt;OperationContext&lt;/a&gt; and an object of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.callbackcontextmessageproperty.aspx"&gt;CallbackContextMessageProperty&lt;/a&gt; to initialize the &lt;strong&gt;wsc:CallbackContext&lt;/strong&gt; message header with the URI of the callback service endpoint. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Invokes the WCF workflow service. &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;The following table reports the code of the &lt;strong&gt;Magic8BallWFCallback&lt;/strong&gt; service class contained in the &lt;strong&gt;Client&lt;/strong&gt; project and the code of the &lt;strong&gt;IMagic8BallWFCallback&lt;/strong&gt; service interface contained in the &lt;strong&gt;ServiceContracts&lt;/strong&gt; project.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.ServiceContracts
{
    [ServiceContract(Namespace = &lt;span class="str"&gt;&lt;a href="http://microsoft.appfabric.cat/10/samples/duplexmep/wf"&gt;http://microsoft.appfabric.cat/10/samples/duplexmep/wf&lt;/a&gt;&lt;/span&gt;, &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ConfigurationName = &lt;span class="str"&gt;&amp;quot;IMagic8BallWFCallback&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IMagic8BallWFCallback
    {
        [OperationContract(Action = &lt;span class="str"&gt;&amp;quot;AskQuestionResponse&amp;quot;&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;void&lt;/span&gt; AskQuestionResponse(WFResponseMessage responseMessage);
    }
}

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.Client
{
    [ServiceBehavior]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Magic8BallWFCallback : IMagic8BallWFCallback
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Constants
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ResponseFormat = &lt;span class="str"&gt;&amp;quot;Response:\n\tId: {0}\n\tAnswer: {1}&amp;quot;&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Static Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; MainForm form = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Static Fields
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; MainForm MainForm
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; form;
            }
            set
            {
                form = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; IMagic8BallCallback Members
        [OperationBehavior]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AskQuestionResponse(WFResponseMessage responseMessage)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (responseMessage != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                responseMessage.Response != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(responseMessage.Response.Id) &amp;amp;&amp;amp;
                !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(responseMessage.Response.Answer))
            {
                form.WriteToLog(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(CultureInfo.CurrentCulture, 
                                              ResponseFormat, 
                                              responseMessage.Response.Id, 
                                              responseMessage.Response.Answer));
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.AppFabric.CAT.Samples.DuplexMEP.Client
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MainForm : Form
    {
        ...
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WriteToLog(&lt;span class="kwrd"&gt;string&lt;/span&gt; message)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (InvokeRequired)
            {
                Invoke(&lt;span class="kwrd"&gt;new&lt;/span&gt; Action&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(InternalWriteToLog), &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { message });
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
            {
                InternalWriteToLog(message);
            }
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InternalWriteToLog(&lt;span class="kwrd"&gt;string&lt;/span&gt; message)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (message != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                message != &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty)
            {
                &lt;span class="kwrd"&gt;string&lt;/span&gt;[] lines = message.Split(&lt;span class="str"&gt;'\n'&lt;/span&gt;);
                DateTime objNow = DateTime.Now;
                &lt;span class="kwrd"&gt;string&lt;/span&gt; space = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;(&lt;span class="str"&gt;' '&lt;/span&gt;, 19);
                &lt;span class="kwrd"&gt;string&lt;/span&gt; line;

                &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; lines.Length; i++)
                {
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (i == 0)
                    {
                        line = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(DateFormat,
                                             objNow.Hour,
                                             objNow.Minute,
                                             objNow.Second,
                                             lines[i]);
                        lstLog.Items.Add(line);
                    }
                    &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    {
                        lstLog.Items.Add(space + lines[i]);
                    }
                }
                lstLog.SelectedIndex = lstLog.Items.Count - 1;
            }
        }
        ...
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The &lt;strong&gt;AskQuestionResponse&lt;/strong&gt; operation exposed by the callback contract validates and logs the content of the response message returned by the WCF workflow service. The following table shows the content of the configuration file of the client application.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Transport&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;protectionLevel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netTcpContextBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Transport&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;protectionLevel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netTcpContextBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.AppFabric.CAT.Samples.DuplexMEP.Client.Magic8BallWFCallback&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;net.tcp://localhost:15001/magic8ballwfcallback&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWFCallback&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;clear&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;net.tcp://localhost/magic8ballwf/syncmagic8ball.xamlx&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWF&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;NetTcpEndpointSyncWF&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;startup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;supportedRuntime&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;v4.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;sku&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.NETFramework,Version=v4.0&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;startup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;As you can easily notice, the client endpoint uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpcontextbinding.aspx"&gt;NetTcpContextBinding&lt;/a&gt;, whereas the callback service endpoint uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpbinding.aspx"&gt;NetTcpBinding&lt;/a&gt;. The context bindings were introduced in the .NET Framework 3.5 and are typically used the same way as their base bindings. However, they add support for a dedicated context management protocol. These bindings can be used with or without a context. The context protocol lets you pass as a custom context a collection of strings in the form of key-value pairs, stored implicitly in the message headers. In our context, the use of a context binding is mandatory to initialize the Durable Duplex Correlation. This brings us to the next topic.&lt;/p&gt;

&lt;h3 align="justify"&gt;WCF Workflow Service&lt;/h3&gt;

&lt;p align="justify"&gt;WCF workflow services provide a productive environment for authoring long-running, durable operations or services. Workflow services are implemented using WF activities that can make use of WCF for sending and receiving data. Explaining in detail how to build a WCF workflow service is out of the scope of the present article. For more information on WCF workflow services, see the following articles:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee358734.aspx"&gt;How to: Create a Workflow Service with Messaging Activities&lt;/a&gt;” topic on MSDN.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/magazine/ff646977.aspx"&gt;Visual Design of Workflows with WCF and WF 4&lt;/a&gt;” article on MSDN Magazine.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://seroter.wordpress.com/2009/12/17/building-wcf-workflow-services-and-hosting-in-appfabric/"&gt;Building WCF Workflow Services and Hosting in AppFabric&lt;/a&gt;” post on Richard Seroter’s blog.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;In this section I will focus my attention on how the WCF workflow service implements communications with both the client application and the BizTalk orchestration. When I created the WCF Workflow Service, the initial workflow just contained a &lt;strong&gt;Sequence&lt;/strong&gt; activity with a &lt;strong&gt;Receive&lt;/strong&gt; activity followed by a &lt;strong&gt;SendReply&lt;/strong&gt; activity as shown in the following illustration.&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8132.WCFWorkflowService_5F00_122AEF07.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WCFWorkflowService" border="0" alt="WCFWorkflowService" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0714.WCFWorkflowService_5F00_thumb_5F00_5E52D2E8.jpg" width="329" height="394" /&gt;&lt;/a&gt;I selected the &lt;strong&gt;Sequential&lt;/strong&gt; activity and I clicked the &lt;strong&gt;Variables&lt;/strong&gt; button to display the corresponding editor. I created a variable for each message to exchange with the client and BizTalk application and then I created a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.correlationhandle.aspx"&gt;CorrelationHandle&lt;/a&gt; variable to hold the callback correlation.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3022.Variables_5F00_58680982.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Variables" border="0" alt="Variables" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1715.Variables_5F00_thumb_5F00_443EC72C.jpg" width="609" height="242" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;In order to expose a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpcontextbinding.aspx"&gt;NetTcpContextBinding&lt;/a&gt; endpoint I configured the &lt;strong&gt;Receive&lt;/strong&gt; activity as shown in the following picture:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6507.ReceiveActivityProperties_5F00_038C54F0.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="ReceiveActivityProperties" border="0" alt="ReceiveActivityProperties" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6518.ReceiveActivityProperties_5F00_thumb_5F00_0B079E90.jpg" width="617" height="471" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;In particular, I used the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.servicecontractname.aspx"&gt;ServiceContractName&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.aspx"&gt;Receive&lt;/a&gt; activity to specify the target namespace and the contract interface of the service endpoint and I used the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.action.aspx"&gt;Action&lt;/a&gt; property to specify the action header of the request message. To initialize the callback correlation handle, I selected the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.aspx"&gt;Receive&lt;/a&gt; activity and then I clicked the ellipsis button next to the (Collection) text for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.receive.correlationinitializers.aspx"&gt;CorrelationInitializers&lt;/a&gt; property in the property grid for the &lt;strong&gt;Add Correlation Initializers&lt;/strong&gt; dialog box to appear.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7674.InitializeCorrelationHandle_5F00_63BD2F8D.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="InitializeCorrelationHandle" border="0" alt="InitializeCorrelationHandle" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5554.InitializeCorrelationHandle_5F00_thumb_5F00_4542C8D7.jpg" width="502" height="302" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;On the left panel of the dialog, I selected the correlation handle variable previously created, and I then chose &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.callbackcorrelationinitializer.aspx"&gt;Callback correlation initializer&lt;/a&gt; in the combobox containing the available correlation type initializers. Before invoking the downstream BizTalk application, the WCF workflow service immediately returns an ACK message to the caller. Therefore, I configured the &lt;strong&gt;SendReply&lt;/strong&gt; activity, bound to the initial &lt;strong&gt;Receive&lt;/strong&gt; activity, to return a &lt;strong&gt;WFAck&lt;/strong&gt; message, as shown in the picture below.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3480.WFWorkflowFirstPart_5F00_669248A6.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WFWorkflowFirstPart" border="0" alt="WFWorkflowFirstPart" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0272.WFWorkflowFirstPart_5F00_thumb_5F00_79371C90.jpg" width="543" height="616" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;As you can notice, the workflow uses a &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt; to emit a user-defined event. This pattern is used throughout the workflow. Custom tracking records generated at runtime by the WCF workflow service can be analyzed using the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee677276.aspx"&gt;AppFabric Dashboard&lt;/a&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p align="justify"&gt;At this point, I had two option to invoke the WCF-NetTcp receive location exposed by the BizTalk application : the first choice was generating a custom WCF proxy activity, whereas the second alternative was using the messaging activities provided out-of-the-box by WF. In this case I opted for the first option, but in the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2011/01/20/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-3.aspx"&gt;next article&lt;/a&gt; I’ll show you how using the messaging activities and the &lt;a href="http://msdn.microsoft.com/en-us/library/dd807508.aspx"&gt;Content-Based Correlation&lt;/a&gt; to implement an asynchronous communication between the WCF workflow service and the underlying orchestration. To create the WCF proxy activity I performed the following steps: &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;I right clicked the &lt;strong&gt;WorkflowServices&lt;/strong&gt; project and I selected the &lt;strong&gt;Add Service Reference&lt;/strong&gt; from the context menu. &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;As shown in the following picture, in the &lt;strong&gt;Add Service Reference&lt;/strong&gt; dialog I specified the URL of the MetadataExchange endpoint exposed by the &lt;strong&gt;DuplexMEP.Sync.WCF-NetTcp.ReceiveLocation&lt;/strong&gt;. Previously, I generated the service metadata endpoint using the &lt;a href="http://msdn.microsoft.com/en-us/library/bb246083(v=BTS.20).aspx"&gt;BizTalk WCF Publishing Wizard&lt;/a&gt;. This has been recently extended in &lt;strong&gt;AppFabric Connect&lt;/strong&gt; to provide the possibility to publish on-premise WCF receive locations to the cloud using the &lt;strong&gt;Windows Azure Service Bus&lt;/strong&gt;. For more information on this topic, see “&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/exposing-biztalk-applications-on-the-cloud-using-appfabric-connect-for-services.aspx"&gt;Exposing BizTalk Applications on the Cloud using AppFabric Connect for Services&lt;/a&gt;&amp;quot; on TechNet.&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7041.AddServiceReference_5F00_13675FE8.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="AddServiceReference" border="0" alt="AddServiceReference" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0216.AddServiceReference_5F00_thumb_5F00_5E4AAAEA.jpg" width="683" height="562" /&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Then I specified a namespace for the proxy activity and I clicked the OK button to confirm.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;In general, this operation generates a custom activity for each operation exposed by the referenced service. As shown in the picture below, in my case this action created a single activity named &lt;strong&gt;AskQuestion&lt;/strong&gt; to invoke the request-response WCF receive location exposed by the BizTalk application.&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5327.AskQuestionActivity_5F00_556A7CD1.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="AskQuestionActivity" border="0" alt="AskQuestionActivity" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5417.AskQuestionActivity_5F00_thumb_5F00_6F9AC028.jpg" width="275" height="380" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following picture depicts the central part of the &lt;strong&gt;SyncMagic8Ball &lt;/strong&gt;WCF workflow service.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3288.WFCentralPart_5F00_57673000.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WFCentralPart" border="0" alt="WFCentralPart" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4375.WFCentralPart_5F00_thumb_5F00_70BF0D6D.jpg" width="500" height="967" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This section of the workflow executes the following actions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tracks a user-defined event using the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;Uses the &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the &lt;strong&gt;WFRequest&lt;/strong&gt; message into a &lt;strong&gt;BizTalkRequest&lt;/strong&gt; message. &lt;/li&gt;

  &lt;li&gt;Tracks a user-defined event using the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;Invokes the WCF receive location exposed by the BizTalk application. &lt;/li&gt;

  &lt;li&gt;Tracks a user-defined event using the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;Uses the &lt;strong&gt;Mapper&lt;/strong&gt; activity to transform the &lt;strong&gt;BizTalkResponse &lt;/strong&gt;message into a &lt;strong&gt;WFResponse &lt;/strong&gt;message. &lt;/li&gt;

  &lt;li&gt;Tracks a user-defined event using the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;The last part of the WCF workflow invokes the callback endpoint exposed by the client application to return the response to the initial request. In particular, the latter contains the Id of the original request, and this allows the client application to correlate the response to the corresponding request, especially when the client has multiple in-flight requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8400.WFLastPart_5F00_7761F123.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WFLastPart" border="0" alt="WFLastPart" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6355.WFLastPart_5F00_thumb_5F00_38604ABB.jpg" width="478" height="421" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This portion of the workflow performs just 2 steps:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Uses a &lt;strong&gt;Send&lt;/strong&gt; activity&amp;#160; to send the response message to the caller. This activity is configured to use the callback handle correlation. &lt;/li&gt;

  &lt;li&gt;Tracks a user-defined event using the &lt;strong&gt;CustomTrackingActivity&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following figure shows how I configured the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.aspx"&gt;Send&lt;/a&gt; activity used to transmit the response message back to the caller.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5415.SendActivityProperties_5F00_6084CA3F.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SendActivityProperties" border="0" alt="SendActivityProperties" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5758.SendActivityProperties_5F00_thumb_5F00_664F480B.jpg" width="605" height="548" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;As highlighted above, I assigned to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.correlateswith.aspx"&gt;CorrelatesWith&lt;/a&gt; property the callback correlation handle that I previously initialized on the Receive activity. Then I properly set the other properties like &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.operationname.aspx"&gt;OperationName&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.action.aspx"&gt;Action&lt;/a&gt;, and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.send.servicecontractname.aspx"&gt;ServiceContractName&lt;/a&gt; to match the characteristics of the callback service endpoint exposed by the client application.&lt;/p&gt;

&lt;h3&gt;BizTalk Application&lt;/h3&gt;

&lt;p align="justify"&gt;The DuplexMEP application is composed of 2 artifacts, the &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; orchestration and the &lt;strong&gt;DuplexMEP.Sync.WCF-NetTcp.ReceiveLocation&lt;/strong&gt;. As mentioned earlier, the orchestration is a BizTalk version of the notorious &lt;a href="http://en.wikipedia.org/wiki/Magic_8-Ball"&gt;Magic 8 Ball&lt;/a&gt; toy: it receives a request message containing a question, waits for a configurable number of seconds and then it randomly returns one of 20 standardized answers.&amp;#160; &lt;/p&gt;

&lt;p&gt;The following picture shows the receive location within the &lt;strong&gt;BizTalk Administration Console&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-38-83-metablogapi/8475.SyncWCFReceiveLocation_5F00_6EDF7ACA.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SyncWCFReceiveLocation" border="0" alt="SyncWCFReceiveLocation" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6332.SyncWCFReceiveLocation_5F00_thumb_5F00_75EE9175.jpg" width="860" height="138" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; orchestration. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3617.SyncMagic8BallOrchestration_5F00_7CFDA820.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SyncMagic8BallOrchestration" border="0" alt="SyncMagic8BallOrchestration" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1663.SyncMagic8BallOrchestration_5F00_thumb_5F00_763A78D0.jpg" width="868" height="1102" /&gt;&lt;/a&gt;If you are interested in more details about the &lt;strong&gt;DuplexMEP&lt;/strong&gt; BizTalk application, you can read the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/11/23/how-using-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-1.aspx"&gt;first&lt;/a&gt; part of this article.&lt;/p&gt;

&lt;h3&gt;AppFabric Configuration&lt;/h3&gt;

&lt;p align="justify"&gt;This section contains the steps I followed to configure the WCF workflow service in the IIS\AppFabric environment. &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Using the&lt;strong&gt; IIS Manager Console&lt;/strong&gt;, I created a web application called &lt;strong&gt;Magic8BallWF&lt;/strong&gt; that points to the folder containing the project for my &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; WCF workflow service.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Then I right-clicked the &lt;strong&gt;Magic8BallWF &lt;/strong&gt;application, as shown in the picture below, I selected&amp;#160; &lt;strong&gt;Manage WCF and WF Services &lt;/strong&gt;from the context menu and then &lt;strong&gt;Configure&lt;/strong&gt;.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7532.AppFabricConfigure_5F00_1F51EB42.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="AppFabricConfigure" border="0" alt="AppFabricConfigure" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2161.AppFabricConfigure_5F00_thumb_5F00_5858A277.jpg" width="597" height="372" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;On the &lt;strong&gt;Monitoring&lt;/strong&gt; tab of the &lt;strong&gt;Configure WCF and WF for Application&lt;/strong&gt; dialog, I enabled event collection to the &lt;strong&gt;AppFabric Monitoring&lt;/strong&gt; database, I selected the connection string for the monitoring database and I chose an appropriate monitoring level. &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3225.MonitoringTab_5F00_42EAC742.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="MonitoringTab" border="0" alt="MonitoringTab" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2677.MonitoringTab_5F00_thumb_5F00_2F4D41D4.jpg" width="862" height="662" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;On the &lt;strong&gt;Workflow Persistence&lt;/strong&gt; tab, I selected the &lt;strong&gt;SQL Server Workflow Per&lt;/strong&gt;sistence option to enable persisting service instances to the &lt;strong&gt;AppFabric Persistence&lt;/strong&gt; database.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6708.WorkflowPersistenceTab_5F00_593D1A2F.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WorkflowPersistenceTab" border="0" alt="WorkflowPersistenceTab" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4667.WorkflowPersistenceTab_5F00_thumb_5F00_5F73CAF0.jpg" width="862" height="662" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6052.Quotes_5F00_Icon_5F00_69F9A440.gif"&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="Quotes_Icon" border="0" alt="Quotes_Icon" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4863.Quotes_5F00_Icon_5F00_thumb_5F00_5F0C9D2B.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note 
            &lt;br /&gt;&lt;/strong&gt;For data protection and performance reasons,&amp;#160; WCF and WF services running on the same AppFabric environment can be configured to use separate monitoring and persistence stores. This solution is particularly suitable for a multi-tenant hosted environment running several applications that are managed by different companies or different divisions within the same company. For more information on this topic, you can read the following articles:&lt;/p&gt;

        &lt;ul type="circle"&gt;
          &lt;li&gt;
            &lt;div align="justify"&gt;“&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/08/13/windows-server-appfabric-monitoring-tracking-bottlenecks-and-mitigation-techniques.aspx"&gt;Windows Server AppFabric Monitoring – Tracking Bottlenecks and Mitigation Techniques&lt;/a&gt;” post on the AppFabric CAT blog.&lt;/div&gt;
          &lt;/li&gt;

          &lt;li&gt;
            &lt;div align="justify"&gt;“&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/09/23/windows-server-appfabric-how-to-adding-multiple-persistence-stores-to-an-appfabric-installation.aspx"&gt;Windows Server AppFabric How-To: Adding multiple persistence stores to an AppFabric installation&lt;/a&gt;” post on the AppFabric CAT blog.&lt;/div&gt;
          &lt;/li&gt;

          &lt;li&gt;
            &lt;div align="justify"&gt;“&lt;a href="http://download.microsoft.com/download/A/5/B/A5B0ED08-844F-4E37-9F0F-BEE9F3043907/AppFabricArchGuide.docx"&gt;AppFabric Architecture and Deployment Topologies guide&lt;/a&gt;” on the Microsoft Download Center.&lt;/div&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;On the &lt;strong&gt;Workflow Host Management&lt;/strong&gt;&amp;#160; tab, I configured the runtime behavior of WF service instances.&amp;#160; &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1121.WorkflowHostManagement_5F00_3176526B.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WorkflowHostManagement" border="0" alt="WorkflowHostManagement" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6012.WorkflowHostManagement_5F00_thumb_5F00_1C1AAF27.jpg" width="862" height="662" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6052.Quotes_5F00_Icon_5F00_69F9A440.gif"&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="Quotes_Icon" border="0" alt="Quotes_Icon" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4863.Quotes_5F00_Icon_5F00_thumb_5F00_5F0C9D2B.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note 
            &lt;br /&gt;&lt;/strong&gt;To manage a durable workflow service within the AppFabric runtime environment, the &lt;strong&gt;net.pipe&lt;/strong&gt; binding must be configured for the website containing that application, and the &lt;strong&gt;net.pipe&lt;/strong&gt; protocol must be enabled for the application. This is required because the &lt;strong&gt;Workflow Management Service&lt;/strong&gt; (WMS), which works with the workflow persistence store to provide reliability and instance control, communicates with the Workflow Control standard endpoint of workflow services via the net.pipe protocol. If the net.pipe protocol is not set for a durable workflow application, when you attempt to configure the application, you will receive the following error message: “Workflow persistence is not fully functional because the net.pipe protocol is missing from the application’s list of enabled protocols.” To enable the &lt;strong&gt;net.pipe&lt;/strong&gt; protocol for an application, right-click the application, point to Manage Application, and then click Advanced Settings. Add “,net.pipe” to “http” in the Enabled Protocols line (with no space between “http” and the comma), and then click OK. For more information on this topic, see &amp;quot;&lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/appfabric-configuration-issues-net-4-net-pipe-and-role-services.aspx"&gt;AppFabric Configuration Issues: .NET 4, net.pipe, and Role Services&lt;/a&gt;&amp;quot; on TechNet.&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;On the &lt;strong&gt;Auto-Start&lt;/strong&gt; tab, I enabled the auto-start feature for my web application. When auto-start is enabled, hosted WF or WCF services within an application are instantiated automatically when the IIS service is started by the operating system. The services within the application will automatically start when the server is started. You can configure all services within an application to start, or a subset of services within an application. If you enable auto-start for an application, the auto-start feature will work only if you also enable auto-start for the application pool used by the application. The auto-start feature of AppFabric is built on top of the auto-start feature of Internet Information Services (IIS) 7.5, which is included in Windows 7 and Windows Server 2008 R2. In IIS, you can configure an application pool and all or some of its applications to automatically start when the IIS service starts. The AppFabric auto-start feature extends this functionality so that you can configure all or some of the services within an application to automatically start when the application starts. &lt;/div&gt;

    &lt;p&gt;For more information on this topic, see the following articles:&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;&lt;i&gt;&amp;quot;Auto-Start Feature&amp;quot;&lt;/i&gt; topic in the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677260.aspx"&gt;Windows Server AppFabric&lt;/a&gt; documentation.&lt;/p&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;p&gt;&lt;i&gt;“Configure Auto-Start Using IIS Manager” &lt;/i&gt;topic in the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677285.aspx"&gt;Windows Server AppFabric&lt;/a&gt; documentation.&lt;i&gt;&lt;/i&gt;&lt;/p&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;p&gt;&lt;i&gt;&amp;quot;Configure Auto-Start Using Windows Server AppFabric Cmdlets&amp;quot; &lt;/i&gt;topic in the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677317.aspx"&gt;Windows Server AppFabric&lt;/a&gt; documentation.&lt;i&gt;&lt;/i&gt;&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8267.AutoStartTab_5F00_12621B24.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="AutoStartTab" border="0" alt="AutoStartTab" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6840.AutoStartTab_5F00_thumb_5F00_6417F99C.jpg" width="862" height="662" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;On the &lt;strong&gt;Throttling&lt;/strong&gt; tab, I configured the properties exposed by the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx"&gt;ServiceThrottlingBehavior&lt;/a&gt; used by my WCF workflow service:&lt;/div&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentcalls.aspx"&gt;MaxConcurrentCalls&lt;/a&gt;: specifies the maximum number of messages actively processing across a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx"&gt;ServiceHost&lt;/a&gt;.&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentinstances.aspx"&gt;MaxConcurrentInstances&lt;/a&gt;: specifies the maximum number of &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontext.aspx"&gt;InstanceContext&lt;/a&gt; objects in the service that can execute at one time.&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentsessions.aspx"&gt;MaxConcurrentSessions&lt;/a&gt;: specifies the maximum number of sessions a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx"&gt;ServiceHost&lt;/a&gt; object can accept at one time.&lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2335.ThrottlingTab_5F00_3FFF7282.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="ThrottlingTab" border="0" alt="ThrottlingTab" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5700.ThrottlingTab_5F00_thumb_5F00_5812B710.jpg" width="862" height="662" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4" sizcache="1" sizset="15"&gt;&lt;tbody sizcache="1" sizset="15"&gt;
    &lt;tr sizcache="1" sizset="15"&gt;
      &lt;td valign="top" width="900" sizcache="1" sizset="15"&gt;
        &lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6052.Quotes_5F00_Icon_5F00_69F9A440.gif"&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="Quotes_Icon" border="0" alt="Quotes_Icon" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4863.Quotes_5F00_Icon_5F00_thumb_5F00_5F0C9D2B.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note&amp;#160; &lt;br /&gt;&lt;/strong&gt;The default values for the properties &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentcalls.aspx"&gt;MaxConcurrentCalls&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentinstances.aspx"&gt;MaxConcurrentInstances&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentsessions.aspx"&gt;MaxConcurrentSessions&lt;/a&gt; exposed by the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx"&gt;ServiceThrottlingBehavior&lt;/a&gt; have been increased and made more dynamic as they are based on the number of processors seen by Windows.&lt;/p&gt;

        &lt;table style="width: 500px" border="0" cellspacing="1" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
            &lt;tr bgcolor="#e4e4e4"&gt;
              &lt;td valign="top" width="187"&gt;Property&lt;/td&gt;

              &lt;td valign="top" width="184"&gt;.NET 4.0 Default&lt;/td&gt;

              &lt;td valign="top" width="124"&gt;Previous Default&lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr bgcolor="#ffffff"&gt;
              &lt;td valign="top" width="187"&gt;MaxConcurrentCalls&lt;/td&gt;

              &lt;td valign="top" width="184"&gt;16 * ProcessorCount&lt;/td&gt;

              &lt;td valign="top" width="124"&gt;16&lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr bgcolor="#f8f8f8"&gt;&lt;/tr&gt;

            &lt;tr&gt;
              &lt;td valign="top" width="187"&gt;MaxConcurrentInstances&lt;/td&gt;

              &lt;td valign="top" width="184"&gt;116 * ProcessorCount&lt;/td&gt;

              &lt;td valign="top" width="124"&gt;26&lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr bgcolor="#ffffff"&gt;
              &lt;td valign="top" width="187"&gt;MaxConcurrentSessions&lt;/td&gt;

              &lt;td valign="top" width="184"&gt;100 * ProcessorCount&lt;/td&gt;

              &lt;td valign="top" width="124"&gt;10&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;&lt;/table&gt;

        &lt;p align="justify"&gt;For more information on this topic, see “&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/29/less-tweaking-of-your-wcf-4-0-apps-for-high-throughput-workloads.aspx"&gt;Less tweaking of your WCF 4.0 apps for high throughput workloads&lt;/a&gt;” post on the AppFabric CAT blog.&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Finally I pressed the OK button to confirm settings.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;Then, I opened the &lt;strong&gt;Services&lt;/strong&gt; page, I right-clicked the &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; and I selected &lt;strong&gt;Configure&lt;/strong&gt; from the context menu. On the &lt;strong&gt;Monitoring&lt;/strong&gt; tab, I clicked the Configure button on the right panel and selected the &lt;strong&gt;Troubleshooting Tracking Profile&lt;/strong&gt;. This tracking profile is quite verbose and therefore is particularly helpful when debugging a WF service in testing environment, but it is not recommended in a production, unless you have to investigate and troubleshoot a problem. &lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6472.ServiceMonitoring_5F00_1543460B.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="ServiceMonitoring" border="0" alt="ServiceMonitoring" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6888.ServiceMonitoring_5F00_thumb_5F00_25EAA51F.jpg" width="881" height="668" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;p align="justify"&gt;The following table contains the configuration file of the WCF workflow service after completing these steps.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellspacing="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="900"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.web&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;compilation&lt;/span&gt; &lt;span class="attr"&gt;debug&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;targetFramework&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4.0&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.web&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Transport&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;protectionLevel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netTcpContextBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Transport&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;protectionLevel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netTcpContextBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="rem"&gt;&amp;lt;!-- This client endpoint is used by the WCF workflow service&lt;/span&gt;
&lt;span class="rem"&gt;           to incoke the WCF receive location exposed by the BizTalk --&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;net.tcp://localhost:7171/Magic8BallBizTalk/Sync&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Magic8Ball&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;bizTalkSyncNetTcpBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SyncMagic8Ball&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWF&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding_SyncMagic8Ball&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpContextBinding&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallWF&amp;quot;&lt;/span&gt; 
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding_SyncMagic8Ball&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="rem"&gt;&amp;lt;!-- To avoid disclosing metadata information, set &lt;/span&gt;
&lt;span class="rem"&gt;               the value below to false and remove the metadata &lt;/span&gt;
&lt;span class="rem"&gt;               endpoint above before deployment --&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceMetadata&lt;/span&gt; &lt;span class="attr"&gt;httpGetEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="rem"&gt;&amp;lt;!-- To receive exception details in faults for debugging purposes, &lt;/span&gt;
&lt;span class="rem"&gt;               set the value below to true. Set to false before deployment to &lt;/span&gt;
&lt;span class="rem"&gt;               avoid disclosing exception information --&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceDebug&lt;/span&gt; &lt;span class="attr"&gt;includeExceptionDetailInFaults&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="rem"&gt;&amp;lt;!-- Added by AppFabric Admin Console --&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;workflowInstanceManagement&lt;/span&gt; &lt;span class="attr"&gt;authorizedWindowsGroup&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AS_Administrators&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;workflowUnhandledException&lt;/span&gt; &lt;span class="attr"&gt;action&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AbandonAndSuspend&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;workflowIdle&lt;/span&gt; &lt;span class="attr"&gt;timeToPersist&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:01:00&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;timeToUnload&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:01:00&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceThrottling&lt;/span&gt; &lt;span class="attr"&gt;maxConcurrentCalls&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;maxConcurrentSessions&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;maxConcurrentInstances&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;etwTracking&lt;/span&gt; &lt;span class="attr"&gt;profileName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Troubleshooting Tracking Profile&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceHostingEnvironment&lt;/span&gt; &lt;span class="attr"&gt;multipleSiteBindingsEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.webServer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;modules&lt;/span&gt; &lt;span class="attr"&gt;runAllManagedModulesForAllRequests&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.webServer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h3 align="justify"&gt;&amp;#160;&lt;/h3&gt;

&lt;p align="justify"&gt;It’s probably worth noting that you can manually modifies the configuration file without using the administration extensions provided by &lt;strong&gt;AppFabric&lt;/strong&gt;. However, &lt;strong&gt;AppFabric&lt;/strong&gt; offers a convenient and handy way to accomplish this task.&amp;#160; &lt;/p&gt;

&lt;h3 align="justify"&gt;Testing the Application&lt;/h3&gt;

&lt;p&gt;To test the application, you can proceed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Makes sure to start the &lt;strong&gt;DuplexMEP&lt;/strong&gt; BizTalk application. &lt;/li&gt;

  &lt;li&gt;Open a new instance of the &lt;strong&gt;Client&lt;/strong&gt; Application, as indicated in the picture below. &lt;/li&gt;

  &lt;li&gt;Enter an existential question like &amp;quot;Why am I here?&amp;quot;, &amp;quot;What's the meaning of like?&amp;quot; or &amp;quot;Will the world end in 2012?&amp;quot; in the &lt;strong&gt;Question&lt;/strong&gt; textbox. &lt;/li&gt;

  &lt;li&gt;Select one of &lt;strong&gt;NetTcpEndpointSyncWF &lt;/strong&gt;in the &lt;strong&gt;Endpoint&lt;/strong&gt; drop down list. &lt;/li&gt;

  &lt;li&gt;Specify a &lt;strong&gt;Delay&lt;/strong&gt; in seconds in the corresponding textbox. &lt;/li&gt;

  &lt;li&gt;Press the &lt;strong&gt;Ask&lt;/strong&gt; button. &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-38-83-metablogapi/5736.SyncMagic8BallClient_5F00_2AAD0D41.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SyncMagic8BallClient" border="0" alt="SyncMagic8BallClient" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2211.SyncMagic8BallClient_5F00_thumb_5F00_26CF1CD7.jpg" width="661" height="540" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;Now, if you press the &lt;strong&gt;Ask&lt;/strong&gt; button multiple times in a row, you can easily notice that the client application is called back by the WCF workflow service in an asynchronous way. Therefore, the client application doesn't need to wait for the response to the previous question before posing a new request.&lt;/p&gt;

&lt;p align="justify"&gt;Make some calls and then open the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677236.aspx"&gt;AppFabric Dashboard&lt;/a&gt;. This page is composed of three detailed metrics sections: three detailed metrics sections: &lt;strong&gt;Persisted WF Instances&lt;/strong&gt;, &lt;strong&gt;WCF Call History&lt;/strong&gt;, and &lt;strong&gt;WF Instance History&lt;/strong&gt;. These sections display monitoring and tracking metrics for instances of .NET Framework 4 WCF and WF services. Let’s focus our attention on the &lt;strong&gt;WF Instance History&lt;/strong&gt; section, highlighted in red in the figure below. The latter displays historical statistics derived from tracked workflow instance events stored in one or more Monitoring databases. It can draw data from several monitoring databases, if the server or farm uses more than one monitoring database for services deployed at the selected scope.&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8883.AppFabricDashboardHighlighted_5F00_34618D45.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="AppFabricDashboardHighlighted" border="0" alt="AppFabricDashboardHighlighted" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6763.AppFabricDashboardHighlighted_5F00_thumb_5F00_40AF64D4.jpg" width="860" height="710" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;If you click the &lt;strong&gt;Completions&lt;/strong&gt; link you can review WF instances that completed in the selected period of time. You can use the &lt;strong&gt;Query&lt;/strong&gt; control on the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677287(v=MSDN.10).aspx"&gt;Tracked WF Instances Page&lt;/a&gt; to run a simple query and restrict the number of rows displayed in the grid below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4130.TrackedWFInstances_5F00_64E42389.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="TrackedWFInstances" border="0" alt="TrackedWFInstances" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8054.TrackedWFInstances_5F00_thumb_5F00_02C1E5E4.jpg" width="860" height="706" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, you can right-click one of the completed WF instances and select &lt;strong&gt;View Tracked Events&lt;/strong&gt; to access the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677338(v=MSDN.10).aspx"&gt;Tracked Events Page&lt;/a&gt; where you can examine events generated by WCF and WF services. Here, you can group events by &lt;strong&gt;Event Type&lt;/strong&gt;, as shown in the figure below, and analyze the user-defined events emitted by the current WCF instance using the &lt;strong&gt;CustomTrackingActivity &lt;/strong&gt;that we saw at the beginning of this article.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4760.TrackedUserDefinedEvents_5F00_409B2B08.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="TrackedUserDefinedEvents" border="0" alt="TrackedUserDefinedEvents" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3036.TrackedUserDefinedEvents_5F00_thumb_5F00_46C1B5FC.jpg" width="860" height="810" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In particular, you can quickly investigate the details of a selected event in the &lt;strong&gt;Details&lt;/strong&gt; pane, as highlighted in red in the figure above. &lt;/p&gt;

&lt;h3&gt;Conclusions&lt;/h3&gt;

&lt;p align="justify"&gt;In this article we have seen how to exchange messages with a WCF workflow service running in IIS\AppFabric using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee358740.aspx"&gt;Durable Duplex Correlation&lt;/a&gt; and a context binding. We have also seen how to create a custom activity to emit user-defined events and how to to use the using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee677236.aspx"&gt;AppFabric Dashboard&lt;/a&gt; to monitor custom tracking events generated by WF services. Finally we have seen how the &lt;strong&gt;Mapper&lt;/strong&gt; activity provided by &lt;a href="http://www.microsoft.com/biztalk/en/us/appfabricconnect.aspx"&gt;AppFabric Connect&lt;/a&gt; to implement message transformations in a WCF workflow service. This component not only allows to implement message transformations in a easy way in any WF project, but it allows developers to reuse maps from existing BizTalk application in an AppFabric solution. In the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2011/01/20/how-to-use-duplex-mep-to-communicate-with-biztalk-from-a-net-application-or-a-wf-workflow-running-inside-appfabric-part-3.aspx"&gt;final part&lt;/a&gt; of this article, we’ll see how to implement an asynchronous communication between a &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx"&gt;WCF Workflow Service&lt;/a&gt; and an Orchestration using WS-Addressing and &lt;a href="http://msdn.microsoft.com/en-us/library/ee358755.aspx"&gt;Content-Based Correlation&lt;/a&gt;. In the meantime, &lt;a href="http://cid-09dba4a06b360a65.office.live.com/self.aspx/Pubblica/DuplexMEP.zip?wa=wsignin1.0&amp;amp;sa=360367418"&gt;here&lt;/a&gt; you can download the companion code for this article. As always, your feedbacks are more than welcome!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10104176" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/BizTalk/">BizTalk</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Best+Practices/">Best Practices</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/WF/">WF</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/-NET4/">.NET4</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Correlation/">Correlation</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Mapper/">Mapper</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric+Connect/">AppFabric Connect</category></item></channel></rss>