<?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 Community 5.6.583.19199 (Build: 5.6.583.19199)</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>0</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/ff963564.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><item><title>AD FS 2.0 to secure WCF and Workflow Services hosted in Windows Server AppFabric</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/14/ad-fs-2-0-to-secure-wcf-and-workflow-services-hosted-in-windows-server-appfabric.aspx</link><pubDate>Wed, 15 Dec 2010 04:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10105114</guid><dc:creator>SurenM</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10105114</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10105114</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/14/ad-fs-2-0-to-secure-wcf-and-workflow-services-hosted-in-windows-server-appfabric.aspx#comments</comments><description>&lt;p&gt;&lt;span style="font-family: 'Segoe UI','sans-serif'; font-size: 8pt;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;This blog entry is a sequel to the October 30th Blog &amp;ldquo;&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/30/securing-wcf-services-hosted-in-windows-server-appfabric-with-windows-identity-foundation-wif.aspx"&gt;Securing WCF Services hosted in Windows Server AppFabric with Windows Identity Foundation (WIF)&lt;/a&gt;&amp;rdquo; where we demonstrated how to use WIF to secure Services hosted in AppFabric.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;And in this blog post we extend the same scenario to demonstrate how you can leverage Active Directory Federation Services 2.0 (&lt;a href="http://msdn.microsoft.com/en-us/magazine/ee335705.aspx"&gt;&lt;span style="color: #0000ff;"&gt;AD FS 2.0&lt;/span&gt;&lt;/a&gt;) to provide you a solution for your &amp;lsquo;&lt;a href="http://en.wikipedia.org/wiki/Federated_identity"&gt;&lt;span style="color: #0000ff;"&gt;federated identity&lt;/span&gt;&lt;/a&gt;&amp;rsquo; needs.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;The AD FS approach also provides you the solution that mitigates security risks (by using ActAs delegation) and authorizes access through all three tiers: the client, the middle tier (e.g., AppFabric hosted Services) to the data tier (e.g., databases) &amp;ndash; we will cover this too. &lt;/span&gt;&lt;/h2&gt;
&lt;p class="MsoNoSpacing"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;This blog is targeted towards both the architect and developer community. The blog demonstrates how you can apply AD FS 2.0 into your architecture to provide federated identity solution and provides adequate details for you to attempt it in your project. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 class="MsoNoSpacing" style="MARGIN: 0in 0in 0pt"&gt;AD FS 2.0&lt;/h2&gt;
&lt;p class="MsoNoSpacing"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;AD FS 2.0 is a Server Role within Windows Server that provides support for &lt;a href="file:///C:/Users/surenm/AppData/Local/Microsoft/Windows/Temporary%20Internet%20Files/Content.Outlook/GNBL4JU9/msdn.microsoft.com/en-us/library/bb498017.aspx"&gt;&lt;span style="color: #0000ff;"&gt;WS-Federation&lt;/span&gt;&lt;/a&gt;, &lt;a href="file:///C:/Users/surenm/AppData/Local/Microsoft/Windows/Temporary%20Internet%20Files/Content.Outlook/GNBL4JU9/channel9.msdn.com/shows/Going+Deep/Vittorio-Bertocci-WS-Trust-Under-the-Hood"&gt;&lt;span style="color: #0000ff;"&gt;WS-Trust&lt;/span&gt;&lt;/a&gt; and &lt;a href="file:///C:/Users/surenm/AppData/Local/Microsoft/Windows/Temporary%20Internet%20Files/Content.Outlook/GNBL4JU9/msdn.microsoft.com/en-us/library/ms733083.aspx"&gt;&lt;span style="color: #0000ff;"&gt;SAML&lt;/span&gt;&lt;/a&gt;, with an easy to use management UI and a powerful claims processing rules engine. In a nutshell, it allows you to register your applications (Relying Parties), Claims Providers (e.g., other STS&amp;rsquo;s) and Attribute Stores (Identity Providers like Active Directory), and define the rules that govern how incoming claims are mapped to claims your application expects. The Figure 1 below illustrates these major features.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;span style="mso-no-proof: yes;"&gt;&lt;o:p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/2570.Figure-1.png" border="0" /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;span style="mso-no-proof: yes;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoCaption"&gt;&lt;strong&gt;&lt;span style="color: #4f81bd;"&gt;Figure &lt;span style="mso-no-proof: yes;"&gt;1&lt;/span&gt;: Major Features of AD FS 2.0 (Source MSDN.com)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;One the biggest advantages you&amp;rsquo;ll notice almost immediately when getting started with AD FS is that you now have that &amp;ldquo;missing UI&amp;rdquo; for &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd347547.aspx"&gt;&lt;span style="color: #0000ff;"&gt;Security Token Service&lt;/span&gt;&lt;/a&gt; (STS) configuration that you don&amp;rsquo;t get when using the STS templates provided by Visual Studio.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Build Out &lt;/h2&gt;
&lt;p class="MsoNormal"&gt;You can download AD FS 2.0 from &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=118c3588-9070-426a-b655-6cec0a92c10b&amp;amp;displaylang=en"&gt;&lt;span style="color: #0000ff;"&gt;here&lt;/span&gt;&lt;/a&gt;. In order to make use of AD FS 2.0 for our scenario, you will also need the following (see the Additional Resources for links):&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst"&gt;&lt;span style="line-height: 115%; font-family: Symbol; font-size: 10pt; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.0pt;"&gt;&lt;span style="mso-list: Ignore;"&gt;&amp;middot;&lt;span style="font: 7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="line-height: 115%; font-size: 10pt; mso-bidi-font-size: 9.0pt;"&gt;&lt;a href="http://www.microsoft.com/windowsserver2008/en/us/ad-main.aspx"&gt;&lt;span style="line-height: 115%; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;span style="color: #0000ff;"&gt;Active Directory&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="line-height: 115%; font-family: Symbol; font-size: 10pt; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.0pt;"&gt;&lt;span style="mso-list: Ignore;"&gt;&amp;middot;&lt;span style="font: 7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="line-height: 115%; font-size: 10pt; mso-bidi-font-size: 9.0pt;"&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=eb9c345f-e830-40b8-a5fe-ae7a864c4d76&amp;amp;displaylang=en"&gt;&lt;span style="line-height: 115%; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;span style="color: #0000ff;"&gt;WIF &amp;ndash; Windows Identity Foundation&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c148b2df-c7af-46bb-9162-2c9422208504&amp;amp;displaylang=en"&gt;&lt;span style="line-height: 115%; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;span style="color: #0000ff;"&gt;WIF .NET 4 SDK&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;. &lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast"&gt;&lt;span style="line-height: 115%; font-family: Symbol; font-size: 10pt; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.0pt;"&gt;&lt;span style="mso-list: Ignore;"&gt;&amp;middot;&lt;span style="font: 7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="line-height: 115%; font-size: 10pt; mso-bidi-font-size: 9.0pt;"&gt;&lt;a href="http://www.microsoft.com/visualstudio/en-us/"&gt;&lt;span style="line-height: 115%; font-size: 9pt; mso-bidi-font-size: 8.0pt;"&gt;&lt;span style="color: #0000ff;"&gt;Visual Studio 2010&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;To set up a test lab environment for this, the easiest approach is to have &lt;a href="http://technet.microsoft.com/en-us/library/adfs2-federation-wif-application-step-by-step-guide(WS.10).aspx"&gt;&lt;span style="line-height: 115%; font-size: 8pt;"&gt;&lt;span style="color: #0000ff;"&gt;two VPC&amp;rsquo;s&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;. One that only runs your Active Directory and the other that is joined to the former&amp;rsquo;s domain, and has AD FS 2.0, WIF, and VS2010 installed.&lt;/p&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Lab Setup&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;In authoring this blog entry, we used a lab environment configured with two VPC&amp;rsquo;s.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Step-by-step guidance on setting up the AD FS 2.0 test lab is available in the &amp;lsquo;references&amp;rsquo; &amp;ndash; the last section on this blog.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;Both these VPCs use a base Windows Server 2008 &lt;span style="mso-bidi-font-weight: bold;"&gt;with Service Pack 2; details around these VPCs along with some major &amp;lsquo;steps&amp;rsquo; are below: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="mso-bidi-font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpFirst"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;VPC 1: FSAD &amp;ndash; Domain Controller&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Add Domain Controller role: This will installs DNS&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Automatically and assign this machine a static IP address.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;VPC2: FSWEB &amp;ndash; AD FS Server &amp;amp; Development environmen&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="mso-bidi-font-weight: bold;"&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Install .NET 3.5 SP1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Assign this machine a static IP address&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Join domain; install AD FS 2 in federation server mode &amp;ndash; this will install IIS&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; mso-fareast-font-family: 'Courier New';"&gt;&lt;span style="mso-list: Ignore;"&gt;&lt;span style="font: 7pt 'Times New Roman';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Install VS 2010 (installs .NET 4).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Create a self-signed SSL certificate.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Register HTTPS binding on Default Web Site to use the self-signed cert.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Complete AD FS Config Wizard selecting Stand-alone server option.&lt;/span&gt;&lt;/span&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Note: Before&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt; running on Server 2008 (not needed for R2) you need to add the&amp;nbsp;entry below (or the service will fail to start) to Microsoft.IdentityServer.Servicehost.exe.config file, located in the ADFS 2 install directory (default C:\Program Files\Active Directory Federation Services 2.0).&lt;br /&gt;&amp;nbsp; &amp;lt;runtime&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;generatePublisherEvidence enabled="false"/&amp;gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&amp;nbsp; &amp;lt;/runtime&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-fareast-font-family: 'Times New Roman';"&gt;&lt;span style="font-family: Segoe UI;"&gt;Install WIF SDK (run as admin, be patient before clicking next on license screen, if it says please wait while computing disk space, restart computer and try again, waiting slightly longer).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style="MARGIN: 10pt 0in 6pt"&gt;&lt;/h2&gt;
&lt;h2 style="MARGIN: 10pt 0in 6pt"&gt;Scenario&amp;nbsp;&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;This blog builds upon the scenario presented in the previous blog (&lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/30/securing-wcf-services-hosted-in-windows-server-appfabric-with-windows-identity-foundation-wif.aspx"&gt;&lt;span style="line-height: 115%; font-size: 8pt;"&gt;&lt;span style="font-family: Segoe UI;"&gt;Securing WCF Services hosted in Windows Server AppFabric with Windows Identity Foundation (WIF)&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Segoe UI;"&gt;) which used a custom STS solution; this current blog will use AD FS 2.0 as the enterprise-grade STS. Figure 2 below provides a quick comparison of the scenarios in both the blogs &amp;ndash;you will notice the big difference is previously we used a custom STS and this time around we used AD FS 2.0. With the release of AD FS2.0, we expect larger number of deployments taking a dependency on AD FS 2.0.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;The coolest part about swapping in AD FS 2.0 from the previous scenario is that there are no have no code changes to make &amp;ndash; all that was needed was a bit of configuration and this is what we will demonstrate in this blog. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/3652.Figure-2.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/5481.Figure-3.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoCaption"&gt;&lt;strong&gt;&lt;span style="font-family: Segoe UI; color: #4f81bd;"&gt;Figure &lt;span style="mso-no-proof: yes;"&gt;2&lt;/span&gt;&lt;span style="mso-no-proof: yes;"&gt; a and b&lt;/span&gt;: Contrast scenarios using Custom STS (top) with current scenario of using AD FS 2.0 (bottom). &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;For this blog scenario we will update our architecture so that it leverages AD FS 2.0 as the STS, so that you are able to learn how to abstract usage of Identity Stores (referred to as Attribute Stores in AD FS interfaces) behind the STS using AD FS 2.0. Identity Stores could be Active Directory, MS SQL, LDAP, or any other custom provider. Subsequently in this blog posting we will also enhance the scenario presented to demonstrate integration of Microsoft SQL Server with Active Directory to append other identity related information to the claims.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;The blog will also show to configure AD FS using its management MMC UI to configure the claims issuance rules for our applications, as well enabling &lt;/span&gt;&lt;a href="http://technet.microsoft.com/en-us/library/adfs2-identity-delegation-step-by-step-guide(WS.10).aspx"&gt;&lt;span style="line-height: 115%; font-size: 8pt;"&gt;&lt;span style="font-family: Segoe UI; color: #0000ff;"&gt;ActAs delegation&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Segoe UI;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;h2 style="MARGIN: 24pt 0in 6pt"&gt;Implementation&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;In showing how to implement the scenario, we will start with the finished version of the &lt;/span&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Components-PostAttachments/00-10-08-35-43/WIFSecuringAF-_2D00_-Dev-STS-ActAs-w-AuthorizationMgr.zip"&gt;&lt;span style="line-height: 115%; font-size: 8pt;"&gt;&lt;span style="font-family: Segoe UI; color: #0000ff;"&gt;Visual Studio solution&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Segoe UI;"&gt; we described in the previous blog posting and show how we can enhance it to leverage federated security, delegation and AD FS 2.0. To accomplish this we need will setup RulesEngine to use AD FS and configure AD FS to secure it; repeat this for the ComputationWorkflows project; and update the service references and related configuration in the RulesEngine and the DataWizApp. Figure 3, below shows our new implementation approach.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/3730.Figure-3.png" border="0" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoCaption"&gt;&lt;strong&gt;&lt;span style="font-family: Segoe UI; color: #4f81bd;"&gt;Figure &lt;span style="mso-no-proof: yes;"&gt;3&lt;/span&gt;: Using AD FS 2.0 STS to secure Services&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h3 class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;Securing the RulesEngine with AD FS&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;To enable RulesEngine to use AD FS instead of the development STS, we run FedUtil, via &lt;i style="mso-bidi-font-style: normal;"&gt;Add STS Reference&lt;/i&gt; again. The key difference this time is the address we use for the federation metadata is on the Security Token Service screen we use the address of AD FS instead of the development STS. The following screens show the entire process.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/3122.figure-4.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/7127.figure-5.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/2045.figure-6.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/0675.figure-7.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/4718.figure-8.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/8306.figure-9.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoCaption"&gt;&lt;strong&gt;&lt;span style="font-family: Segoe UI; color: #4f81bd;"&gt;Figure 4 to 9: Configuration Changes&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;The above configuration changes will take care of updating the RulesEngine web.config so that it calls AD FS during authentication. &lt;/span&gt;&lt;/p&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Modifications to Web.Config files&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;We have two more modifications to make in web.config. We need to configure service clients (like DataWiz and RulesEngine) to request the desired claims; these claims are expressed in web.config. AD FS will only provide requested tokens, unlike our Dev STS which doesn't care and always sends the same set of tokens. In our scenario, FedUtil by default requests Name and Role, but we must manually request CanLoadData. This amounts to editing the custom binding added by FedUtil, and adding that claim to &lt;i style="mso-bidi-font-style: normal"&gt;system.serviceModel\bindings\customBinding\binding\security\secureConversationBootstrap\issuedTokenParameters\additionalRequestParameters\SecondaryParamaters\Claims &lt;/i&gt;as shown below:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;issuedTokenParameters&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;keySize&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;256&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;keyType&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SymmetricKey&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;tokenType&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;""&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;additionalRequestParameters&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:SecondaryParameters&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:KeyType&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;trust:KeyType&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:KeySize&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;256&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;trust:KeySize&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:Claims&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;Dialect&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://schemas.xmlsoap.org/ws/2005/05/identity&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;wsid:ClaimType&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;Uri&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;Optional&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;xmlns:wsid&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;http://schemas.xmlsoap.org/ws/2005/05/identity&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;wsid:ClaimType&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;Uri&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://schemas.microsoft.com/ws/2008/06/identity/claims/role&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;Optional&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;xmlns:wsid&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;http://schemas.xmlsoap.org/ws/2005/05/identity&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="background: yellow; mso-highlight: yellow;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;wsid:ClaimType&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;Uri&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;"&lt;span style="color: blue;"&gt;http://contoso.com/claims/canloaddata&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;Optional&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;xmlns:wsid&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;"&lt;span style="color: blue;"&gt;http://schemas.xmlsoap.org/ws/2005/05/identity&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:Claims&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:KeyWrapAlgorithm&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;trust:KeyWrapAlgorithm&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:EncryptWith&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;http://www.w3.org/2001/04/xmlenc#aes256-cbc&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;trust:EncryptWith&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:SignWith&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;http://www.w3.org/2000/09/xmldsig#hmac-sha1&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;trust:SignWith&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:CanonicalizationAlgorithm&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;http://www.w3.org/2001/10/xml-exc-c14n#&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;trust:CanonicalizationAlgorithm&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:EncryptionAlgorithm&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;xmlns:trust&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;http://www.w3.org/2001/04/xmlenc#aes256-cbc&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;trust:EncryptionAlgorithm&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;trust:SecondaryParameters&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;additionalRequestParameters&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="background: yellow; mso-highlight: yellow;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;issuer&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;address&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; background: yellow; font-size: 8pt; mso-bidi-font-size: 9.5pt; mso-highlight: yellow;"&gt;"&lt;span style="color: blue;"&gt;https://fsweb.contoso.com/adfs/services/trust/13/kerberosmixed&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;https://fsweb.contoso.com/adfs/services/trust/13/kerberosmixed&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;binding&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;customBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;issuerMetadata&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="font-family: Consolas; color: red; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;address&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;https://fsweb.contoso.com/adfs/services/trust/mex&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-family: Consolas; color: #a31515; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;issuedTokenParameters&lt;/span&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="font-family: Segoe UI; color: #000000; font-size: x-small;"&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: Consolas; color: blue; font-size: 8pt; mso-bidi-font-size: 9.5pt;"&gt;&lt;span style="font-family: Segoe UI; color: #000000; font-size: x-small;"&gt;In addition, AD FS exposes multiple service endpoints and when FedUtil runs, it basically chooses the first endpoint which is a certificate based one.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Since we are using Windows domain credentials, we need to use a Kerberos endpoint. These endpoints are all listed in the web.config commented out under an &lt;i style="mso-bidi-font-style: normal"&gt;alternativeIssuedTokenParameters&lt;/i&gt; section, you just need to remove the one that&amp;rsquo;s within the &lt;i style="mso-bidi-font-style: normal"&gt;issuedTokenParameters&lt;/i&gt; section and replace it with one of the others from the commented region. The second highlighted line in the config above shows the updated endpoint in place.&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Configuring AD FS for Securing the Solution&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Now that we&amp;rsquo;ve configured the RulesEngine to use ADFS, we need to tell ADFS about the RulesEngine. To do this we open the AD FS 2.0 Management Snap-in from &lt;i style="mso-bidi-font-style: normal;"&gt;Start Menu-&amp;gt;Administrative Tools-&amp;gt;AD FS 2.0 Management.&lt;/i&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;In the tree view we expand the &lt;b style="mso-bidi-font-weight: normal;"&gt;Trust Relationships&lt;/b&gt; node and then right-click the &lt;b style="mso-bidi-font-weight: normal;"&gt;Relying Party Trusts&lt;/b&gt; node, selecting &lt;b style="mso-bidi-font-weight: normal;"&gt;Add Relying Party Trust&lt;/b&gt;&amp;hellip; which loads wizard of the same name.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;We click &lt;b style="mso-bidi-font-weight: normal;"&gt;Start&lt;/b&gt; past the welcome screen:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/8547.figure-10.png" border="0" /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;On the &lt;b style="mso-bidi-font-weight: normal;"&gt;Select Data Source&lt;/b&gt; screen, we can simply import the Federation Metadata requirements of the RulesEngine from a file (since we are not using HTTPS to host the RulesEngine, the first radio is not an option).&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;As you can see in the screenshot, the FederationMetadata.xml documentforRulesEngine is located under the RulesEngine project. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/5280.figure-11.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;span style="font-family: Segoe UI;"&gt;Next you enter a user friendly display name and any notes.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/0552.figure-12.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Then, by default we don&amp;rsquo;t want to perform any authorization at the ADFS STS, so we just leave the Permit all option selected.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/5148.figure-13.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;You can review the various settings pulled in from the FederationMetadata and your selections on the following screen.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/7077.figure-14.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;You will then be prompted with the &lt;b style="mso-bidi-font-weight: normal;"&gt;Edit Claims Rules&lt;/b&gt; screen, which you&amp;rsquo;ll want to display to configure how claims are issued from ADFS for the RulesEngine. In our scenario, we need to define rules to issue three claims: Name, Role and CanLoadData. We will also define a fourth, DOB, to show how we can obtain values from claims from attribute stores other than Active Directory. The following screenshot shows our Issuance Transform Rules with all claims added; we will then see how we configure the Name, Role and CanLoadData claims (the first three in the screenshot). We&amp;rsquo;ll return to showing how we add the DOB claim at the end of this blog post.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/4213.figure-15.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Let&amp;rsquo;s start with the Name claim. Here we receive the name via the presented Windows credentials, so we just need to pass it through. To create such a rule, click &lt;b style="mso-bidi-font-weight: normal;"&gt;Add Rule&lt;/b&gt;&amp;hellip; and the in the Claim rule template select &lt;i style="mso-bidi-font-style: normal;"&gt;Pass Through or Filter and Incoming Claim&lt;/i&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/3223.figure-16.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Click &lt;b style="mso-bidi-font-weight: normal;"&gt;Next&lt;/b&gt;. Enter a user friendly description for the rule. Because we are after the incoming Name claim, select that in the first drop down and leave Pass through all claim values selected. Your screen should look as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/2055.figure-17.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Clicking &lt;b style="mso-bidi-font-weight: normal;"&gt;Finish&lt;/b&gt; will add the rule to the Issuance Transform Rules listing, but more importantly results in the Name claim being properly forwarded from the AppWiz client to the RulesEngine. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Next, let&amp;rsquo;s see how we add the Role claim that always provides a value of &amp;ldquo;AuthenticatedUsers&amp;rdquo;. Again, we click Add Rule&amp;hellip; here we simply want to issue a new Role claim (we don&amp;rsquo;t want to pass through or transform the existing one). The only way to issue a completely new claim is to use a Custom Rule. So in the Claim rule template, select &lt;i style="mso-bidi-font-style: normal;"&gt;Send Claims Using a Custom Rule&lt;/i&gt; and click next.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/0044.figure-18.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;All rules that you configure through the rule templates are ultimately expressed in this rule syntax (see the Additional References section for details on the syntax).&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;span style="font-family: Segoe UI;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/p&gt;
&lt;div style="padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: #eaf1dd; margin-left: 7.1pt; margin-right: 0in; padding-top: 1pt; mso-background-themecolor: accent3; mso-background-themetint: 51; mso-element: para-border-div; border: #999999 1.5pt solid;"&gt;
&lt;p class="ppNote"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Note:&lt;/b&gt; A quick point, for any rule you&amp;rsquo;ve configured that&amp;rsquo;s not a Custom Rule, you can edit it and click View Rule Language&amp;hellip; to see it- this is a great way to bootstrap your custom rule authoring.&amp;nbsp;&lt;/span&gt;&lt;o:p&gt;&lt;span style="font-family: Segoe UI;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Here we write a custom rule, that basically reads irrespective of any incoming claim (the condition that would normally be to the left of the =&amp;gt; is empty means this), create and output to the claimset a new claim with the &amp;ldquo;role&amp;rdquo; type and a value of &amp;ldquo;AuthenticatedUsers&amp;rdquo;. Clicking Finish adds this rule and now we have our second claim being issued.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/3441.figure-19.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;The third claim we add is for CanLoadData. Recall users who belong to the SeniorManagers Windows group should get this claim with a value of true. To add this rule, again we begin by clicking Add Rule&amp;hellip;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;this time selecting &lt;i style="mso-bidi-font-style: normal;"&gt;Send Group Membership as a Claim&lt;/i&gt; as and clicking Next.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/1447.figure-20.png" border="0" /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Now we give the rule a friendly name, select the SeniorManager group from AD, specify that the outgoing claim type is canloaddata and give it a value of true as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/5734.figure-21.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;After clicking Finish, we have our third rule in place. Now SeniorManagers will automatically get the canloaddata claim as expected by our scenario.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Back on the Edit Claims Rules for RulesEngine screen, if you click the Issuance Authorization Rules tab you should see this single rule called &lt;i style="mso-bidi-font-style: normal"&gt;Permit Access to All Users&lt;/i&gt;. This is what we want, as we don&amp;rsquo;t want to perform any authorization at the STS in our scenario (we just want it to authenticate).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;We could add similar rules here that control if a user is even granted tokens to present to the RulesEngine.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Securing the ComputationWorkflows with AD FS&amp;nbsp;&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Securing the ComputationWorkflows project happens in a way similar to what we did for the RulesEngine. We add an STS Reference to AD FS from the ComputationWorkflows project, this time using the address for the LoadService.xamlx as the value of the Application URI in the first screen of FedUtil. Incidentally, this actually ends up taking care of both services because the service endpoints are not explicitly described in the web.config as it uses a protocolMapping. We run through the rest of FedUtil following exactly the same steps as we did for RulesEngine.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Next, we need to register the ComputationWorkflows application with ADFS.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;We add the Relying Party Trust as previously described, but this time use the FederationMetada.xml located under the ComputationWorkflows project. We then create the following issuance rules:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/2818.figure-22.png" border="0" /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;The first three are exactly the same as those we added to RulesEngine. The fourth one is new. This one is responsible for taking the CanLoadData claim acquired and passed down by the RulesEngine and passing it thru to the ComputationWorkflows when it performs the ActAs delegated call.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;This rule uses the &lt;i style="mso-bidi-font-style: normal;"&gt;Pass Through or Filter an Incoming Claim&lt;/i&gt; rule template and is configured as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/4572.figure-23.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Just as for the RulesEngine, we don&amp;rsquo;t specify any authorization at the STS, so our Issuance Authorization Rules tab contains just the single &lt;i style="mso-bidi-font-style: normal;"&gt;Permit Access to All Users&lt;/i&gt; entry.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Now, the ComputationWorkflow has a unique requirement because it is the target of invocations that use delegated, ActAs credentials. By default, delegation is disabled. In order to allow it, on the Delegation Authorization Rules tab, we click Add Rule&amp;hellip; and select Permit All Users in the drop down and click Next.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/0636.figure-24.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Clicking Finish will allow any callers to use delegated credentials. In the real world, you will likely choose a specific account that is allowed to perform delegation (such as NETWORK SERVICE) and then specify a &lt;i style="mso-bidi-font-style: normal"&gt;Permit or Deny Users Based on an Incoming Claim&lt;/i&gt; rule template that checks for that account name.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;With that we have fully configured AD FS for both services, now we just need to update the service references so the clients know to authenticate against AD FS.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Update the Service References in the RulesEngine&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;First, in Visual Studio, from the RulesEngine project update the service reference to the Load service so that it gets the new federation settings. We need to adjust web.config so that the Download endpoint uses the same settings as were automatically applied to Load when we updated the service reference.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Open web.config and update the client endpoint for the Download service. Change the binding to &lt;i style="mso-bidi-font-style: normal"&gt;custom&lt;/i&gt; and the bindingConfiguration value so it uses the same configuration name as Load. Here&amp;rsquo;s an example:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;system.serviceModel&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;client&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;endpoint&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt; &lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;address&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;"&lt;span style="COLOR: blue"&gt;http://localhost/ComputationWorkflows/DownloadService.xamlx&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; BACKGROUND: yellow; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt; mso-highlight: yellow"&gt;binding&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; BACKGROUND: yellow; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt; mso-highlight: yellow"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; BACKGROUND: yellow; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt; mso-highlight: yellow"&gt;"&lt;span style="COLOR: blue"&gt;customBinding&lt;/span&gt;"&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt; &lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; BACKGROUND: yellow; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt; mso-highlight: yellow"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; BACKGROUND: yellow; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt; mso-highlight: yellow"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; BACKGROUND: yellow; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt; mso-highlight: yellow"&gt;"&lt;span style="COLOR: blue"&gt;WS2007FederationHttpBinding_IService2&lt;/span&gt;"&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;contract&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;"&lt;span style="COLOR: blue"&gt;Download.IService&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;WS2007FederationHttpBinding_IService&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;identity&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;certificate&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt; &lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;encodedValue&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;"&lt;span style="COLOR: blue"&gt;&amp;hellip;&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;identity&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;endpoint&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;endpoint&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt; &lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;address&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;"&lt;span style="COLOR: blue"&gt;http://localhost/ComputationWorkflows/LoadService.xamlx&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;binding&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;"&lt;span style="COLOR: blue"&gt;customBinding&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;WS2007FederationHttpBinding_IService2&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;contract&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;"&lt;span style="COLOR: blue"&gt;Load.IService&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;WS2007FederationHttpBinding_IService1&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;identity&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;certificate&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt; &lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: red; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;encodedValue&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;=&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;"&lt;span style="COLOR: blue"&gt;&amp;hellip;&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;identity&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;endpoint&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: #a31515; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;client&lt;/span&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 8pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-font-size: 9.5pt"&gt;&lt;/span&gt;&lt;o:p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/p&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Update the DataWizApp client's Service Reference&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Simply update service reference on Contoso (rules engine) and the app.config is updated for federation with AD FS.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Because this client will need to also request CanLoadData, add the canloaddata claim to the requested claims and select the Kerberos ADFS endpoint(by modifying the SecondaryParameters Claims collection in the custom binding as we had shown previously when we configured the RulesEngine to use AD FS).&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 class="MsoNormal" style="MARGIN: 0in 0in 6pt"&gt;Integrating AD FS with other data stores: Provide additional claim information in the form of attributes acquired from Microsoft SQL Server. Extra Credit &lt;span style="FONT-FAMILY: Wingdings; mso-ascii-font-family: 'Segoe UI'; mso-hansi-font-family: 'Segoe UI'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;J&lt;/span&gt;&lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;While Active Directory might store organization and contact information, it would not likely store other user information such as preferences, favorites, authorized working hours or similar items useful to the application. Here we show how we can leverage multiple attribute stores simultaneously (e.g., Active Directory &amp;amp; SQL) from ADFS to provide richer claims about the identity.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;For simplicity we will use the following database create in our local copy of SQL Express. It contains a single table called Users, which itself has three columns: Id, Name and DOB: &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;/****** Object:&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Table [dbo].[Users]&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Script Date: 12/11/2010 14:27:05 ******/&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;IF&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type in (N'U'))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;DROP TABLE [dbo].[Users]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;/****** Object:&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Table [dbo].[Users]&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Script Date: 12/11/2010 14:27:05 ******/&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;SET ANSI_NULLS ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;SET QUOTED_IDENTIFIER ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type in (N'U'))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;CREATE TABLE [dbo].[Users](&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[Id] [int] IDENTITY(1,1) NOT NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[Name] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[DOB] [date] NOT NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;SET IDENTITY_INSERT [dbo].[Users] ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;INSERT [dbo].[Users] ([Id], [Name], [DOB]) VALUES (3, N'CONTOSO\John Doe', CAST(0xDF080B00 AS Date))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;INSERT [dbo].[Users] ([Id], [Name], [DOB]) VALUES (4, N'CONTOSO\Jane Doe', CAST(0x3F080B00 AS Date))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-size: 8pt; mso-bidi-font-size: 11.0pt;"&gt;&lt;span style="font-family: Calibri;"&gt;SET IDENTITY_INSERT [dbo].[Users] OFF&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;You may want to add additional records that match the names of users you will test with.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;After creating the database, you need to create a login for Network Service (or the account under which AD FS is running) and give it database owner permissions (a little overkill, but for simplicities sake).&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Now we can look at what it takes to configure AD FS to query the Users table.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;First we need to register the database by adding a SQL Attribute Store. Within the AD FS 2.0 MMC, right-click the Attribute Stores folder and select Add Attribute Store&amp;hellip; in the dialog that appear provide a user friendly display name, select SQL as the Attribute store type and enter the connection string and click OK:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/0574.figure-25.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Now we can access this DB for querying from our claims issuance rules, so let&amp;rsquo;s add a rule that adds the DOB value queried for the user from the Users table to the set of emitted claims. For RulesEngine, add custom rule that looks up DateOfBirth DOB. To do this, go to the Relying Party Trusts folder. Right-click on the RulesEngine entry and select Edit claims rules&amp;hellip; on the Issuance Transform Rules tab click Add Rule&amp;hellip; IN the first dialog, select the &lt;i style="mso-bidi-font-style: normal;"&gt;Send Claims Using a Custom Rule&lt;/i&gt; template (queries to other Attribute Stores always use custom rules) and click Next.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Define the rule as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/7462.figure-26.png" border="0" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;Notice the syntax for the &lt;i style="mso-bidi-font-style: normal;"&gt;query&lt;/i&gt; parameter in the issue statement is parameterized to use the value of the incoming Name claim in an approach similar to String.Format(). Note that the parameter {0} is not surrounded by single quotes as you might be inclined to do&amp;hellip;adding these quotes will generate an error. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;There are a few items to point out when writing a custom rule for this. First, in the select statement a column maps to a claim type (where the &lt;i style="mso-bidi-font-style: normal;"&gt;types&lt;/i&gt; parameter in the rule lists out the types in order).&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Returning multiple rows results in multiple claim values for that claim type.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;In our case, we have only one column and one row, so we emit exactly one claim of the DOB type with the value of the DOB field in the database. The second gotcha, is that all values must of a string form (e.g., varchar, char, text, etc) which is why in the above we needed to cast DOB because in the database is stored as a Date.&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Finally, the value set for the &lt;i style="mso-bidi-font-style: normal;"&gt;store&lt;/i&gt; parameter is the Display Name you entered when you registered the new Attribute Store.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;With this rule in place, you can access the DOB claim in service code as you would any other (e.g., Service.svc.cs), even within a workflow service (following the steps we showed in the first blog entry)!&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;Conclusion&lt;/h2&gt;
&lt;p class="ppBodyText"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 8pt;"&gt;In conclusion, you saw how it was possible to replace a custom STS solution with AD FS 2.0 that that was needed to do so was configuration changes. And more importantly we also demonstrated how easy it is to integrate data from other stores to provide other claim data/attributes. I do hope this blog post series helped you with your architectural decisions around securing Services hosted by Windows Server AppFabric. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;Additional Resources&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;&lt;span style="font-family: Segoe UI;"&gt;Prequel Blog - &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/30/securing-wcf-services-hosted-in-windows-server-appfabric-with-windows-identity-foundation-wif.aspx"&gt;&lt;span style="color: windowtext; text-decoration: none; text-underline: none;"&gt;&lt;span style="font-family: Segoe UI;"&gt;Securing WCF Services hosted in Windows Server AppFabric with Windows Identity Foundation (WIF)&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Segoe UI;"&gt;: &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/30/securing-wcf-services-hosted-in-windows-server-appfabric-with-windows-identity-foundation-wif.aspx"&gt;&lt;span style="font-family: Segoe UI;"&gt;http://blogs.msdn.com/b/appfabriccat/archive/2010/10/30/securing-wcf-services-hosted-in-windows-server-appfabric-with-windows-identity-foundation-wif.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Segoe UI;"&gt; &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;&lt;span style="font-family: Segoe UI;"&gt;ADFS 2.0: &lt;span class="MsoHyperlink"&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=118c3588-9070-426a-b655-6cec0a92c10b&amp;amp;displaylang=en"&gt;&lt;span style="color: #0000ff;"&gt;http://www.microsoft.com/downloads/en/details.aspx?FamilyID=118c3588-9070-426a-b655-6cec0a92c10b&amp;amp;displaylang=en&lt;/span&gt;&lt;/a&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span style="color: #0000ff;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;&lt;span style="font-family: Segoe UI;"&gt;WIF Runtime: &lt;span class="MsoHyperlink"&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=eb9c345f-e830-40b8-a5fe-ae7a864c4d76&amp;amp;displaylang=en"&gt;&lt;span style="color: #0000ff;"&gt;http://www.microsoft.com/downloads/en/details.aspx?FamilyID=eb9c345f-e830-40b8-a5fe-ae7a864c4d76&amp;amp;displaylang=en&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="mso-no-proof: yes;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;&lt;span style="font-family: Segoe UI;"&gt;WIF SDK: &lt;span class="MsoHyperlink"&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c148b2df-c7af-46bb-9162-2c9422208504&amp;amp;displaylang=en"&gt;&lt;span style="color: #0000ff;"&gt;http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c148b2df-c7af-46bb-9162-2c9422208504&amp;amp;displaylang=en&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; &lt;span style="mso-no-proof: yes;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 6pt;"&gt;&lt;span style="font-family: Segoe UI;"&gt;Setting up an AD FS 2.0 with WIF lab environment: &lt;span class="MsoHyperlink"&gt;&lt;a href="http://technet.microsoft.com/en-us/library/adfs2-federation-wif-application-step-by-step-guide(WS.10).aspx"&gt;&lt;span style="color: #0000ff;"&gt;http://technet.microsoft.com/en-us/library/adfs2-federation-wif-application-step-by-step-guide(WS.10).aspx&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-bidi-language: EN-US; mso-ansi-language: EN-US; mso-fareast-language: EN-US;"&gt;AD FS Claims Rules&amp;nbsp;Language Syntax: &lt;span class="MsoHyperlink"&gt;&lt;a href="http://technet.microsoft.com/en-us/library/dd807118(WS.10).aspx"&gt;&lt;span style="color: #0000ff;"&gt;http://technet.microsoft.com/en-us/library/dd807118(WS.10).aspx&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: 'Segoe UI','sans-serif'; font-size: 9pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-bidi-language: EN-US; mso-ansi-language: EN-US; mso-fareast-language: EN-US;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 class="MsoNormal"&gt;Acknowledgement&lt;/h2&gt;
&lt;p&gt;&lt;span style="font-family: Segoe UI;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;Acknowledge contributions from &lt;span class="user-name1"&gt;&lt;span lang="EN" style="color: #666666; mso-ansi-language: EN;"&gt;&lt;a href="http://blogs.msdn.com/members/masimms/"&gt;&lt;span style="color: #0000ff;"&gt;Mark Simms&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang="EN" style="color: #666666; mso-ansi-language: EN;"&gt; &lt;/span&gt;and &lt;span class="user-name1"&gt;&lt;span lang="EN" style="color: #666666; mso-ansi-language: EN;"&gt;&lt;a href="http://blogs.msdn.com/members/leprino/"&gt;&lt;span style="color: #0000ff;"&gt;Paolo Salvatori&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang="EN" style="color: #666666; mso-ansi-language: EN;"&gt; &lt;/span&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&amp;nbsp;&lt;i style="mso-bidi-font-style: normal"&gt;Namaste&lt;/i&gt;!&lt;span style="font-family: Segoe UI;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10105114" width="1" height="1"&gt;</description><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/SurenM/">SurenM</category></item><item><title>Logging and Counters in App Fabric Cache</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/14/logging-in-app-fabric-cache.aspx</link><pubDate>Wed, 15 Dec 2010 01:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10105063</guid><dc:creator>Jaime Alva</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10105063</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10105063</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/14/logging-in-app-fabric-cache.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The following is a good place to get started with how to go about collecting basic information for monitoring and/or troubleshooting an App Fabric (AF) cache setup (Host/Cluster and clients). It starts by pointing to some resources on the different available logging features and then, via a sample scenario, goes over the decision taken to implement a logging solution. Additionally, it answers a frequent customer question on what are the basic recommended performance counters to collect. &lt;/p&gt;  &lt;h3&gt;What App Fabric Cache offers&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/b/velocity/archive/2009/06/24/troubleshooting-velocity-series-iii.aspx"&gt;Here&lt;/a&gt; is a quick walk through on how to better format and generate the log generation for ease of management, some of the links within are pre-release so you may refer to the following more updated ones, &lt;a href="http://msdn.microsoft.com/en-us/library/ee790882.aspx"&gt;server log sink settings&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ee790893.aspx"&gt;client log sink settings&lt;/a&gt;. These should give a fairly good idea on the logging capabilities offered in AF Cache, please review the given links, as its knowledge will help further reading. With these concepts, the discussion and planning on what is the best suitable logging solution for your specific implementation can start. &lt;/p&gt;  &lt;h3&gt;A Sample Scenario&lt;/h3&gt;  &lt;p&gt;Assuming that memory pressure issues are a concern on the host side. The default event trace level of ERROR would not be enough as it would be necessary to have a more detailed sense of what objects are being cached on the host. This can be done by overriding the default &lt;a href="http://msdn.microsoft.com/en-us/library/ee790882.aspx"&gt;host log sink to collect information level&lt;/a&gt; logs, enabling more detailed log analysis in the case of memory related errors. 5 different levels are provided: No Tracing (-1), Error (0), Warning (1), Information(2), Verbose(3). In this sample, the Information level will be taken.&lt;/p&gt;  &lt;p&gt;At that point the next decision will be to determine if the configuration setting should be performed via code or XML (configuration file). In this sample, the organization decides that their Infrastructure personnel can handle the required changes via XML and no programmers will be required (no code needed) and hence the XML solution is the simplest.&lt;/p&gt;  &lt;p&gt;Next is the type of logging – as the same infrastructure team will also be analyzing the logs, a file-based log sink is agreed upon (versus console or Event Tracing for Windows - ETW). For the sake of simplicity and to ease the understanding of the sample in this blog, AF Cache logging was chosen. ETW logging is a viable option as well. Since the logs will be written into an existing central shared location on the network, the NETWORK SERVICE account is given rights to the share (in the case of a cluster, each host NETWORK SERVICE account will have to be added to have write access to this share). &lt;strong&gt;NOTE that AF Cache service ONLY runs under the NETWORK SERVICE account of the server (which is the account assigned to the computer by the domain), the service cannot run as any other account, such as an independent (not server/local machine account) Network user or group.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In the case of an outage the logs could be overwritten, to alleviate this, the process-specific character ($) is agreed upon and it is to be used within the log name. Also, the &lt;a href="http://blogs.msdn.com/b/velocity/archive/2009/06/24/troubleshooting-velocity-series-iii.aspx"&gt;log generation interval&lt;/a&gt; is settled for every hour (dd-hh). &lt;/p&gt;  &lt;p&gt;Similarly, since memory pressure on the webservers (AF cache client) is also a concern, the &lt;a href="http://msdn.microsoft.com/en-us/library/ee790893.aspx"&gt;client logs sink needs similar changes&lt;/a&gt;. The final custom type attribute for client and host for the fabric object will then look similar to the following:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;span style="font-family: calibri"&gt;&amp;lt;customType &lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&lt;span style="font-family: calibri"&gt;className=&amp;quot;System.Data.Fabric.Common.EventLogger,FabricCommon&amp;quot; &lt;/span&gt;&lt;span style="font-family: calibri"&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&lt;span style="font-family: calibri"&gt;sinkName=&amp;quot;System.Data.Fabric.Common.FileEventSink,FabricCommon&amp;quot;&lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&lt;span style="font-family: calibri"&gt;sinkParam=\\CentralLogs\\AFCache\\&lt;strong&gt;Server1-&lt;/strong&gt;$/dd-hh &lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&amp;lt;!-- For the client machines the log name are modified: &lt;span style="font-family: calibri"&gt;sinkParam=&amp;quot;\\CentralLogs\\AFCache\\&lt;strong&gt;Client1-&lt;/strong&gt;$/dd-hh&amp;quot; –&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&lt;span style="font-family: calibri"&gt;defaultLevel=&amp;quot;2&amp;quot; &lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&lt;span style="font-family: calibri"&gt;/&amp;gt;&lt;/span&gt;&amp;#160; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Logs are a good way to collect application specific or, as in the case above, scenario specific information that will allow for ad-hoc or error-driven analysis. Similarly, collecting performance counters can give a window in the internal operations of not only the particular application (AF cache) but also of the overall system. &lt;/p&gt;  &lt;h3&gt;Performance Counters&lt;/h3&gt;  &lt;p&gt;As a complement to the above, here is a list of recommended performance counters to aid in monitoring (for later analysis) and troubleshooting AF cache issues. The table contains the names for the performance monitor counters and the important instances to monitor. A small comment follows each counter grouping.&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="838"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="85"&gt;         &lt;p align="center"&gt;&lt;strong&gt;Counter Name&lt;/strong&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="50"&gt;         &lt;p align="center"&gt;&lt;strong&gt;Running Instance&lt;/strong&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="353"&gt;         &lt;p align="center"&gt;&lt;strong&gt;Counter Instance&lt;/strong&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="348"&gt;         &lt;p align="center"&gt;&lt;strong&gt;Comments&lt;/strong&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="85"&gt;         &lt;p align="left"&gt;AppFabric Caching:Host&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="50"&gt;         &lt;blockquote style="margin-right: 0px" dir="ltr"&gt;           &lt;p align="left"&gt;N/A&lt;/p&gt;         &lt;/blockquote&gt;       &lt;/td&gt;        &lt;td valign="top" width="353"&gt;         &lt;p align="left"&gt;All (*):           &lt;br /&gt;Cache Miss Percentage,Total Client Requests, Total Client Requests /sec, Total Data Size Bytes, Total Evicted Objects, Total Eviction Runs, Total Expired Objects, Total Get Requests, Total Get Requests /sec, Total GetAndLock Requests, Total GetAndLock Requests /sec, Total Memory Evicted, Total Notification Delivered, Total Object Count, Total Read Requests, Total Read Requests /sec, Total Write Operations, Total Write Operations /sec            &lt;br /&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="348"&gt;         &lt;p align="left"&gt;For obvious reasons all the host counters are included. For memory troubleshooting and monitoring, the counters “Total Data Size Bytes” and “Total Object Count” are relevant. Also, a high level of evictions (Total Memory Evicted) may indicate memory pressure.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="85"&gt;         &lt;p align="left"&gt;.NET CLR Memory &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="50"&gt;         &lt;p align="left"&gt;Distributed           &lt;br /&gt;CacheService&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="353"&gt;         &lt;p align="left"&gt;# Gen 0 Collections, # Gen 1 Collections, # Gen 2 Collections, # of Pinned Objects, % Time in GC, Large Object Heap size, Gen 0 heap size, Gen 1 heap size, Gen 2 heap size&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="348"&gt;         &lt;p align="left"&gt;These counters will give a fuller spectrum on what is taking place with the CLR memory. For instance, a large “% Time in GC” would indicate that too much garbage collection (GC) is taking place, and the CPU will provably be working extra to process the GC. Memory pressure may therefore be an issue. See &lt;a href="http://blogs.msdn.com/b/maoni/archive/2004/06/03/148029.aspx"&gt;this blog&lt;/a&gt; for further details &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="85"&gt;         &lt;p align="left"&gt;Memory&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="50"&gt;         &lt;p align="left"&gt;N/A&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="353"&gt;         &lt;p align="left"&gt;Available MBytes&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="348"&gt;         &lt;p align="left"&gt;The preference will be to keep this at above 10% of total memory and plan to have available space for high traffic times.            &lt;br /&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="85"&gt;         &lt;p align="left"&gt;Process &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="50"&gt;         &lt;p align="left"&gt;Distributed           &lt;br /&gt;CacheService&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="353"&gt;         &lt;p align="left"&gt;% Processor Time, Thread Count, Working Set&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="348"&gt;         &lt;p align="left"&gt;A small working set could imply memory pressure from AF Cache as oppose to other processes in the box.           &lt;br /&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="85"&gt;         &lt;p align="left"&gt;Process &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="50"&gt;         &lt;p align="left"&gt;_Total&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="353"&gt;         &lt;p align="left"&gt;% Processor Time&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="348"&gt;         &lt;p align="left"&gt;Monitoring the total process time will tell which application(s) are competing for CPU resources.           &lt;br /&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="85"&gt;         &lt;p align="left"&gt;Network Interface &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="50"&gt;         &lt;p align="left"&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="353"&gt;         &lt;p align="left"&gt;All (*):           &lt;br /&gt;Bytes Received/sec, Bytes Sent/sec, Current Bandwidth&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="348"&gt;         &lt;p align="left"&gt;As long as memory and Garbage Collection are not an issue then the CPU should be expected to work well and a lot of throughput can be handle. At this point a slow network card or any network point from there to the client may become the bottleneck. Monitor the network interfaces to ensure that they are not saturated.&amp;#160; &lt;br /&gt; &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Adding the counters&lt;/h3&gt;  &lt;p&gt;To avoid having to include all the counters above one-by-one, &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14661"&gt;download this performance counter data collection set template&lt;/a&gt; and import it to the server, as follows (alternative you can also use &lt;a href="http://technet.microsoft.com/en-us/library/cc766318.aspx"&gt;this more generic instructions&lt;/a&gt;):&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;From the run command type “perfmon” and hit enter. &lt;/li&gt;    &lt;li&gt;From the tree view, open “Data Collector Sets”, right click on “User Defined” and then choose “New” &amp;gt; “Data Collector Set”, this screen should appear, enter a suitable name and choose “Create from a template (Recommended)”.&lt;span style="font-family: calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6406.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5482.image_5F00_thumb_5F00_1.png" width="586" height="383" /&gt;&lt;/a&gt;&lt;/span&gt; &lt;/li&gt;    &lt;li&gt;Click “Next” and on do not choose any of the basic templates, instead click “Browse…”, load the &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14661"&gt;downloaded XML file template&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Click “Next” and Browse to the drop directory you wan to setup, make sure it is not already been use by other counters, otherwise it may not work or maybe to difficult to recognize one counter from another, and click “Finish”. Alternatively, click on “Next” and then choose “Open properties for this data collector set” and you will get a chance to review all the settings before finishing. &lt;/li&gt;    &lt;li&gt;Right click on the recently created Data collector set and hit Start, as shown&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6087.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8032.image_5F00_thumb_5F00_3.png" width="593" height="333" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Click “stop” once you are done collecting counters and collect the counters from the drop directory. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;In summary&lt;/h3&gt;  &lt;p&gt;Both logs and performance counters collected together are the first step in being ready to analyze errors or monitor for specific concerns or conditions (i.e. memory pressure) with AppFabric Caching. &lt;/p&gt;  &lt;p&gt;Since this is a big subject, I will look into further exploring the reasons behind the performance counters recommendation in a future blog.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Author: Jaime Alva Bravo&lt;/p&gt;  &lt;p&gt;Reviewers: Mark Simms; James Podgorski; Rama Ramani&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10105063" 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/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/-NET4/">.NET4</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Cache/">Cache</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/AppFabric+Cache/">AppFabric Cache</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/logging/">logging</category></item><item><title>StreamInsight Query Patterns: Fun with process data – calculating the wind chill factor</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/13/streaminsight-query-patterns-fun-with-process-data-calculating-the-wind-chill-factor.aspx</link><pubDate>Tue, 14 Dec 2010 00:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10104348</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=10104348</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10104348</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/13/streaminsight-query-patterns-fun-with-process-data-calculating-the-wind-chill-factor.aspx#comments</comments><description>&lt;p&gt;Process data, commonly accessed from OPC or a process historian such as OSIsoft PI, is well suited for analysis using StreamInsight &amp;ndash; being time-series data with data values from a range of sensors.&amp;nbsp; In this post, I&amp;rsquo;ll walk through a couple of simple patterns for working with process data (not that these patterns are isolated to process data).&lt;/p&gt;
&lt;p&gt;To follow along, the LINQ query for this example is &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14654"&gt;here&lt;/a&gt; (if you haven&amp;rsquo;t used LINQPad with StreamInsight yet, follow the directions &lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2010/11/24/streaminsight-linqpad-driver.aspx"&gt;here&lt;/a&gt; to get up and running).&lt;/p&gt;
&lt;p&gt;The general case for collecting process data is that of a range of sensors (temperature, pressure, humidity, flow, etc) connected to process control equipment (Programmable Logic Controllers, or PLC&amp;rsquo;s, SCADA systems, etc) that in turn relay the information upstream to process historians (or provide a direct data gathering interface, through OPC or a similar protocol).&amp;nbsp; &lt;/p&gt;
&lt;p&gt;The reason I mention this level of detail has to do with how process data typically arrives &amp;ndash; in a single or mixed stream.&amp;nbsp; That is to say as connections to these embedded devices tends to be &amp;lsquo;expensive&amp;rsquo; &lt;strong&gt;we want to minimize connections and communication and pull multiple data values over a single connection&lt;/strong&gt;, often emitted as a single CepStream&amp;lt;T&amp;gt; in StreamInsight (rather than having, for example, temperature and humidity information coming from two different data sources, in two different streams).&amp;nbsp; This is why I have intermingled data types in my examples below, and why the query patterns usually start out with creating different virtual streams based on a data type.&lt;/p&gt;
&lt;p&gt;For these examples, let&amp;rsquo;s consider a representative process control data type with some simple fields&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;string Id&lt;/li&gt;
&lt;li&gt;DateTime Timestamp&lt;/li&gt;
&lt;li&gt;double Value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Next, assume that the Id field uses an &amp;ldquo;asset.sensor&amp;rdquo; naming convention (i.e. Station1.Temperature, and Station1.Windspeed).&amp;nbsp; Also assume that the data updates are not guaranteed to be synchronized (i.e. the underlying PLC may not report updates to temperature and humidity at the same time, nor on the same schedule).&amp;nbsp; For the first query, we want to create a query that answers the question:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;ldquo;What is the current wind chill factor&amp;rdquo;&lt;/strong&gt;&amp;nbsp; (or is it a dry cold &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6378.wlEmoticon_2D00_smile_5F00_65BC4421.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" /&gt; - the opposite side of the coin from the humidex)&lt;/p&gt;
&lt;p&gt;Which breaks down to answering these questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For each station, what is the latest value of both temperature and wind speed?&lt;/li&gt;
&lt;li&gt;Every time I have a new temperature or humidity value, I need to calculate a new wind chill factor.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&amp;rsquo;s start by examining the first question.&amp;nbsp; Whenever we see a question involving latest value, we need to take a series of point or interval events and convert them into a signal (refer to &lt;a href="http://technet.microsoft.com/en-us/library/ee362414.aspx"&gt;Point to Signal&lt;/a&gt; conversion on MSDN).&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/5707.image_5F00_02E1EC2C.png"&gt;&lt;img height="172" width="597" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5633.image_5F00_thumb_5F00_19548AB3.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: ; 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;This is a timeline representation of what we&amp;rsquo;re looking to do.&amp;nbsp; We need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create separate streams for the temperature values and wind speed values, creating the inferred join key based off of the &lt;strong&gt;prefix &lt;/strong&gt;of the Id.&lt;/li&gt;
&lt;li&gt;Convert each stream from a series of Point Events into signal stream using AlterEventLifetime and ClipEventDuration.&lt;/li&gt;
&lt;li&gt;For each joint event (i.e. each time we receive a new value from either sub-stream, calculate a new wind chil).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For the purposes of this example, assume that all temperature are in F, and the wind speed is in mph.&lt;/p&gt;
&lt;p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ef10280-2c55-4c0f-abd8-5b10bd334c7a" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #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:#008000"&gt;/////////////////////////////////////////////////////////////////////////////&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// Create some sample values for both temperature and wind sensor &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;// measurements&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;/////////////////////////////////////////////////////////////////////////////&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; sensorValues = &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Temperature"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:00:00 AM"&lt;/span&gt;), Value = 20.1f },&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Temperature"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:00:30 AM"&lt;/span&gt;), Value = 18.1f },&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Temperature"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:00:45 AM"&lt;/span&gt;), Value = 17.1f },&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Temperature"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:01:00 AM"&lt;/span&gt;), Value = 22.5f },&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Windspeed"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:00:05 AM"&lt;/span&gt;), Value = 30.1f },&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Windspeed"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:00:25 AM"&lt;/span&gt;), Value = 40.4f },&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Windspeed"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:00:35 AM"&lt;/span&gt;), Value = 50.3f },&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { Id = &lt;span style="color:#a31515"&gt;"Station10.Windspeed"&lt;/span&gt;, Timestamp = &lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Parse(&lt;span style="color:#a31515"&gt;"10/23/2009 9:01:55 AM"&lt;/span&gt;), Value = 40.6f },&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:#008000"&gt;/////////////////////////////////////////////////////////////////////////////&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;// Convert the input set into a temporal stream by using the Timestamp &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// field (and ordering the incoming data)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; inputStream = sensorValues.OrderBy(e =&amp;gt; e.Timestamp)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.ToPointStream(&lt;span style="color:#2b91af"&gt;Application&lt;/span&gt;, e =&amp;gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;PointEvent&lt;/span&gt;.CreateInsert(e.Timestamp, e),&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af"&gt;AdvanceTimeSettings&lt;/span&gt;.StrictlyIncreasingStartTime);&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 temperature stream, and assign the ID as the component of the &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;// ID before the .Temperature&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; temperatureStream = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; e &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; inputStream&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;where&lt;/span&gt; e.Id.EndsWith(&lt;span style="color:#a31515"&gt;".Temperature"&lt;/span&gt;)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Id = e.Id.Substring(0, e.Id.IndexOf(&lt;span style="color:#a31515"&gt;"."&lt;/span&gt;)),&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Timestamp = e.Timestamp,&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Value = e.Value&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;// Create a windspeed stream, and assign the ID as the component of the &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// ID before the .Windspeed&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; windspeedStream = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; e &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; inputStream&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;where&lt;/span&gt; e.Id.EndsWith(&lt;span style="color:#a31515"&gt;"Windspeed"&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Id = e.Id.Substring(0, e.Id.IndexOf(&lt;span style="color:#a31515"&gt;"."&lt;/span&gt;)),&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Timestamp = e.Timestamp,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Value = e.Value&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// TEMP: dump the raw streams&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;//temperatureStream.Dump("temps");&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//windspeedStream.Dump("wind");&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;// Convert the temperature and wind speed streams into signals (i.e. remember&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;// last known value).&amp;nbsp;&amp;nbsp;Assume that we get at least one update every hour&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; temperatureSignal = temperatureStream&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.AlterEventDuration(e =&amp;gt; &lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromHours(1))&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.ClipEventDuration(temperatureStream, (e1, e2) =&amp;gt; (e1.Id == e2.Id));&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; windspeedSignal = windspeedStream&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.AlterEventDuration(e =&amp;gt; &lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromHours(1))&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.ClipEventDuration(windspeedStream, (e1, e2) =&amp;gt; (e1.Id == e2.Id));&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// TEMP: dump out the signal streams&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;//var sinkTemp = from p in temperatureSignal.ToIntervalEnumerable()&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where p.EventKind == EventKind.Insert&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select new { p.Payload.Value, p.Payload.Id, p.StartTime, p.EndTime };&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//sinkTemp.Dump("temp dump");&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;//&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//var windTemp = from p in windspeedSignal.ToIntervalEnumerable()&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where p.EventKind == EventKind.Insert&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select new { p.Payload.Value, p.Payload.Id, p.StartTime, p.EndTime };&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;//windTemp.Dump("wind dump");&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// Join the two streams based on ID - the output will be an event containing&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;// the last known values for both Temperature and Windspeed.&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; measurements = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; e1 &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; temperatureSignal&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;join&lt;/span&gt; e2 &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; windspeedSignal &lt;span style="color:#0000ff"&gt;on&lt;/span&gt; e1.Id &lt;span style="color:#0000ff"&gt;equals&lt;/span&gt; e2.Id&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Id = e1.Id,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Temperature = e1.Value,&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Windspeed = e2.Value&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#008000"&gt;// TEMP - dump out the joint values&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; measures = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; p &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; measurements.ToIntervalEnumerable()&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;where&lt;/span&gt; p.EventKind == &lt;span style="color:#2b91af"&gt;EventKind&lt;/span&gt;.Insert&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { p.Payload.Temperature, p.Payload.Windspeed, p.Payload.Id, p.StartTime, p.EndTime };&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;measures.Dump(&lt;span style="color:#a31515"&gt;"measures"&lt;/span&gt;);&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;This LINQ snippet implements step one and two, giving us the joined result of the last known values for each sub-stream:&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/6708.image_5F00_2BBCDB68.png"&gt;&lt;img height="240" width="707" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7317.image_5F00_thumb_5F00_540C0DBC.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: ; 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;Now that we have the correlated temperature and wind speed in a single event, we can go ahead and calculate the wind chill factor for each data update.&amp;nbsp; The algorithm we&amp;rsquo;ll use, as defined by the &lt;a href="http://www.weather.gov/os/windchill/images/wind-chill-brochure.pdf"&gt;National Weather Service&lt;/a&gt; is&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/6646.image_5F00_263E44F7.png"&gt;&lt;img height="42" width="420" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4188.image_5F00_thumb_5F00_3CB0E37E.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: ; 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;with &lt;em&gt;T&lt;/em&gt; being the e.Temperature value, and &lt;em&gt;V &lt;/em&gt;being the wind speed factor.&amp;nbsp; We add this to the projection as&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f29dba6b-8ded-42be-b9c2-b49f7482bf3a" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #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:#008000"&gt;// Join the two streams based on ID - the output will be an event containing&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;// the last known values for both Temperature and Windspeed.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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; measurements = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;from&lt;/span&gt;&lt;span style="color:#000000"&gt; e1 &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; temperatureSignal&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;join&lt;/span&gt;&lt;span style="color:#000000"&gt; e2 &lt;/span&gt;&lt;span style="color:#0000ff"&gt;in&lt;/span&gt;&lt;span style="color:#000000"&gt; windspeedSignal &lt;/span&gt;&lt;span style="color:#0000ff"&gt;on&lt;/span&gt;&lt;span style="color:#000000"&gt; e1.Id &lt;/span&gt;&lt;span style="color:#0000ff"&gt;equals&lt;/span&gt;&lt;span style="color:#000000"&gt; e2.Id&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color:#000000"&gt;{&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;Id = e1.Id,&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;Temperature = e1.Value,&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;Windspeed = e2.Value,&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;Windchill = Math.Round( &lt;/span&gt;&lt;span style="color:#c81efa"&gt;35.74&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;&lt;/span&gt;&lt;span style="color:#000000"&gt;+ (&lt;/span&gt;&lt;span style="color:#c81efa"&gt;0.6215&lt;/span&gt;&lt;span style="color:#000000"&gt; * e1.Value) &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;- (&lt;/span&gt;&lt;span style="color:#c81efa"&gt;35.75&lt;/span&gt;&lt;span style="color:#000000"&gt; * Math.Pow(e2.Value, &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0.16&lt;/span&gt;&lt;span style="color:#000000"&gt;)) &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;+ (&lt;/span&gt;&lt;span style="color:#c81efa"&gt;0.4275&lt;/span&gt;&lt;span style="color:#000000"&gt; * e1.Value * Math.Pow(e2.Value, &lt;/span&gt;&lt;span style="color:#c81efa"&gt;0.16&lt;/span&gt;&lt;span style="color:#000000"&gt;)))&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#000000"&gt;};&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;And observe the calculated results.&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/1055.image_5F00_6EC80DFB.png"&gt;&lt;img height="241" width="795" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0407.image_5F00_thumb_5F00_2FA6DDA0.png" alt="image" border="0" title="image" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: ; 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;This query pattern will work for any data source wherein you need to work off of and synchronize the &amp;ldquo;last known value&amp;rdquo; for a given set or subset of data.&amp;nbsp; Note that if you are &lt;strong&gt;guaranteed&lt;/strong&gt; to have synchronized timestamps on incoming data the point to signal conversion steps are not necessary before performing the join (as the timestamps of the incoming events already have the appropriate overlap).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10104348" 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>SQL Azure and Entity Framework Connection Fault Handling</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx</link><pubDate>Sat, 11 Dec 2010 01:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10103477</guid><dc:creator>James Podgorski</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10103477</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10103477</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A number of customers are choosing to use Entity Framework with &lt;a href="http://www.microsoft.com/en-us/sqlazure/default.aspx"&gt;Microsoft SQL Azure&lt;/a&gt;, and rightfully so.&amp;nbsp; Entity Framework provides an abstraction above the database so that queries are developed using the business model or conceptual model and queries are executed using the richness of LINQ to Entities.&amp;nbsp; SQL Azure is a cloud-based database based upon SQL Server which provides reliability and elasticity for database applications.&amp;nbsp; And, the Entity Framework supports SQL Azure, both the designer and the provider runtime can be used against either a SQL Server database on premise or in the cloud.&lt;/p&gt;
&lt;p&gt;But these same customers are describing connectivity drops, classified as general network issues, and are asking for the best practice to handle such network issues between SQL Azure instances and clients utilizing Entity Framework.&amp;nbsp; In fact, SQL Azure has a whole host of reasons to terminate a connection including but not exclusive to resource shortages and other transient conditions.&amp;nbsp; Similar issues apply when using ADO.NET; networks can be unreliable and are often suspect to sporadic fits resulting in dropped TCP connections.&amp;nbsp; There are a number of blog posts, such as &lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-connection-management-in-sql-azure.aspx"&gt;'SQL Azure: Connection Management in SQL Azure'&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx"&gt;'Best Practices for Handling Transient Conditions in SQL Azure Client Applications'&lt;/a&gt;, which provide connection fault handling guidance and even a framework for creating retry policies with SQL Azure client. Neither article is fully comprehensive regarding the Entity Framework aspects.&amp;nbsp; The purpose of this blog posting is to fill in the details and discussion points for the many developer options to handle and recover from intermittent connectivity drops when using Entity Framework.&lt;/p&gt;
&lt;h3&gt;Background Information &amp;ndash; Connection Pooling&lt;/h3&gt;
&lt;p&gt;It is well known that the creation and teardown of database connections to SQL Server is expensive, thus ADO.NET uses connection pools as an optimization strategy to limit the cost of the database connection creation and teardown operations.&amp;nbsp; The connection pool maintains a group of all physical connections to the database and when clients such as Entity Framework request a connection, ADO.NET provides the next available connection from the pool.&amp;nbsp; The opposite occurs when clients close a connection &amp;ndash; the connection is put back into the pool.&amp;nbsp; What is less understood is that the connection pooler will remove connections from the pool only after an idle period OR after the pooler detects that the connection with the server has been severed.&amp;nbsp; But the pooler can only detect severed connections after an attempt has been made to issue a command against the server.&amp;nbsp; This means that clients such as Entity Framework could potentially draw a severed or invalid connection from the pool.&amp;nbsp; With high latency and volatile networks, this happens on a more frequent basis.&amp;nbsp; The invalid connections are removed from the pool only after the connection is closed.&amp;nbsp; Alternatively the client can flush all of the connections using ClearAllPools or ClearPool methods.&amp;nbsp; See MSDN article &lt;a href="http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx"&gt;&amp;lsquo;SQL Server Connection Pooling'&lt;/a&gt; for a more verbose description of the concepts.&lt;/p&gt;
&lt;h3&gt;Background Information - Entity Framework Database Connection&lt;/h3&gt;
&lt;p&gt;The Entity Framework provider abstracts most if not all of the facets from executing a query against the backend store, from establishment of the connection, to the retrieval of the data and materialization of the POCO or &lt;em&gt;EntityObjects&lt;/em&gt;.&amp;nbsp; Nevertheless it does provide access to the underlying store connection through the Connection property of the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;System.Data.Objects.ObjectContext&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;ObjectContext&lt;/a&gt;&lt;/em&gt; wraps the underlying &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx"&gt;&lt;em&gt;System.Data.SqlClient.SqlConnection&lt;/em&gt;&lt;/a&gt; to the SQL Server database by using an instance of the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityclient.entityconnection.aspx"&gt;System.Data.EntityClient.EntityConnection&lt;/a&gt;&lt;/em&gt; class.&amp;nbsp; The &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityclient.entityconnection.aspx"&gt;EntityConnection&lt;/a&gt;&lt;/em&gt; class exposes a read/write StoreConnection property which is essentially the underlying &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx"&gt;SqlConnection&lt;/a&gt;&lt;/em&gt; to the SQL Azure instance.&amp;nbsp; That mouthful simply says that we have a mechanism upon which to read the current state of a connection and assign the store connection if so desired.&amp;nbsp; Since we have access to the database connection, we can most certainly catch exceptions thrown when the network transport has failed and retry our operations per a given retry policy.&lt;/p&gt;
&lt;p&gt;One subtlety which requires a touch of clarification, take the code snippet below. In this example the connection was explicitly opened on the context. The explicit opening of the connection is a way of informing EF not to open and reopen the connection on each command. Had I not opened the connection in this way, EF would implicitly open and close a database connection for each query within the scope of the context. We will leverage this knowledge in the connection retry scenarios that follow.&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" 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;using&lt;/span&gt; (AdventureWorksLTAZ2008R2Entities dc = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AdventureWorksLTAZ2008R2Entities())&lt;br /&gt;{&lt;br /&gt;    dc.Connection.Open();&lt;br /&gt;    &lt;span style="color: #008000"&gt;// ...&lt;/span&gt;&lt;br /&gt;}&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;Case #1 &amp;ndash; Retry Policies &lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s take the following code as an example. How many connections are drawn from the pool? The answer is two, one for the retrieval of the customer and another for the retrieval of the address. This means that if implemented in this general way, Entity Framework will use a new connection for every query it executes against the backend data store given the scope of the current &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;ObjectContext&lt;/a&gt;&lt;/em&gt;. It pulls a connection for the pool, submits the query against the database and closes the connection for each LINQ query. You can see this by running SQL Profiler on an instance of SQL Server as shown in the table below the query.&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" 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;using&lt;/span&gt; (AdventureWorksLTAZ2008R2Entities dc = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AdventureWorksLTAZ2008R2Entities())&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; cId = 29485;&lt;br /&gt;    Customer c1 = (from x &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.Customers&lt;br /&gt;                   &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; x.CustomerID == cId&lt;br /&gt;                   select x).First();&lt;br /&gt;&lt;br /&gt;    Address ad1 = (from x &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.Addresses&lt;br /&gt;                   from y &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.CustomerAddresses&lt;br /&gt;                   &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; y.CustomerID == cId &amp;amp;&amp;amp; x.AddressID == y.AddressID&lt;br /&gt;                   select x).FirstOrDefault();&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;table cellpadding="2" cellspacing="0" border="1" style="width: 520px;"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="117" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;Audit Login&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;font&gt;&lt;/font&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="401" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="122" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;font&gt;&lt;/font&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="401" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_executesql N'SELECT TOP (1) &lt;br /&gt;[Extent1].[CustomerID] AS [CustomerID] &amp;hellip;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="125" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;Audit Logout&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;font&gt;&lt;/font&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="401" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="128" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;font&gt;&lt;/font&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="401" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_reset_connection &lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;Audit Login&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;font&gt;&lt;/font&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="401" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="131" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;font&gt;&lt;/font&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="401" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_executesql N'SELECT &lt;br /&gt;[Limit1].[AddressID] AS [AddressID], &amp;hellip;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="132" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;Audit Logout&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;font&gt;&lt;/font&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="401" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;But there is an interesting facet to the code above, the connection to the database was not explicitly created.&amp;nbsp; The &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityclient.entityconnection.aspx"&gt;EntityConnection&lt;/a&gt;&lt;/em&gt; was transparently created by the Entity Framework when the AdventureWorksLTAZ2008R2Entities &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;ObjectContext&lt;/a&gt;&lt;/em&gt; was instantiated and the &lt;em&gt;StoreConnection&lt;/em&gt; property or actual &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx"&gt;SqlConnection&lt;/a&gt;&lt;/em&gt; state is set to closed. Only after the LINQ query is executed by the EF provider is the connection opened and the query submitted to SQL Server.&amp;nbsp; The state of the inner connection changes to closed and the connection placed back into the pool once the results have been successfully retrieved.&lt;/p&gt;
&lt;p&gt;In this example, we have two places in which a transient network error or invalid connection in the pool could affect the query and cause a &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityexception.aspx"&gt;System.Data.EntityException&lt;/a&gt;&lt;em&gt;&lt;/em&gt;, for the retrieval of the customer and for the retrieval of the address.&amp;nbsp; The inner exception of the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityexception.aspx"&gt;EntityException&lt;/a&gt;&lt;/em&gt; is of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.aspx"&gt;System.Data.SqlClient.SqlException&lt;/a&gt;&lt;em&gt;&lt;/em&gt; and it contains the actual SQL Server error code for the exception. &lt;/p&gt;
&lt;p&gt;A policy can be applied to wrap the LINQ queries to catch the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityexception.aspx"&gt;EntityException&lt;/a&gt;&lt;/em&gt; and retry the query given the particular metrics of the policy.&amp;nbsp; The retry policy in the code below utilizes the Transient Conditions Handling Framework described in the &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx"&gt;blog&lt;/a&gt; written by my teammate Valery. This blog provides a very comprehensive selection of retry policies which will properly handle the thrown exceptions. The basic principle is to support a number of retries with increasing periods of wait between each subsequent retry (i.e. a backoff algorithm).&amp;nbsp; In this case we abort the operation after 10 attempts with a wait periods of 100ms, 200ms&amp;hellip; up to 1 second. &lt;/p&gt;
&lt;div&gt;
&lt;pre id="codeSnippet" 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;using&lt;/span&gt; Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling.SqlAzure;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" 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;using&lt;/span&gt; (AdventureWorksLTAZ2008R2Entities dc = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AdventureWorksLTAZ2008R2Entities())&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; cId = 29485;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; MaxRetries = 10;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; DelayMS = 100;&lt;br /&gt;&lt;br /&gt;    RetryPolicy policy = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RetryPolicy&amp;lt;SqlAzureTransientErrorDetectionStrategy&amp;gt;(MaxRetries, TimeSpan.FromMilliseconds(DelayMS));&lt;br /&gt;&lt;br /&gt;    Customer c1 = policy.ExecuteAction&amp;lt;Customer&amp;gt;(() =&amp;gt; &lt;br /&gt;                  (from x &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.Customers&lt;br /&gt;                   &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; x.CustomerID == cId&lt;br /&gt;                   select x).First());&lt;br /&gt;&lt;br /&gt;    Address ad1 = policy.ExecuteAction&amp;lt;Address&amp;gt;(() =&amp;gt;&lt;br /&gt;                  (from x &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.Addresses&lt;br /&gt;                   from y &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.CustomerAddresses&lt;br /&gt;                   &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; y.CustomerID == cId &amp;amp;&amp;amp; x.AddressID == y.AddressID&lt;br /&gt;                   select x).FirstOrDefault());&lt;br /&gt;}&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;p&gt;This retry policy approach is not without its challenges, particularly in regards to the developer experience.&amp;nbsp; The Func delegates require that a type be passed in, something that is somewhat cumbersome when using anonymous types because the return type must be set to an object type.&amp;nbsp; This means that the developer must cast the object to the anonymous type to make use of it, a sample of which is shown below.&amp;nbsp; I created a CastHelper class for that purpose.&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" 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;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CastHelper&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; T Cast&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj, T type)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (T)obj;     &lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" 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;var c1 = policy.ExecuteAction&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;(() =&amp;gt;&lt;br /&gt;              (from x &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.Customers&lt;br /&gt;               &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; x.CustomerID == cId&lt;br /&gt;               select &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; { x.CustomerID, x.FirstName, x.LastName }).First());&lt;br /&gt;&lt;br /&gt;var anon = CastHelper.Cast(c1, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; { CustomerID = -1, FirstName = &lt;span style="color: #006080"&gt;""&lt;/span&gt;, LastName = &lt;span style="color: #006080"&gt;""&lt;/span&gt; });&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;Case #2 &amp;ndash; Retry Policy With Transaction Scope&lt;/h3&gt;
&lt;p&gt;Case #2 expands the previous case to include a transaction scope.&amp;nbsp; The dynamics of the sample changes because a &lt;a href="http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx"&gt;System.Transactions.TransactionScope&lt;/a&gt;&lt;em&gt;&lt;/em&gt; object is used to ensure data consistency of all scoped queries using an ambient transaction context which is automatically managed for the developer. But from the trace shown below we still observe the typical pattern of Audit Logout events with the SQL Transaction Begin and End events.&amp;nbsp; This begs the question:&amp;nbsp; How can we have a local transaction (non-distributed) if our data access code spans multiple connections?&amp;nbsp;&amp;nbsp; Well, in this case we are not truly spanning multiple physical connections because every connection drawn from pool is based upon the proper connection string and, for those enlisted in a transaction, the thread context.&amp;nbsp; We can imagine the connection pool subdivided into subdivisions based upon individual transaction contexts and the connection string.&amp;nbsp; In this way, pulling a connection from the pool guarantees that we are not attempting to enlist in a distributed transaction.&lt;/p&gt;
&lt;p&gt;The net result:&amp;nbsp; We cannot implement our retry policies at the query or SaveChanges level and still maintain the ACID properties of the transaction.&amp;nbsp; The retry policies must be implemented against the entire transactional scope as shown below.&amp;nbsp; Note that if you do attempt to place retry logic against the individual queries and a network glitch occurs, be assured than an &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityexception.aspx"&gt;EntityException&lt;/a&gt;&lt;/em&gt; will be thrown having an inner &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.aspx"&gt;SqlException&lt;/a&gt;&lt;/em&gt; with a message of &amp;ldquo;MSDTC on Server &amp;ldquo;xxx&amp;rdquo; is unavailable&amp;rdquo;, SQL Azure does not support distributed transactions.&amp;nbsp; Nevertheless, this is not SQL Azure specific problem. The error is non-recoverable at the query statement level; it is all or nothing with transactions.&lt;/p&gt;
&lt;p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" 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;using&lt;/span&gt; (AdventureWorksLTAZ2008R2Entities dc = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AdventureWorksLTAZ2008R2Entities())&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; MaxRetries = 10;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; DelayMS = 100;&lt;br /&gt;&lt;br /&gt;    RetryPolicy policy = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RetryPolicy&amp;lt;SqlAzureTransientErrorDetectionStrategy&amp;gt;(MaxRetries, TimeSpan.FromMilliseconds(DelayMS));&lt;br /&gt;    TransactionOptions tso = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TransactionOptions();&lt;br /&gt;    tso.IsolationLevel = IsolationLevel.ReadCommitted;&lt;br /&gt;    policy.ExecuteAction(() =&amp;gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (TransactionScope ts = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TransactionScope(TransactionScopeOption.Required, tso))&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; cId = 29485;&lt;br /&gt;&lt;br /&gt;            Customer c1 = (from x &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.Customers&lt;br /&gt;                           &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; x.CustomerID == cId&lt;br /&gt;                           select x).First();&lt;br /&gt;&lt;br /&gt;            Address ad1 = (from x &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.Addresses&lt;br /&gt;                           from y &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; dc.CustomerAddresses&lt;br /&gt;                           &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; y.CustomerID == cId &amp;amp;&amp;amp; x.AddressID == y.AddressID&lt;br /&gt;                           select x).FirstOrDefault();&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; firstName = c1.FirstName;&lt;br /&gt;            c1.FirstName = c1.LastName;&lt;br /&gt;            c1.LastName = firstName;&lt;br /&gt;&lt;br /&gt;            dc.SaveChanges();&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; addressLine1 = ad1.AddressLine1;&lt;br /&gt;            ad1.AddressLine1 = ad1.AddressLine2 == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; ? &lt;span style="color: #006080"&gt;"dummy data"&lt;/span&gt; : ad1.AddressLine2;&lt;br /&gt;            ad1.AddressLine2 = addressLine1;&lt;br /&gt;            dc.SaveChanges();&lt;br /&gt;&lt;br /&gt;            ts.Complete();&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;table cellpadding="2" cellspacing="0" border="1" style="width: 532px;"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;SQL Transaction&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;0 &amp;ndash; Begin&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_executesql N'SELECT TOP (1) &lt;br /&gt;[Extent1].[CustomerID] AS [CustomerID], &amp;hellip;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;Audit Logout&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_reset_connection &lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_executesql N'SELECT &lt;br /&gt;[Limit1].[AddressID] AS [AddressID], &amp;hellip;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;Audit Logout&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_reset_connection &lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_executesql N'update [SalesLT].[Customer] &lt;br /&gt;set [FirstName] = @0, [LastName] = @1 &amp;hellip;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;Audit Logout&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_reset_connection &lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_executesql N'update [SalesLT].[Address] &lt;br /&gt;set [AddressLine1] = @0 &amp;hellip;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;Audit Logout&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;RPC:Completed&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;exec sp_reset_connection &lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;SQL Transaction&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;1 &amp;ndash; End&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="130" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;Audit Logout&lt;/span&gt;&lt;/td&gt;
&lt;td width="400" valign="top"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;Case #3 &amp;ndash; Implement Retry Policy in OnContextCreated&lt;/h3&gt;
&lt;p&gt;If your scenario is such that the EF queries return very quickly, which is the most typical pattern, then it probably suffices to employ a retry policy solely at the connection level. If other words, only retry when a connection fails to open. The premise is that if the client application acquires a valid connection, no other network related errors will occur while during the execution of my queries. If an error does occur, the application can catch the exception and resubmit as it would in a traditional non-cloud based implementation. Besides, this tactic offers the least invasive solution because as you will from the code sample below, we only have to implement the retry policy in one spot. The remainder of the EF code works the same as if it was executing against an on premise SQL Server. &lt;/p&gt;
&lt;p&gt;Remember earlier we stated that the &amp;lsquo;validity&amp;rsquo; of a connection is only determined after a command is issued against the server. So conceivably to ensure a valid connection, one must attempt to open a connection and submit a command to the database. If an exception is thrown, the connection is close and thus removed from the pool. There is an associated overhead to opening and submitting a command just to check the validity of a connection and for this reason the ADO.NET connection pool elects not to perform this on behalf of the client application. &lt;/p&gt;
&lt;p&gt;The tactic is to implement the OnContextCreated partial method of the models context which is called each time a new context is instantiated. In this partial method, employ a retry policy which opens a connection, submits a dummy query and handles exceptions with proper closure of invalid connections. In this way, the pool is &amp;lsquo;cleansed&amp;rsquo; of all connections that have disconnected due to network glitches or idle expirations. The tradeoffs are obvious, the additional round trip to the SQL Azure database and the possible delay while the OnContextCreated method closes invalid connections. &lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" 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;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnContextCreated()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; MaxRetries = 10;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; DelayMS = 100;&lt;br /&gt;&lt;br /&gt;    RetryPolicy policy = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RetryPolicy&amp;lt;SqlAzureTransientErrorDetectionStrategy&amp;gt;(MaxRetries, TimeSpan.FromMilliseconds(DelayMS));&lt;br /&gt;    policy.ExecuteAction(() =&amp;gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ss = Connection.ConnectionString;&lt;br /&gt;            Connection.Open();&lt;br /&gt;            var storeConnection = (SqlConnection)((EntityConnection)Connection).StoreConnection;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SqlCommand(&lt;span style="color: #006080"&gt;"declare @i int"&lt;/span&gt;, storeConnection).ExecuteNonQuery();&lt;br /&gt;            &lt;span style="color: #008000"&gt;// throw new ApplicationException("Test only");&lt;/span&gt;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception e)&lt;br /&gt;        {&lt;br /&gt;            Connection.Close();&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; e;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    );&lt;br /&gt;}&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table cellpadding="2" cellspacing="0" border="1" style="width: 520px;"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="105" valign="top"&gt;RPC:Completed&lt;/td&gt;
&lt;td width="413" valign="top"&gt;exec sp_executesql N'declare @i int; set @i = @ix',N'@ix int',@ix=1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="105" valign="top"&gt;RPC:Completed&lt;/td&gt;
&lt;td width="413" valign="top"&gt;
&lt;p&gt;exec sp_executesql N'SELECT TOP (1) &lt;br /&gt;[Extent1].[CustomerID] AS [CustomerID], &amp;hellip;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="105" valign="top"&gt;RPC:Completed&lt;/td&gt;
&lt;td width="413" valign="top"&gt;
&lt;p&gt;exec sp_executesql N'SELECT &lt;br /&gt;[Limit1].[AddressID] AS [AddressID], &amp;hellip;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="105" valign="top"&gt;Audit Logout&lt;/td&gt;
&lt;td width="413" valign="top"&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The sample above submits a lightweight batch to the database, the only overhead to the database is the time to execution of the RPC statement.&amp;nbsp; All looks good, but there is one important fact that may catch you.&amp;nbsp; From the profiler trace we observe that the same connection is used for each query database query. This is by design and as discussed early, i.e. when a connection is explicitly opened by the developer it tells EF not to open/reopen a connection for each command. The series of Audit Login/Logout events to retrieve the customer entity or address entity are not submitted as we saw in Case #1 and #2. This means we cannot implement a retry policy for each individual query like I showed earlier. Since the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entityclient.entityconnection.aspx"&gt;EntityConnection&lt;/a&gt;&lt;/em&gt; has been assigned to the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;ObjectContext&lt;/a&gt;&lt;/em&gt;, EF takes the position that you really truly want to use one connection for all of your queries within the scope of that context. Retrying a query on an invalid or closed connection can never work, a &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entitycommandexecutionexception.aspx"&gt;System.Data.EntityCommandExecutionException&lt;/a&gt;&lt;em&gt;&lt;/em&gt; will be thrown with an inner &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.aspx"&gt;SqlException&lt;/a&gt;&lt;/em&gt; contains the message for the error.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Three cases were examined. Retry policies with/without a transaction scope and an implementation of OnContextCreated. The first two cases apply if you wish to introduce retry policies on all of your queries, in or out of a &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx"&gt;TransactionScope&lt;/a&gt;&lt;/em&gt;. You may find justification in this approach if your EF queries are apt to become throttled by SQL Azure which manifests itself during execution. The programming paradigms while not overly complex do require more work on the part of the developer. Applying a retry policy in the OnContextCreated method provides slimmer coverage but offers the best bang for the effort. In the majority of cases, network related exceptions tend to reveal themselves just after the connection is retrieved from the pool, thus a policy implemented right after the connection is opened should prove sufficient for those cases where database queries are expected to return quickly.&lt;/p&gt;
&lt;pre class="code"&gt;Authored By: James Podgorski
Review By: Valery Mizonov, Mark Simms, Faisal Mohamood&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10103477" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Entity+Framework/">Entity Framework</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/SQL+Server/">SQL Server</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/LINQ/">LINQ</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Azure/">Azure</category></item><item><title>Distributed Cache != Database</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/09/cache-database.aspx</link><pubDate>Thu, 09 Dec 2010 23:55:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10102925</guid><dc:creator>Rama Ramani</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10102925</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10102925</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/09/cache-database.aspx#comments</comments><description>&lt;p&gt;Even though this topic looks obvious, there have been some interesting customer scenarios centered around this topic. I am hoping that this blog helps for decision making. As a basic tenet, in most solutions, a distributed cache will be used along with a database to optimize the application performance. In most cases, one would not replace one of these technologies with the other, since they provide different set of capabilities. However, based on some of the new kinds of web workload, there are some key criteria where a distributed cache can be chosen over a database.
&lt;/p&gt;&lt;p&gt;This blog is a synopsis from a recent presentation done at &lt;a href="http://sqlpass.eventpoint.com/topic/details/AD386A"&gt;SQL PASS&lt;/a&gt;. 
&lt;/p&gt;&lt;h1&gt;Considerations
&lt;/h1&gt;&lt;p&gt;Here are a set of questions to ask yourself when looking at this decision:
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Are there expensive '&lt;strong&gt;key based lookup&lt;/strong&gt;' operations? 
&lt;/li&gt;&lt;li&gt;Are there &lt;strong&gt;rarely changing&lt;/strong&gt; data items accessed frequently? 
&lt;/li&gt;&lt;li&gt;Are there a lot of &lt;strong&gt;temporal writes&lt;/strong&gt;? 
&lt;/li&gt;&lt;li&gt;Do you need a &lt;strong&gt;scalable ASP.NET session &lt;/strong&gt;store?
&lt;/li&gt;&lt;li&gt;Is &lt;strong&gt;highly availability &lt;/strong&gt;in memory enough instead of requiring durability?
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Most benefit is got when objects cached in AppFabric are frequently accessed &lt;em&gt;aggregated objects,&lt;/em&gt; created by executing JOIN across several tables by a stored procedure or by making a set of Web service calls or a combination of both. For example, consider a popular forums website with over 300M page views per month. Each time, a user visits the forums home page, the ASP.NET application might have to run a stored procedure to aggregate the set of &lt;em&gt; Posts&lt;/em&gt;, the various related &lt;em&gt;Threads&lt;/em&gt;, showcase stats for the number of unanswered questions and review rating for the popular topics in each category. With 100s of categories and 1000s of &lt;em&gt;Posts&lt;/em&gt;, each &lt;em&gt;Post&lt;/em&gt; having 10s of &lt;em&gt;Threads&lt;/em&gt; very quickly this becomes a scaling problem. In order to make this efficient, the aggregated "&lt;em&gt;ForumPost"&lt;/em&gt; object can be cached so that subsequent read requests are made against a distributed cache such as AppFabric Cache thus freeing up the database server for transactional and durable data. So one will have both the distributed cache and the database, just doing different things
&lt;/p&gt;&lt;p&gt;Storing an entire table and raw rowsets in AppFabric cache is not going to be optimal, since there are serialization and de-serialization costs when doing GETs or PUTs from AppFabric Cache. The latency of requests will not be optimal. However, depending on the how overloaded the database system gets and your allowable performance metrics, this approach might be useful. However, this is not the typical usage.
&lt;/p&gt;&lt;p&gt;Setting up High Availability is a configuration knob in AppFabric Cache. There is no need to have any high end hardware or complex deployment techniques. And it is available at a Named Cache level and allows to apply this selectively
&lt;/p&gt;&lt;p&gt;AppFabric Cache provides elastic scale thus allowing your data or application tier to scale linearly. Adding or Removing nodes at run-time can be done based on your needs. This is due to the scale-out architecture that it uses by leveraging some core platform components such as Fabric and CAS (Common Availability Substrate)
&lt;/p&gt;&lt;p&gt;ASP.NET session state is one such scenario where &lt;em&gt;temporal reads &amp;amp; writes&lt;/em&gt; can remain in-memory, highly available and does not really need durable storage.
&lt;/p&gt;&lt;p&gt;Another related scenario is when performing a lot of computations (reads and writes) with the need of a "centralized scratch pad", which again may not require durability. The final result could be persisted in durable storage, like a database server
&lt;/p&gt;&lt;p&gt;If your application needs rich querying, then the relational operators &amp;amp; model will work. However, if you are dealing with complex event processing with real time querying involving time windows, a product like &lt;a href="http://msdn.microsoft.com/en-us/library/ee362541.aspx"&gt;StreamInsight&lt;/a&gt; may be a better fit. AppFabric Cache has support for tags and allows 'Bulk' operations which may work as a basic workaround. However this does not provider querying functionality. 
&lt;/p&gt;&lt;p&gt;Transactions and Durability are some of the core tenets in database systems. AppFabric Cache does not support them out of the box. We have got ASKs about &lt;em&gt;Write-Behind&lt;/em&gt; feature to persist the in-memory contents and this feature is being prioritized and evaluated for a future release. 
&lt;/p&gt;&lt;p&gt;Here is a scorecard that compares a database server with AppFabric cache based on the criteria above.
&lt;/p&gt;&lt;div&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:252px"/&gt;&lt;col style="width:175px"/&gt;&lt;col style="width:213px"/&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr style="height: 39px; background: #fa761c"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-top:  solid white 1.0pt; border-left:  solid white 1.0pt"&gt;&lt;p&gt;&lt;strong&gt;Criteria&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-top:  solid white 1.0pt"&gt;&lt;p&gt;&lt;strong&gt;Database server &lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-top:  solid white 1.0pt; border-right:  solid white 1.0pt"&gt;&lt;p&gt;&lt;strong&gt;AppFabric Cache &lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 39px; background: white"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-left:  solid white 1.0pt"&gt;&lt;p&gt;&amp;lt;key, value&amp;gt; where &lt;em&gt;value&lt;/em&gt; is an aggregated object &lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8814.120910_5F00_2355_5F00_Distributed1.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-right:  solid white 1.0pt"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0474.120910_5F00_2355_5F00_Distributed2.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 39px; background: white"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-left:  solid white 1.0pt"&gt;&lt;p&gt;Ease of setting up HA &lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4604.120910_5F00_2355_5F00_Distributed3.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-right:  solid white 1.0pt"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8814.120910_5F00_2355_5F00_Distributed4.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 39px; background: white"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-left:  solid white 1.0pt"&gt;&lt;p&gt;Ease of Scale out &lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0878.120910_5F00_2355_5F00_Distributed5.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-right:  solid white 1.0pt"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6648.120910_5F00_2355_5F00_Distributed6.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 39px; background: white"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-left:  solid white 1.0pt"&gt;&lt;p&gt;ACID properties &lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8080.120910_5F00_2355_5F00_Distributed7.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-right:  solid white 1.0pt"&gt; &lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 39px; background: white"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-left:  solid white 1.0pt"&gt;&lt;p&gt;Temporal data &lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7823.120910_5F00_2355_5F00_Distributed8.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-right:  solid white 1.0pt"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0871.120910_5F00_2355_5F00_Distributed9.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 39px; background: white"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-left:  solid white 1.0pt"&gt;&lt;p&gt;Read-only data&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3187.120910_5F00_2355_5F00_Distributed10.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-right:  solid white 1.0pt"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0385.120910_5F00_2355_5F00_Distributed11.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="height: 39px; background: white"&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-left:  solid white 1.0pt; border-bottom:  solid white 1.0pt"&gt;&lt;p&gt;Rich query semantics &lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-bottom:  solid white 1.0pt"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7220.120910_5F00_2355_5F00_Distributed12.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-top: 5px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px; border-bottom:  solid white 1.0pt; border-right:  solid white 1.0pt"&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1440.120910_5F00_2355_5F00_Distributed13.png" alt=""/&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;And finally, you would have both of them in your solution architecture, possibly warming up the cache with the aggregated objects and expiring them or keeping cached objects in sync explicitly with the backend changes.
&lt;/p&gt;&lt;p&gt;You may not agree with the * rating since it varies by scenario, but some of the aspects should be factored in your decision criteria. 
&lt;/p&gt;&lt;p&gt;Happy Caching!
&lt;/p&gt;&lt;p style="background: white"&gt;&lt;span style="font-family:Segoe UI; font-size:10pt"&gt;&lt;em&gt;Contribution from &lt;a href="http://sqlpass.eventpoint.com/speaker/details/Todd_Robinson"/&gt;&lt;/em&gt;Todd Robinson&lt;/span&gt;&lt;span style="color:black; font-family:Tahoma; font-size:8pt"&gt;&lt;strong&gt;
			&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Segoe UI; font-size:10pt"&gt;&lt;em&gt;is acknowledged. &lt;/em&gt;&lt;/span&gt;&lt;span style="color:black; font-family:Tahoma; font-size:8pt"&gt;&lt;strong&gt;
			&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="background: white"&gt;&lt;span style="font-family:Segoe UI; font-size:10pt"&gt;&lt;span style="color:#333333"&gt;&lt;em&gt;Authored by: Rama Ramani &lt;br/&gt;Reviewed by: &lt;a href="http://blogs.msdn.com/members/quocbui/"/&gt;&lt;/em&gt;&lt;/span&gt;Quoc Bui&lt;span style="color:#333333"&gt;&lt;em&gt;, &lt;a href="http://blogs.msdn.com/members/Christian.Martinez/"/&gt;&lt;/em&gt;&lt;/span&gt;Christian Martinez&lt;/span&gt;&lt;span style="color:#333333"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10102925" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Cache/">Cache</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric+Cache/">AppFabric Cache</category></item><item><title>Fronting long-running WF Services with MSMQ, the right way</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/08/fronting-long-running-wf-services-with-msmq-the-right-way.aspx</link><pubDate>Wed, 08 Dec 2010 14:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10100613</guid><dc:creator>Emil Velinov</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10100613</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10100613</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/08/fronting-long-running-wf-services-with-msmq-the-right-way.aspx#comments</comments><description>&lt;p&gt;A couple of weeks ago I was working with a customer who engaged me to assist with a "little" problem they had &amp;ndash; under certain conditions, the system would lose messages coming from a MSMQ queue and designed to correlate to instances of a long-running WF service hosted in IIS/AppFabric. &lt;/p&gt;
&lt;h1&gt;The Rule of Thumb &lt;/h1&gt;
&lt;p&gt;Now, because I don't want to waste anybody's time, before I go into explaining all the details I'll just give you the rule of thumb from my learning: &lt;strong&gt;if you want to reliably&amp;nbsp;expose your&amp;nbsp;WF services via MSMQ, always use transactional queues coupled with a TransactedReceiveScope inside the workflow definition.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As long as you remember the above and are comfortable implementing it, you can happily stop reading right here. For the curious amongst us, I'll continue with the full story. &lt;/p&gt;
&lt;h1&gt;The Scenario &lt;/h1&gt;
&lt;p&gt;So, the customer had a long-running WF-based service that at some point in the execution was awaiting a correlated message to come in, via an endpoint bound to a non-transactional MSMQ queue. &lt;/p&gt;
&lt;p&gt;(By the way, if you are looking for information on enabling MSMQ communication for WF services, I would point you&amp;nbsp;to an excellent step-by-step guide written by Cindy Song and available &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=94F62981-AB14-4907-8C3E-D699AA965D58&amp;amp;amp;displaylang=en"&gt;here&lt;/a&gt;.) &lt;/p&gt;
&lt;p&gt;Anyway, under normal circumstances, everything works OK, with the correlated message consumed off the queue and fed into the right workflow instance, which would continue its execution as expected. However, as with any real-life solution, the customer had a few scenarios (not very uncommon) that pushed the envelope a bit &amp;ndash; welcome to the real world! So, let's look at &lt;strong&gt;the easiest and most obvious to explain&lt;/strong&gt; in a blog post &amp;ndash; a workflow instance starts, sends a one-way request to an external application or a human to perform some task, continues to do a bit of work, and then starts waiting for the external one-way&amp;nbsp;"response" to come in (via a non-transactional MSMQ queue) before completing. Conceptually, this is depicted below: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3426.120610_5F00_0205_5F00_Frontinglon1.png" /&gt; &lt;/p&gt;
&lt;p&gt;Now, let's look at what happens if one of the "Do something" activities fails &amp;ndash; obviously the workflow instance will get suspended and never reach the "Receive TaskCompleted" activity. Unless you've created some special logic on the client to detect such conditions the following sequence will happen: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The client "Complete Task" message will go to the queue bound to the "Receive TaskCompleted" endpoint &lt;/li&gt;
&lt;li&gt;From there, the workflow endpoint using the MSMQ binding will pick up the message (this takes the message off the queue completely and unconditionally)&lt;/li&gt;
&lt;li&gt;The message dispatcher, which is the WF runtime component responsible for inspecting incoming messages and matching them to their corresponding WF instances,&amp;nbsp;will try to get to our now suspended WF instance, which of course will fail. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;What now? The message has been consumed from the queue and because it is a non-transactional queue there is no rollback. At the same time the target WF instance is incapable of receiving the message and AppFabric itself does not provide a temporary message store to put the message into. So, at that point, the runtime's only choice is to logs an exception in the AppFabric monitoring DB and discontinue further actions&amp;nbsp;for&amp;nbsp;this message,&amp;nbsp;&amp;nbsp;as follows: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7635.120610_5F00_0205_5F00_Frontinglon2.png" /&gt; &lt;/p&gt;
&lt;p&gt;The bottom line is that in cases like this we are&amp;nbsp;losing the message payload with no ability to handle&amp;nbsp;the message manually or through a different component.&lt;/p&gt;
&lt;p&gt;Once you realize what's happening in step 3 above, even if it is not the desired/ideal outcome, at least it is all logical and makes sense. So, let's focus on the solution - to transaction-enable the queue and the corresponding receive activity within the workflow so that if the WF runtime&amp;nbsp;cannot deliver the message to an instance, the pick-up from the queue would roll back and a delivery retried later, if so configured.&lt;/p&gt;
&lt;h2&gt;Using a transactional MSMQ queue &lt;/h2&gt;
&lt;p&gt;To enable transactions for a MSMQ queue, you will need to create the queue as Transactional. What I mean here is that you cannot just change a non-transactional queue to a transactional one without re-creating it completely. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To create a transactional queue, use the Computer Management console, right-click on the "Private Queues" node, and select "New-&amp;gt;Private Queue" from the context menu:&lt;br /&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2451.120610_5F00_0205_5F00_Frontinglon3.png" /&gt;&lt;br /&gt;Make sure you name the queue after the relative URL of your WF service &amp;ndash; also note the forward slash in the path (the service in this example is deployed to &lt;a href="http://localhost/MsmqWF/Service1.xamlx"&gt;http://localhost/MsmqWF/Service1.xamlx&lt;/a&gt;). Then select the "Transactional" checkbox. &lt;/li&gt;
&lt;li&gt;Once the queue is created, adjust its permissions so that the account used by the app pool running your WF service has read/write access to the queue (for simplicity, the screenshot below grants "Full Control" to all Authenticated Users):&lt;br /&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6175.120610_5F00_0205_5F00_Frontinglon4.png" /&gt;&lt;/li&gt;
&lt;li&gt;You can also elect to enable the Journal via the General properties tab, which will provide traceability for your messages:&lt;br /&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1778.120610_5F00_0205_5F00_Frontinglon5.png" /&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Configuring the service to receive messages from the transactional queue &lt;/h2&gt;
&lt;p&gt;The first step is to update the workflow to use the &lt;em&gt;TransactedReceiveScope&lt;/em&gt; for all MSMQ-bound &lt;em&gt;Receive&lt;/em&gt; activities. Let's assume we have the following super-simple workflow with just two one-way &lt;em&gt;Receive&lt;/em&gt; activities - Start, and FollwowUp, which is correlated to the Start: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5582.120610_5F00_0205_5F00_Frontinglon6.png" /&gt; &lt;/p&gt;
&lt;p&gt;We will need to modify the definition to use the &lt;em&gt;TransactedReceiveScope&lt;/em&gt; activity as depicted below: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8625.120610_5F00_0205_5F00_Frontinglon7.png" /&gt; &lt;/p&gt;
&lt;p&gt;As we can see, the change is as simple as placing the FollowUp activity into the &lt;em&gt;Request&lt;/em&gt; placeholder of a &lt;em&gt;TransactedReceiveScope&lt;/em&gt; activity. &lt;/p&gt;
&lt;p&gt;The second step is to create the correct web.config file entries for the service's endpoint(s), along with their binding configuration. For the sample service below, my updated web.config file has the following content: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6574.120610_5F00_0205_5F00_Frontinglon8.png" /&gt; &lt;/p&gt;
&lt;p&gt;The second, MSMQ-bound, endpoint is using the &lt;em&gt;netMsmqBinding&lt;/em&gt;, with a custom configuration named &lt;em&gt;netMsmqBinding_Config&lt;/em&gt;, which specifies the &lt;em&gt;exactlyOnce&lt;/em&gt; attribute with a value of &lt;em&gt;true&lt;/em&gt; (meaning it should use transactional semantics for communicating with the queue). The custom binding configuration also specifies what retry semantics should be used for "failed" messages via the &lt;em&gt;receiveRetryCount&lt;/em&gt;, &lt;em&gt;maxRetryCycles&lt;/em&gt;, and &lt;em&gt;retryCycleDelay&lt;/em&gt; attributes. The meaning and default values for these attributes and how they affect the MSMQ message delivery retry logic can be found on MSDN &lt;a href="http://msdn.microsoft.com/en-us/library/ms789028.aspx"&gt;here&lt;/a&gt;. With the sample web.config above, if the target WF instance cannot receive the request, the message will be placed in the "retry" pool of the queue and a single re-delivery attempt will be made after 1 minute. The &lt;em&gt;receiveErrorHandling&lt;/em&gt; attribute with a value of &lt;em&gt;Move&lt;/em&gt; means that if all specified delivery attempts fail, the message will be moved to the &lt;em&gt;poison&lt;/em&gt; queue where another process or a person can handle the error condition (the topic of poison queues is also covered in the &lt;a href="http://msdn.microsoft.com/en-us/library/ms789028.aspx"&gt;same MSDN article&lt;/a&gt;). &lt;/p&gt;
&lt;h1&gt;The Conclusion &lt;/h1&gt;
&lt;p&gt;When using MSMQ to communicate with long-running WF services, the system design should always employ transactional queues for reliable delivery. This will effectively eliminate the potential for message loss in the WF message dispatcher in cases where the correlated target WF instance cannot either be found, activated, or capable of receiving the incoming message at the given point in time. &lt;/p&gt;
&lt;p&gt;Thanks for reading again and happy MSMQ'ing! &lt;span style="font-family:Wingdings"&gt;J&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Authored by: Emil Velinov&lt;br /&gt;Reviewed by: Keith Bauer, Christian Martinez&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10100613" 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/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/WCF/">WCF</category></item><item><title>StreamInsight: Reading from other data contexts into StreamInsight with LINQPad</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/03/streaminsight-reading-from-other-data-contexts-into-streaminsight-with-linqpad.aspx</link><pubDate>Sat, 04 Dec 2010 03:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10100251</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=10100251</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10100251</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/03/streaminsight-reading-from-other-data-contexts-into-streaminsight-with-linqpad.aspx#comments</comments><description>&lt;p&gt;The LINQPad driver for StreamInsight provides an awesomely easy way to run StreamInsight queries using easily accessible data contexts of temporal streams.&amp;nbsp; However, as LINQPad only supports a single active data context connection in a query it can be difficult to use one of the hard to read &amp;ldquo;without a data context&amp;rdquo; sources (such as OData) and use StreamInsight.&lt;/p&gt;
&lt;p&gt;As LINQPad does enable execution of generic .NET code, we can use a little trick to get around the single-connection context limitation simply placing the embedded server creation code (i.e. Server.Create()) directly into a LINQPad query statement (regardless of the active context).&lt;/p&gt;
&lt;h3&gt;Step 1: Reading an OData Service in LINQPad&lt;/h3&gt;
&lt;p&gt;We&amp;rsquo;ll start off by importing the Northwind data set as an OData service, then converting the &lt;strong&gt;Orders &lt;/strong&gt;table into a CepStream.&amp;nbsp; For more background on how to work with the new (as of 1.1) IEnumerable/IObservable adapters for StreamInsight refer to Colin Meek&amp;rsquo;s excellent &lt;a href="http://blogs.msdn.com/b/meek/archive/2010/10/27/streaminsight-sequence-integration-five-easy-pieces.aspx"&gt;StreamInsight Sequence Integration: Five Easy Pieces&lt;/a&gt; post.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Start a copy of LINQPad with the StreamInsight driver installed.&amp;nbsp; Refer to the &lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2010/11/24/streaminsight-linqpad-driver.aspx"&gt;StreamInsight LINQPad Driver&lt;/a&gt; post if you haven&amp;rsquo;t yet done this. &lt;/li&gt;
&lt;li&gt;From the data context list, click on &lt;strong&gt;Add Connection&lt;/strong&gt;.&amp;nbsp; From the Choose Data Context dialog, select &lt;em&gt;WCF Data Services (OData)&lt;/em&gt; and click &lt;strong&gt;Next&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/8054.image_5F00_thumb11_5F00_7E17D269.png"&gt;&lt;img height="480" width="655" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6811.image_5F00_thumb11_5F00_thumb_5F00_222D072C.png" alt="image_thumb1[1]" border="0" title="image_thumb1[1]" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 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;ul&gt;
&lt;li&gt;Type the URI &lt;a href="http://services.odata.org/Northwind/Northwind.svc"&gt;http://services.odata.org/Northwind/Northwind.svc&lt;/a&gt; into the LINQPad connection dialog, and click &lt;strong&gt;OK&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/4276.image_5F00_thumb31_5F00_18A422E9.png"&gt;&lt;img height="367" width="524" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2022.image_5F00_thumb31_5F00_thumb_5F00_53C7D8E7.png" alt="image_thumb3[1]" border="0" title="image_thumb3[1]" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 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;The Northwind OData context is now available for use in LINQPad.&amp;nbsp; One question that might immediately crop up is why didn&amp;rsquo;t I use the StreamInsight database context instead of the OData context?&amp;nbsp; LINQPad, unfortunately, doesn&amp;rsquo;t yet support multiple database contexts in a single query.&amp;nbsp; With the need to pull data from one context (LINQ to OData) and process it in another (StreamInsight), and the LINQ to OData context being rather challenging to create on the fly, we&amp;rsquo;ll use the Northwind as our primary context, and &lt;span style="text-decoration: underline;"&gt;dynamically generate a StreamInsight embedded server&lt;/span&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Northwind data context should now be available in the list of connections.&amp;nbsp; From the query pane, select &lt;strong&gt;C# Statement(s) &lt;/strong&gt;as the language, and the Northwind URI as the database.&amp;nbsp; We use C# Statement instead of C# Expression to let us build up more complicated objects and code (such as the StreamInsight embedded server object). &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/1376.image_5F00_thumb6_5F00_3F32639C.png"&gt;&lt;img height="87" width="644" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7356.image_5F00_thumb6_5F00_thumb_5F00_074FF9AC.png" alt="image_thumb6" border="0" title="image_thumb6" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 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;ul&gt;
&lt;li&gt;Let&amp;rsquo;s run a simple query to make sure that the data feed is flowing through appropriately.&amp;nbsp; Type the code in the block below into the query window and press &lt;strong&gt;F5 &lt;/strong&gt;to execute the query. &lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="class" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c96b6b7f-b43a-4240-9eac-bc5b18f98c89" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
&lt;div style="background: #ddd; overflow: auto"&gt;&lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// Retrieve orders from the Northwind OData feed that&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;// have valid shipping dates and order dates.&amp;nbsp; Select&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// fields to be used in the StreamInsight query (basic&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;// types only)&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; orders = &lt;span style="color: #0000ff"&gt;from&lt;/span&gt; o &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; Orders &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; o.ShippedDate != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; o.OrderDate != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;orderby&lt;/span&gt; o.OrderDate &lt;span style="color: #0000ff"&gt;ascending&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CustomerName = o.Customer.CompanyName, &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OrderDate = (&lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;)o.OrderDate, &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShippedDate = (&lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;)o.ShippedDate, &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Region = o.ShipRegion &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }; &lt;/li&gt;
&lt;li&gt;&amp;nbsp; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;orders.Dump(); &lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;li&gt;The results should be similar to those shown in the screenshot below.&amp;nbsp; Once you&amp;rsquo;ve validated that the OData feed is being consumed properly, delete the &lt;em&gt;orders.Dump() &lt;/em&gt;call. &lt;/li&gt;
&lt;/ul&gt;
&lt;table cellpadding="0" cellspacing="0" border="0" style="list-style-type: disc; width: 668px; border-collapse: collapse;"&gt;
&lt;colgroup&gt;&lt;col width="256" style="width: 192pt; mso-width-source: userset; mso-width-alt: 9362;"&gt;&lt;/col&gt;&lt;col width="147" style="width: 110pt; mso-width-source: userset; mso-width-alt: 5376;"&gt;&lt;/col&gt;&lt;col width="118" style="width: 89pt; mso-width-source: userset; mso-width-alt: 4315;"&gt;&lt;/col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr height="18" style="height: 13.5pt;"&gt;
&lt;td colspan="4" width="668" height="18" class="xl73" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: #1177bb; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: #1177bb 1pt solid; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Tahoma;"&gt;&lt;span style="color: #ffffff; font-size: 9.9pt;"&gt;&lt;strong&gt;IOrderedQueryable&amp;lt;&amp;gt; (200 items)&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" title="System.String" class="xl68" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;CustomerName&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="146" title="System.DateTime" class="xl66" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;OrderDate&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="146" title="System.DateTime" class="xl66" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;ShippedDate&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" title="System.String" class="xl69" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;Region&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Vins et alcools Chevalier&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/4/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/16/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Toms Spezialit&amp;auml;ten&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/5/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/10/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Hanari Carnes&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/8/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/12/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;RJ&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Victuailles en stock&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/8/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/15/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Supr&amp;ecirc;mes d&amp;eacute;lices&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/9/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/11/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Hanari Carnes&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/10/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/16/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;RJ&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Chop-suey Chinese&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/11/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/23/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Richter Supermarkt&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/12/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/15/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;Wellington Importadora&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/15/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/17/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;SP&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;HILARION-Abastos&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/16/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="146" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/22/1996 0:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="118" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;T&amp;aacute;chira&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;Step 2: Creating a StreamInsight host and a basic query&lt;/h3&gt;
&lt;p&gt;Now that we have the OData feed available in LINQPad, let&amp;rsquo;s go ahead and set things up to allow us to create and execute StreamInsight queries without a data context (a data context or data connection makes this a lot easier &amp;ndash; but since we also need the Northwind OData context, one of these has to be manually defined).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In LINQPad, click on the &lt;strong&gt;Query &lt;/strong&gt;menu item, then on &lt;strong&gt;Query Properties &lt;/strong&gt;(or press &lt;strong&gt;F4&lt;/strong&gt;). &lt;/li&gt;
&lt;li&gt;In the Query Properties dialog, add the following references to the Additional References list, as per the screenshot below. 
&lt;ul&gt;
&lt;li&gt;Microsoft.ComplexProcessing.dll &lt;/li&gt;
&lt;li&gt;Microsoft.ComplexProcessing.Observable.dll &lt;/li&gt;
&lt;/ul&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/1586.image_5F00_thumb91_5F00_662CD744.png"&gt;&lt;img height="154" width="702" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7245.image_5F00_thumb91_5F00_thumb_5F00_48F7096D.png" alt="image_thumb9[1]" border="0" title="image_thumb9[1]" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 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;ul&gt;
&lt;li&gt;Click on the Additional Namespace Imports tab, and add the following namespaces as per the screenshot below. 
&lt;ul&gt;
&lt;li&gt;Microsoft.ComplexEventProcessing &lt;/li&gt;
&lt;li&gt;Microsoft.ComplexEventProcessing.Linq &lt;/li&gt;
&lt;/ul&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/4544.image_5F00_thumb12_5F00_0486F261.png"&gt;&lt;img height="126" width="703" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5040.image_5F00_thumb12_5F00_thumb_5F00_2E3A4787.png" alt="image_thumb12" border="0" title="image_thumb12" 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;ul&gt;
&lt;li&gt;Since this won&amp;rsquo;t be the only time (I hope &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8764.wlEmoticon_2D00_smile_5F00_7C7F2A31.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;) that we use this technique, go ahead and click on the &lt;strong&gt;Set as default for new queries &lt;/strong&gt;button, click OK to acknowledge the popup, then click &lt;strong&gt;OK&lt;/strong&gt; to close the Query Properties dialog. &lt;/li&gt;
&lt;li&gt;Now we can go ahead and define an embedded StreamInsight server to process our queries, by pasting the code below into the LINQPad query window. &lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="class" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b82df75a-3b75-40ff-a8fd-42d7f4ef77e2" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
&lt;div style="background: #ddd; max-height: 500px; overflow: auto"&gt;&lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;
&lt;li&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt;&lt;span style="color: #000000"&gt; (Server server = Server.Create(&lt;/span&gt;&lt;span style="color: #dc1414"&gt;"Default"&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;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;Application app = server.CreateApplication(&lt;/span&gt;&lt;span style="color: #dc1414"&gt;"test"&lt;/span&gt;&lt;span style="color: #000000"&gt;);&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;li&gt;Using the techniques described in Colin&amp;rsquo;s excellent post on using Sequences with StreamInsight v1.1, let&amp;rsquo;s convert the set of orders into a temporal stream.&amp;nbsp; The code below demonstrates how to obtain a CepStream&amp;lt;&amp;gt; of &lt;strong&gt;intervals &lt;/strong&gt;from the enumerable set of orders. &lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="class" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f58b2452-71b3-45cb-8366-e69ade78c0b9" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
&lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt;&lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// Convert the set of orders into an interval stream &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; orderStream = orders.ToIntervalStream(app, t =&amp;gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;IntervalEvent&lt;/span&gt;.CreateInsert((&lt;span style="color: #2b91af"&gt;DateTimeOffset&lt;/span&gt;)t.OrderDate, (&lt;span style="color: #2b91af"&gt;DateTimeOffset&lt;/span&gt;)t.ShippedDate, t), &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;AdvanceTimeSettings&lt;/span&gt;.IncreasingStartTime); &lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;li&gt;Now we&amp;rsquo;re ready to write our basic query.&amp;nbsp; Let&amp;rsquo;s look for the condition wherein we have more than one outstanding order in a region (i.e. if the order date and ship dates overlap). &lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="class" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fa68b59c-66d2-4788-af3c-7486a4d019db" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
&lt;div style="background: #ddd; max-height: 500px; overflow: auto"&gt;&lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// Group the order stream by region, and create &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;// snapshot windows to look at the sets of overlapping&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// orders.&amp;nbsp; Count the number of orders.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; regionCounts = &lt;span style="color: #0000ff"&gt;from&lt;/span&gt; o &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; orderStream &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;group&lt;/span&gt; o &lt;span style="color: #0000ff"&gt;by&lt;/span&gt; o.Region &lt;span style="color: #0000ff"&gt;into&lt;/span&gt; regionGroups &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;from&lt;/span&gt; win &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; regionGroups.SnapshotWindow(&lt;span style="color: #2b91af"&gt;SnapshotWindowOutputPolicy&lt;/span&gt;.Clip) &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; { ShipRegion = regionGroups.Key, Count = win.Count() }; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// Look for regions which have more than 1 overlapping&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;// order&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; filter = &lt;span style="color: #0000ff"&gt;from&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; regionCounts &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; e.Count &amp;gt; 2 &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;select&lt;/span&gt; e; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// Dump the results of the query out into an enumerable&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; snk = &lt;span style="color: #0000ff"&gt;from&lt;/span&gt; i &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; filter.ToIntervalEnumerable() &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; i.EventKind == &lt;span style="color: #2b91af"&gt;EventKind&lt;/span&gt;.Insert &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff"&gt;select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; { i.StartTime, i.EndTime, i.Payload.ShipRegion, i.Payload.Count }; &lt;/li&gt;
&lt;li&gt;snk.Dump(); &lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;li&gt;Let&amp;rsquo;s run the query (by pressing F5) and observe the results. &lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;table cellpadding="0" cellspacing="0" border="0" style="list-style-type: disc; width: 670px; border-collapse: collapse;"&gt;
&lt;colgroup&gt;&lt;col width="256" style="width: 192pt; mso-width-source: userset; mso-width-alt: 9362;"&gt;&lt;/col&gt;&lt;col width="101" style="width: 76pt; mso-width-source: userset; mso-width-alt: 3693;"&gt;&lt;/col&gt;&lt;col width="57" style="width: 43pt; mso-width-source: userset; mso-width-alt: 2084;"&gt;&lt;/col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr height="18" style="height: 13.5pt;"&gt;
&lt;td colspan="4" width="670" height="18" class="xl73" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: #1177bb; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: #1177bb 1pt solid; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Tahoma;"&gt;&lt;span style="color: #ffffff; font-size: 9.9pt;"&gt;&lt;strong&gt;IEnumerable&amp;lt;&amp;gt; (130 items)&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" title="System.DateTimeOffset" class="xl69" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;StartTime&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="256" title="System.DateTimeOffset" class="xl66" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;EndTime&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="101" title="System.String" class="xl66" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;ShipRegion&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="57" title="System.Int64" class="xl70" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: #dddddd; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;&lt;strong&gt;Count&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="20" style="height: 15pt;"&gt;
&lt;td width="256" height="20" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/8/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="256" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/9/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="101" class="xl68" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="57" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="39" style="height: 29.25pt;"&gt;
&lt;td width="256" height="39" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/9/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="256" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/10/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="101" class="xl68" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="57" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="39" style="height: 29.25pt;"&gt;
&lt;td width="256" height="39" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/10/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="256" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/11/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="101" class="xl68" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="57" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="39" style="height: 29.25pt;"&gt;
&lt;td width="256" height="39" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/11/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="256" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/12/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="101" class="xl68" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="57" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height="39" style="height: 29.25pt;"&gt;
&lt;td width="256" height="39" class="xl71" style="border-bottom: #aaaaaa 1pt solid; border-left: #1177bb 1.5pt solid; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/12/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="256" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/15/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td width="101" class="xl68" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="right" width="57" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Interesting result combining LINQPad exploration of a LINQ to WCF OData and StreamInsight &amp;ndash; but what went into producing that result? Which collection of events resulted in that output event?&amp;nbsp; Answering that question will be my next post on using the Event Flow Debugger with LINQPad and StreamInsight &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8764.wlEmoticon_2D00_smile_5F00_7C7F2A31.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;&lt;/p&gt;
&lt;div class="class" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1e5c70bd-3718-497a-a60b-e6a8a36b166b" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;
&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
&lt;div style="background: #ddd; overflow: auto"&gt;&lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// Retrieve orders from the Northwind OData feed that&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;// have valid shipping dates and order dates.&amp;nbsp; Select&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #008000"&gt;// fields to be used in the StreamInsight query (basic&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;// types only)&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;&lt;span style="color: #000000"&gt; orders = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;from&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; Orders &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #0000ff"&gt;where&lt;/span&gt;&lt;span style="color: #000000"&gt; o.ShippedDate != &lt;/span&gt;&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;&lt;span style="color: #000000"&gt; &amp;amp;&amp;amp; o.OrderDate != &lt;/span&gt;&lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff"&gt;orderby&lt;/span&gt;&lt;span style="color: #000000"&gt; o.OrderDate &lt;/span&gt;&lt;span style="color: #0000ff"&gt;ascending&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: #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&gt;&lt;span style="color: #000000"&gt;{&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;CustomerName = o.Customer.CompanyName,&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;OrderDate = (DateTime)o.OrderDate,&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;ShippedDate = (DateTime)o.ShippedDate,&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;Region = o.ShipRegion&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: #0000ff"&gt;using&lt;/span&gt;&lt;span style="color: #000000"&gt; (Server server = Server.Create(&lt;/span&gt;&lt;span style="color: #dc1414"&gt;"Default"&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;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;Application app = server.CreateApplication(&lt;/span&gt;&lt;span style="color: #dc1414"&gt;"test"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #008000"&gt;// Convert the set of orders into an interval stream &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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; orderStream = orders.ToIntervalStream(app, t =&amp;gt; &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;IntervalEvent.CreateInsert((DateTimeOffset)t.OrderDate, (DateTimeOffset)t.ShippedDate, t), &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;AdvanceTimeSettings.IncreasingStartTime);&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #008000"&gt;// Group the order stream by region, and create &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #008000"&gt;// snapshot windows to look at the sets of overlapping&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #008000"&gt;// orders.&amp;nbsp; Count the number of orders.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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; regionCounts = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;from&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; orderStream&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;group&lt;/span&gt;&lt;span style="color: #000000"&gt; o &lt;/span&gt;&lt;span style="color: #0000ff"&gt;by&lt;/span&gt;&lt;span style="color: #000000"&gt; o.Region &lt;/span&gt;&lt;span style="color: #0000ff"&gt;into&lt;/span&gt;&lt;span style="color: #000000"&gt; regionGroups&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;from&lt;/span&gt;&lt;span style="color: #000000"&gt; win &lt;/span&gt;&lt;span style="color: #0000ff"&gt;in&lt;/span&gt;&lt;span style="color: #000000"&gt; regionGroups.SnapshotWindow(SnapshotWindowOutputPolicy.Clip) &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;span style="color: #000000"&gt; { ShipRegion = regionGroups.Key, Count = win.Count() };&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #008000"&gt;// Look for regions which have more than 1 overlapping&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #008000"&gt;// order&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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; filter = &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; regionCounts&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;where&lt;/span&gt;&lt;span style="color: #000000"&gt; e.Count &amp;gt; &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&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;&amp;nbsp; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #008000"&gt;// Dump the results of the query out into an enumerable&lt;/span&gt; &lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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; snk = &lt;/span&gt;&lt;span style="color: #0000ff"&gt;from&lt;/span&gt;&lt;span style="color: #000000"&gt; i &lt;/span&gt;&lt;span style="color: #0000ff"&gt;in&lt;/span&gt;&lt;span style="color: #000000"&gt; filter.ToIntervalEnumerable() &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;where&lt;/span&gt;&lt;span style="color: #000000"&gt; i.EventKind == EventKind.Insert &lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;span style="color: #000000"&gt; { i.StartTime, i.EndTime, i.Payload.ShipRegion, i.Payload.Count };&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #000000"&gt;snk.Dump();&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;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10100251" 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/OData/">OData</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/LINQPad/">LINQPad</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Event+Flow+Debugger/">Event Flow Debugger</category></item><item><title>StreamInsight: Where did that query result come from (using the Event Flow Debugger in LINQPad)?</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/02/streaminsight-where-did-that-query-result-come-from.aspx</link><pubDate>Thu, 02 Dec 2010 17:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10099629</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=10099629</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10099629</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/12/02/streaminsight-where-did-that-query-result-come-from.aspx#comments</comments><description>&lt;p&gt;Occasionally, when working with StreamInsight queries an unusual result will crop up, leading to asking the rather blunt question &amp;ldquo;where did that come from?&amp;rdquo;.&amp;nbsp; Luckily the StreamInsight Event Flow Debugger has a great feature (&lt;strong&gt;Root Cause Analysis&lt;/strong&gt;) that will let us examine how certain results were generated.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve never used the Event Flow Debugger, or are having trouble working with it, please have a look through &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/21/streaminsight-getting-started-with-using-the-event-flow-debugger-viewing-diagnostics-and-exposing-the-management-service.aspx"&gt;StreamInsight: Getting started with using the (Event Flow) debugger, viewing diagnostics, and exposing the management service&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll start by creating a system that produces &amp;ldquo;questionable&amp;rdquo; results, then examining it with the Event Flow Debugger.&amp;nbsp; This system will:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pull in a stream of events from the Northwind OData feed &lt;/li&gt;
&lt;li&gt;Look for a specific condition occuring in the Orders table (thanks to &lt;a href="http://www.sqlis.com/"&gt;Allan Mitchell&lt;/a&gt; for the query idea &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5635.wlEmoticon_2D00_smile_5F00_46B4BB37.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;), using LINQPad and the StreamInsight driver to execute the query &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you haven&amp;rsquo;t installed LINQPad with the StreamInsight driver, the step-by-step instructions may be found at &lt;a href="http://blogs.msdn.com/b/streaminsight/archive/2010/11/24/streaminsight-linqpad-driver.aspx"&gt;StreamInsight LINQPad Driver&lt;/a&gt; on the StreamInsight team blog.&amp;nbsp; This tool combination makes ad-hoc querying drastically simpler, and I highly recommend dropping down the $30 for autocompletion.&amp;nbsp; Well worth it!&lt;/p&gt;
&lt;p&gt;With the system up and running, we&amp;rsquo;ll use the offline trace file capabilities of StreamInsight to capture events flowing through the system, then analyze the results to see if it &amp;ldquo;makes sense&amp;rdquo;.&amp;nbsp; The details of using LINQPad to pull an OData stream from the internet and query it with StreamInsight are covered &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/03/streaminsight-reading-from-other-data-contexts-into-streaminsight-with-linqpad.aspx"&gt;StreamInsight: Reading from other data contexts into StreamInsight with LINQPad&lt;/a&gt;.&amp;nbsp; The trace file that I use in this blog post was generated by running the LINQ statement from that blog post.&lt;/p&gt;
&lt;h3&gt;Capturing a trace&lt;/h3&gt;
&lt;p&gt;We&amp;rsquo;ll use the offline trace capability of StreamInsight to figure out some root cause analysis of output events.&amp;nbsp; From the previous &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/03/streaminsight-reading-from-other-data-contexts-into-streaminsight-with-linqpad.aspx"&gt;post&lt;/a&gt;, let&amp;rsquo;s track down what went into producing this output event:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/12/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="256" class="xl67" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;7/15/1996 7:00:00 AM +00:00&lt;/span&gt;&lt;/span&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td width="101" class="xl68" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #aaaaaa 1pt solid; padding-top: 1px"&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #008000; font-size: 11pt;"&gt;&lt;em&gt;null&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;td align="right" width="57" class="xl72" style="border-bottom: #aaaaaa 1pt solid; border-left: medium none; padding-bottom: 1px; background-color: white; padding-left: 1px; padding-right: 1px; vertical-align: top; border-top: medium none; border-right: #1177bb 1.5pt solid; padding-top: 1px"&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style="font-family: Verdana;"&gt;&lt;span style="color: #000000; font-size: 11pt;"&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Verdana; color: #000000;"&gt;Open up a command prompt, and navigate to the &lt;em&gt;C:\Program Files\Microsoft StreamInsight 1.1\Tools &lt;/em&gt;directory.&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana; color: #000000;"&gt;From this directory, use &lt;em&gt;trace.cmd&lt;/em&gt; to start capturing tracing information via &lt;em&gt;trace start rootcause.etl&lt;/em&gt;.&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana; color: #000000;"&gt;From LINQPad, execute the query again.&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana; color: #000000;"&gt;From the command prompt stop tracing by executing the command &lt;em&gt;trace stop&lt;/em&gt;.&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana; color: #000000;"&gt;If you observe the contents of the &lt;em&gt;C:\Program Files\Microsoft StreamInsight 1.1\Tools &lt;/em&gt;directory the rootcause.etl file should be visible with a non-zero length.&amp;nbsp; We&amp;rsquo;ll now use the Event Flow Debugger to perform a root cause analysis.&lt;/span&gt;
&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&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/1638.image_5F00_7B295182.png"&gt;&lt;img height="300" width="650" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7002.image_5F00_thumb_5F00_6AED63BC.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Using the Event Flow Debugger against a Trace file&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Start the &lt;strong&gt;Event Flow Debugger &lt;/strong&gt;(Start &amp;ndash;&amp;gt; Microsoft StreamInsight 1.1 x64 (en) &amp;ndash;&amp;gt; Event Flow Debugger). &lt;/li&gt;
&lt;li&gt;Click on &lt;strong&gt;File&lt;/strong&gt;, then on &lt;strong&gt;Open&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Browse to the &lt;em&gt;C:\Program Files\Microsoft StreamInsight 1.1\Tools&lt;/em&gt; directory.&amp;nbsp; Select the &lt;em&gt;rootcause.etl&lt;/em&gt; file and click &lt;strong&gt;Open&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;From the &lt;strong&gt;Object Explorer&lt;/strong&gt;, expand the &lt;strong&gt;rootcause.etl &lt;/strong&gt;node, then the &lt;strong&gt;Server &lt;/strong&gt;node, then the &lt;strong&gt;test &lt;/strong&gt;application node. &lt;/li&gt;
&lt;li&gt;Right-click on the &lt;strong&gt;IEnumerable subscription 0 query&lt;/strong&gt;, and click &lt;strong&gt;Display Query&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/7485.image_5F00_3D5C1E2C.png"&gt;&lt;img height="234" width="438" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2781.image_5F00_thumb_5F00_370521D1.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If we expand the IEnumerable stream 1 input adapter, we&amp;rsquo;ll see all of the events that flowed into this query.&amp;nbsp; We&amp;rsquo;ll come back to this in a bit, but we&amp;rsquo;re more interested right now in looking at the output and determining root cause. &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/7484.image_5F00_15292373.png"&gt;&lt;img height="230" width="644" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1185.image_5F00_thumb_5F00_0F9A6735.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scroll down to the OutputAdapter_Cleanse box, and expand it.&amp;nbsp; Since we&amp;rsquo;re (for this exploration) only interested in the actual output events (rather than the liveliness of the query by examining CTI&amp;rsquo;s), let&amp;rsquo;s go ahead and filter for INSERT events by adding a filter to the operator view.&amp;nbsp; This filter will be &lt;strong&gt;EventKind == &amp;ldquo;Insert&amp;rdquo;&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/1261.image_5F00_4840FD43.png"&gt;&lt;img height="402" width="644" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8686.image_5F00_thumb_5F00_07EA982F.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We&amp;rsquo;re trying to track down what went into producing a specific event, so let&amp;rsquo;s add a more detailed filter to the cleanse box.&amp;nbsp; In this case we added &lt;strong&gt;&amp;ldquo;&amp;amp;&amp;amp; StartTime == DateTime.Parse(&amp;ldquo;7/12/1996 7:00:00 AM&amp;rdquo;)&lt;/strong&gt;&amp;rdquo; &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/7587.image_5F00_67BB51A5.png"&gt;&lt;img height="414" width="644" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5123.image_5F00_thumb_5F00_6A04ADD6.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Now that we&amp;rsquo;ve tracked down the specific event we&amp;rsquo;re interested in, let&amp;rsquo;s go ahead and see what went into producing it.&amp;nbsp; Click on the event to select it, then click &lt;strong&gt;Analysis &lt;/strong&gt;in the menu, and finally click &lt;strong&gt;Root Cause Analysis&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/6661.image_5F00_19EEB3BE.png"&gt;&lt;img height="213" width="644" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6204.image_5F00_thumb_5F00_3D1B5CC9.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scroll back up to the input adapter, and we can now observe the four events that went into generated our output event! &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/8838.image_5F00_61D4720F.png"&gt;&lt;img height="287" width="644" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7245.image_5F00_thumb_5F00_2A3DEF7A.png" alt="image" border="0" title="image" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Takeaways&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.linqpad.net/"&gt;LINQPad&lt;/a&gt;, together with the StreamInsight LINQpad driver makes a great ad-hoc query and exploratory interface. &lt;/li&gt;
&lt;li&gt;Use the offline trace viewing capability of the &lt;a href="http://msdn.microsoft.com/en-us/library/ff518532.aspx"&gt;Event Flow Debugger&lt;/a&gt; to capture query activity and investigate how your output events came to be. &lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10099629" 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></item><item><title>Basics on how to setup an App Fabric Cache server and API usage</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/30/basics-on-how-to-setup-an-app-fabric-cache-server-and-api-usage.aspx</link><pubDate>Wed, 01 Dec 2010 02:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10098693</guid><dc:creator>Jaime Alva</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10098693</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10098693</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/30/basics-on-how-to-setup-an-app-fabric-cache-server-and-api-usage.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At this year&amp;rsquo;s &lt;a href="http://www.sqlpass.org/summit/na2010/AboutSummit.aspx"&gt;SQL PASS summit&lt;/a&gt;, I had the opportunity to talk with customers about App Fabric Cache and in preparation for the event, I put a demo to show some of the characteristics of the available APIs. The following is an explanation on how to setup the demo, what to expect when running it (as if you had attended), along with notes based on the most frequently asked questions.&lt;/p&gt;
&lt;h1&gt;The setup &lt;/h1&gt;
&lt;p&gt;For simplicity, everything will be contained on one machine. Start by downloading the appropriate &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&amp;amp;FamilyID=467e5aa5-c25b-4c80-a6d2-9f8fb0f337d2"&gt;Windows Server AppFabric bits&lt;/a&gt; and installing them and make sure to add the Caching Services, Cache Client and Cache Administrator (I would recommend installing everything so as to play with the host bits as well but nothing of that is included in this blog), see 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/6114.image_5F00_2.png"&gt;&lt;img height="422" width="562" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4150.image_5F00_thumb.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;After the bits are installed the configure Hosting Services window will come up, again, for simplicity, take the defaults as shown&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/7183.image_5F00_4.png"&gt;&lt;img height="428" width="569" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7367.image_5F00_thumb_5F00_1.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;Set the cache host with a XML configuration provider (SQL provider not use only for simplicity, SQL is however the recommended setup) and a small cluster. Make sure the service account has rights to the XML share, as follows. If you have ran the wizard on the same share before you will have to remove the existing ClusterConfig.xml file (or rename it)&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/1030.image_5F00_6.png"&gt;&lt;img height="434" width="577" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1423.image_5F00_thumb_5F00_2.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;Leave all ports as per defaults (see 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/8688.image_5F00_12.png"&gt;&lt;img height="432" width="574" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5148.image_5F00_thumb_5F00_5.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;for more installation details see &lt;a href="http://msdn.microsoft.com/en-us/library/ff637745.aspx"&gt;Install Windows Server AppFabric&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ff637694.aspx"&gt;Configure Windows Server AppFabric&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;NOTE: Do not try to setup either a client or server by copying and GACing the App Fabric Cache DLLs, this will lead to errors and is not a supported installation.&lt;/p&gt;
&lt;p&gt;Now that the cache host is setup and configured, run the &amp;ldquo;Caching Administration Windows PowerShell&amp;rdquo; in elevated rights, as an Administrator. And to start the cache host, run the following command.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt;Start-CacheHost&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You will be prompted for the hostname and cache port. Give the machine name and port 22233 (since the defaults were taken when running the configuration wizard), you should see the following&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas;"&gt;HostName : CachePort Service Name Service Status Version Info&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas;"&gt;-------------------- ------------ -------------- ------------&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas;"&gt;jaimelap2:22233 AppFabricCachingService UP 1 [1,1][1,1]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Setup your user account to an allowed client user, in my case I had&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt;Grant-CacheAllowedClientAccount redmond\jaimeab&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Create the cache for the demo application and look at the current statistics&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt;new-cache default&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt;get-cachestatistics default&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You will see the following stats since nothing has yet taken place:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;Size : 0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;ItemCount : 0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;RegionCount : 0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;RequestCount : 0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas; font-size: x-small;"&gt;MissCount : 0&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;/h4&gt;
&lt;h1&gt;Running the demos&lt;/h1&gt;
&lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14498"&gt;Here&lt;/a&gt; is the demo project (built in VS2010 ultimate), make sure the two following references are correctly set, otherwise your setup may be incorrect, refer to this &lt;a href="http://blogs.msdn.com/b/velocity/archive/2009/06/22/troubleshooting-velocity-series-ii.aspx"&gt;blog for troubleshooting hints&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/3386.clip_5F00_image002_5B00_6_5D00_.png"&gt;&lt;img height="59" width="349" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4762.clip_5F00_image002_5B00_6_5D005F00_thumb.png" alt="clip_image002[6]" border="0" title="clip_image002[6]" 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;Running the solution will show the following windows form:&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/3704.clip_5F00_image003_5B00_6_5D00_.png"&gt;&lt;img height="413" width="391" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4375.clip_5F00_image003_5B00_6_5D005F00_thumb.png" alt="clip_image003[6]" border="0" title="clip_image003[6]" 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;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;Demo #1, Basic Object Addition, Retrieval and Removal&lt;/h3&gt;
&lt;p&gt;This is the most commonly use APIs, as per the message in the Status text start by adding an object,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;first start by clicking the &lt;strong&gt;Add&lt;/strong&gt; button, this will add a single entry into the cache, the status will show &amp;ldquo;&amp;gt;&amp;gt;Add-Object Added to Cache [key=LockingDemo]&amp;rdquo;. &lt;/li&gt;
&lt;li&gt;Clicking the &lt;strong&gt;Get&lt;/strong&gt; button will show the content of the added object which was retrieved by leveraging the Key &amp;ldquo;lockingDemo&amp;rdquo;, the status will show &amp;ldquo;&amp;gt;&amp;gt; Get Object and reference retrieved from cache. [key=LockingDemo, Object=Object stored in cache]&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;At this point go back to the &amp;ldquo;Caching Administration Windows PowerShell&amp;rdquo; console and type:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt;Get-CacheStatistics default&lt;/em&gt; &lt;/p&gt;
&lt;p&gt;The RequestCount will be 1, this is the new added object had just got added&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Hit the &lt;strong&gt;Remove&lt;/strong&gt; button and then the &lt;strong&gt;Get&lt;/strong&gt; button, you will see the fail status as it indicates that no object was found. The same can be seen if an object is added and retrieved after 15 minutes, which is the default time to keep an item in the cache, this is further explore in the Demo #4 below.&lt;/li&gt;

&lt;/ul&gt;&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacache.add(v=WS.10).aspx"&gt;Add API&lt;/a&gt; can be thought as a type of insert statement but it only takes a key value pair. Note that the Get API merely retrieved whatever it found in the object in an optimistic manner, it did not care if it was changed by any other process, as it retrieved the latest version.&lt;/p&gt;
&lt;h3&gt;Demo #2, Version retrieval, GetIfNewer and Put&lt;/h3&gt;
&lt;p&gt;If you want to know when an object has changed from the last time it was retrieved then &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacache.getifnewer(v=WS.10).aspx"&gt;GetIfNewer&lt;/a&gt; is a good option. Looking at the code in the solution, when the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacache.get(v=WS.10).aspx"&gt;Get API&lt;/a&gt; was executed (in line 134 of form1.cs) a &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacacheitemversion(v=WS.10).aspx"&gt;DataCacheItemVersion&lt;/a&gt; was also collected, this can be thought of as a type of version for the gotten item. See line 143 in Form1.cs&lt;/p&gt;
&lt;p&gt;&lt;em&gt;RetrievedStrFromCache = (string)myDefaultCache.Get(myKey, out myVersionBeforeChange)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For simplicity, say it is retrieved as Version1, if another process comes and does a &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacache.put(v=WS.10).aspx"&gt;Put&lt;/a&gt; against the same item (by using the same key) then it will change its version to say Version2, in the same way the DataCacheItemVersion will get updated. GetIfNewer can be used to leverage this type of versioning, by using the DataCacheItemVersion retrieved in the Get API in the GetIfNewer API, it will know to return a NULL object if it finds an object with the same DataCacheItemVersion in cache, otherwise it will return the new (updated) object.&lt;/p&gt;
&lt;p&gt;Go back to the demo form, &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;click on the &lt;strong&gt;Add&lt;/strong&gt; button (if a valid object is still present the Object already exist exception will be raised)&lt;/li&gt;
&lt;li&gt;Then click on the &lt;strong&gt;GetIfNewer&lt;/strong&gt; button and you will get a message saying that a NULL object was retrieved. &lt;/li&gt;
&lt;li&gt;Now click on the &lt;strong&gt;Put&lt;/strong&gt; button (which can be thought as an update statement)&lt;/li&gt;
&lt;li&gt;Go back and click on the &lt;strong&gt;GetIfNewer&lt;/strong&gt; button, now you will get the object that the Put API just updated, the value string changed from &amp;ldquo;Object stored in cache&amp;rdquo; to &amp;ldquo;MOD 1 - Object stored in cache&amp;rdquo;. Note that clicking on the &lt;strong&gt;GetIfNewer&lt;/strong&gt; button again will return a NULL item since the version has not changed from the last time the API was executed. This also shows that the value of the DataCacheItemVersion also gets updated with each execution of the GetIfNewer API.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Similarly, if GetIfNewer is executed after doing a Remove and an Add, it will also retrieve an object since these two operations (Remove and Add) will have, in effect, modified the object.&lt;/p&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;Demo #3, Contention, GetAndLock, Unlock and PutAndUnlock&lt;/h3&gt;
&lt;p&gt;As explained, the Get API does an optimistic retrieval but there are cases when a pessimistic retrieval may be preferred. This scenario will be most adequately use for Resource data (shared reads &amp;amp; writes across multiple users). For those cases, the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacache.getandlock(v=WS.10).aspx"&gt;GetAndLock&lt;/a&gt; API will allow locking an object for a given period of time; the demo does it for 5 seconds. Two other things to keep in mind are the key and the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacachelockhandle(v=WS.10).aspx"&gt;DataCacheLockHandle&lt;/a&gt;, as these are needed to handle the locking semantics.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Running the demo:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click the &lt;strong&gt;Add&lt;/strong&gt; button, if an object already exist an exception will be shown.&lt;/li&gt;
&lt;li&gt;Click on the &lt;strong&gt;GetAndLock&lt;/strong&gt; button, this will collect a DataCacheLockHandle object that will be required to gracefully unlock the object (the Put API may also do this without requiring a DataCacheLockHandle, more on this further below).&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;GetAndLock&lt;/strong&gt; button again, an exception explaining that the object is already lock will be generated. &lt;/li&gt;
&lt;li&gt;Before the 5 seconds for expiration have taken place, hit the &lt;strong&gt;Unlock (Bad)&lt;/strong&gt; button, this will generate an exception due to the fact that even though the correct key is used, the incorrect DataCacheLockHandle is employed. &lt;/li&gt;
&lt;li&gt;If the &lt;strong&gt;GetAndLock&lt;/strong&gt; button is press right after (before the 5 seconds lock is reached) then the exception showing that the object is still lock will be shown, this since the previous unlock called was unsuccessful.&lt;/li&gt;
&lt;li&gt;When the &lt;strong&gt;Unlock (ok)&lt;/strong&gt; button is pressed, the object will be gracefully unlock, as this method uses the correct key and DataCacheLockHandle&lt;/li&gt;
&lt;li&gt;Pressing the &lt;strong&gt;GetAndLock&lt;/strong&gt; button will not show an exception but instead will lock the object again for 5 seconds.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The &lt;strong&gt;PutAndUnlock&lt;/strong&gt; button will also correctly unlock the object but, as stated by its name, it will update the object at the same time.&lt;/p&gt;
&lt;p&gt;NOTE: the &lt;strong&gt;Put&lt;/strong&gt; button will override the lock semantics; that is, the object will be unlock and update without requiring a DataCacheLockHandle. This is because the intent with the lock APIs is for all applications to honor it, so in order for the locking to be honored, it is incumbent upon the clients to be using the Lock methods since not using them will override the locking guarantees. &lt;/p&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;Demo #4, Enable Local cache&lt;/h3&gt;
&lt;p&gt;This demo goes over the ability to locally cache objects, this will save a round trip to the cache cluster, and in essence, it will eliminate the network delay to and back from the cache server. &lt;/p&gt;
&lt;p&gt;To start the demo start the &amp;ldquo;Caching Administration Windows PowerShell&amp;rdquo; tool and run the following commands&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt;restart-cachecluster&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt;get-cachestatistics default&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The purpose here is to clean all the objects currently cache; the statistics results should show all zeros.&lt;/p&gt;
&lt;p&gt;Running the demo:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click the &lt;strong&gt;Add&lt;/strong&gt; button, as seen in Demo #1, after adding an object the statistics show a RequestCount of 1.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Enabled&lt;/strong&gt; from the local cache drop down&lt;/li&gt;
&lt;li&gt;Click on the &lt;strong&gt;Get&lt;/strong&gt; button a few times.&lt;/li&gt;
&lt;li&gt;Go back to the &amp;ldquo;Caching Administration Windows PowerShell&amp;rdquo; tool and run the &amp;ldquo;Get-cacheStatistics default&amp;rdquo; command again. The requestCount should still stay at 1, this is because the configuration provider did not register the request since it was locally served. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note that if you do a GetIfNewer instead of a Get, the requestCount will increase; this is because GetIfNewer cannot be locally supplied, as it needs to check with all the other cache hosts (in this case, the XML configuration provider).&lt;/p&gt;
&lt;p&gt;To achieved the demonstrated, two &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacachefactory(v=WS.10).aspx"&gt;DataCacheFactories&lt;/a&gt; are leverage - see line 54~59 in form1.cs. The DataCacheFactory named &amp;ldquo;myCacheFactory&amp;rdquo; is the one use for non-local cache and the one named &amp;ldquo;myCacheFactory_LC&amp;rdquo; is the one setup for local cache, its configuration property is defined in line 57, as follows.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;//Create the local cache cacheFactory constructor, kept for 5 min.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;configuration.LocalCacheProperties = new DataCacheLocalCacheProperties(1000, new TimeSpan(0, 5, 0), DataCacheLocalCacheInvalidationPolicy.TimeoutBased);&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Note that the timeout is setup to 5 minutes, to demo it,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go back to the &amp;ldquo;Caching Administration Windows PowerShell&amp;rdquo; tool and run the &amp;ldquo;Get-cacheStatistics default&amp;rdquo; and make note of the requestCount&lt;/li&gt;
&lt;li&gt;Makes sure the local cache drop down is set to &lt;strong&gt;Enabled&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Add&lt;/strong&gt; button&lt;/li&gt;
&lt;li&gt;Wait for 5 minutes and then hit the &lt;strong&gt;Get &lt;/strong&gt;button&lt;/li&gt;
&lt;li&gt;Go back to the &amp;ldquo;Caching Administration Windows PowerShell&amp;rdquo; tool and run the &amp;ldquo;Get-cacheStatistics default&amp;rdquo; again. The requestCount will have gone up, as the local cache item would have expired and had to be retrieved from the host cache. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Reviewed by: Christian Martinez and Mark Simms&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10098693" 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/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/-NET4/">.NET4</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/Azure+AppFabric+Cache/">Azure AppFabric Cache</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric+Cache/">AppFabric Cache</category></item><item><title>Hybrid Cloud Solutions With Windows Azure AppFabric Middleware</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/29/hybrid-cloud-solutions-with-windows-azure-appfabric-middleware.aspx</link><pubDate>Tue, 30 Nov 2010 06:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10098143</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=10098143</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10098143</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/29/hybrid-cloud-solutions-with-windows-azure-appfabric-middleware.aspx#comments</comments><description>&lt;h1&gt;Abstract &lt;/h1&gt;  &lt;p&gt;(updated version)&lt;/p&gt;  &lt;p&gt;Technical and commercial forces are causing Enterprise Architects to evaluate moving established &lt;a href="http://en.wikipedia.org/wiki/On-premises_software"&gt;on-premises&lt;/a&gt; applications into the &lt;a href="http://en.wikipedia.org/wiki/Cloud_software#Application"&gt;cloud&lt;/a&gt; – the Microsoft Windows Azure Platform. &lt;/p&gt;  &lt;p&gt;This blog post will demonstrate that there are established application architectural patterns that can get the best of both worlds: applications that continue to live on-premises while interacting with other applications that live in the cloud – the &lt;i&gt;hybrid&lt;/i&gt; approach. In many cases, such &lt;i&gt;hybrid&lt;/i&gt; architectures are not just a transition point — but a requirement since certain applications or data is required to remain on-premises largely for security, legal, technical and procedural reasons. &lt;/p&gt;  &lt;p&gt;The &lt;i&gt;cloud&lt;/i&gt; is new, and the &lt;i&gt;hybrid &lt;/i&gt;cloud is even newer. There are many technologies that have just been released or announced so there is no one source for authentic information, especially one that compares, contrasts, and ties it all together. This blog, and a few more that will follow, is an attempt to demystify and make sense of it all. We begin with a brief review of two prevalent deployment paradigms and their influence on architectural patterns: On-premises and Cloud. After that, we discuss developing the &lt;i&gt;hybrid&lt;/i&gt; architecture. &lt;/p&gt;  &lt;p&gt;This posting takes an architect’s perspective and surveys the major building block components that compose this &lt;i&gt;hybrid&lt;/i&gt; architecture. We also match requirements against the capabilities of available and announced &lt;a href="http://www.microsoft.com/windowsazure/"&gt;Windows Azure&lt;/a&gt; and &lt;a href="http://www.microsoft.com/en-us/appfabric/azure/default.aspx"&gt;Windows Azure AppFabric&lt;/a&gt; technologies. Our discussions also factor in the usage costs and strategies for keeping these costs in check. We conclude with a survey of interesting and relevant Windows Azure technologies announced at &lt;a href="http://www.microsoft.com/events/pdc/"&gt;Microsoft PDC 2010 - Professional Developer's Conference&lt;/a&gt; during October 2010. &lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;On-Premises Solutions&lt;/h1&gt;  &lt;p&gt;On-premises solutions are usually designed to access data repositories (through client or browser applications) and services hosted inside of a corporate network. In the graphic below, Web Server and Database Server are within a corporate firewall. The user, via the browser, is authenticated and has access to data. &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0023" border="0" alt="clip_image0023" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7345.clip_5F00_image0023_5F00_09D293F9.jpg" width="478" height="261" /&gt;&lt;i&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Figure 1: Typical On-Premises Solution (Source - Microsoft.com)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ce40e4e1-9838-4c89-a197-a373b2a60df2"&gt;Patterns and Practices Application Architecture Guide 2.0&lt;/a&gt; provides an exhaustive survey of the on-premises Applications. This Architecture Guide is a great reference document and helps you understand the underlying architecture and design principles and patterns for developing successful solutions on the Microsoft application platform and the .NET Framework. The Microsoft Application Platform is composed of products, infrastructure components, run-time services, and the .NET Framework, as detailed in the following table (source: .NET Application Architecture 434 Guide, 2nd Edition). &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Table 1: Microsoft Application Platform (Source - Microsoft.com)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0043" border="0" alt="clip_image0043" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5707.clip_5F00_image0043_5F00_112E53A6.jpg" width="498" height="370" /&gt;&lt;/p&gt;  &lt;p&gt;The on-premises architectural patterns are well documented (above), so in this blog post we will not dive into prescriptive technology selection guidance here, however let’s briefly review some core concepts since we will reference them while elaborating &lt;i&gt;hybrid &lt;/i&gt;cloud architectural patterns. &lt;/p&gt;  &lt;h2&gt;Hosting The Application&lt;/h2&gt;  &lt;p&gt;Commonly* on-premises applications (with the business logic) run on &lt;a href="http://www.microsoft.com/windowsserver2008/en/us/internet-information-services.aspx"&gt;IIS&lt;/a&gt; (as an &lt;a href="http://technet.microsoft.com/en-us/library/cc735084(WS.10).aspx"&gt;IIS w3wp process&lt;/a&gt;) or as a &lt;a href="http://msdn.microsoft.com/en-us/library/d56de412(VS.80).aspx"&gt;Windows Service Application&lt;/a&gt;. The recent release of &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849.aspx"&gt;Windows Server AppFabric&lt;/a&gt; makes it easier to build, scale, and manage Web and &lt;a href="http://msdn.microsoft.com/en-us/library/bb220803.aspx#whatarecomapps_topic3"&gt;Composite (WCF, SOAP, REST and Workflow Services)&lt;/a&gt; Applications that run on IIS.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;* As indicated in Table 1 (above) &lt;/em&gt;&lt;a href="http://www.microsoft.com/biztalk/en/us/default.aspx"&gt;&lt;em&gt;Microsoft BizTalk Server &lt;/em&gt;&lt;/a&gt;&lt;em&gt;is capable of hosting on-premises applications; however, for sake of this blog, we will focus on Windows Server AppFabric&lt;/em&gt;&lt;/p&gt;  &lt;h2&gt;Accessing On-premises Data&lt;/h2&gt;  &lt;p&gt;Your on-premises applications may access data from the local file system or network shares. They may also utilize databases hosted in &lt;a href="http://www.microsoft.com/sqlserver/2008/en/us/"&gt;Microsoft SQL Server&lt;/a&gt; or other relational and non-relational data sources. In addition, your applications hosted in IIS may well be leveraging &lt;a href="http://www.microsoft.com/windowsserver2008/en/us/app-main.aspx"&gt;Windows Server AppFabric Cache&lt;/a&gt; for your session state, as well as other forms of reference or resource data. &lt;/p&gt;  &lt;h2&gt;Securing Access&lt;/h2&gt;  &lt;p&gt;Authenticated access to these data stores are traditionally performed by inspecting certificates, user name and password values, or &lt;a href="http://msdn.microsoft.com/en-us/library/yk7437c8.aspx"&gt;NTLM/Kerberos&lt;/a&gt; credentials. These credentials are either defined in the data source themselves, heterogeneous repositories such as in SQL Logins, local machine accounts, or in &lt;a href="file:///C:\Users\surenm\AppData\Roaming\Microsoft\Word\en.wikipedia.org\wiki\Ldap"&gt;directory Services (LDAP)&lt;/a&gt; such as &lt;a href="http://www.microsoft.com/windowsserver2008/en/us/active-directory.aspx"&gt;Microsoft Windows Server Active Directory&lt;/a&gt;, and are generally verifiable within the same network, but typically not outside of it unless you are using &lt;a href="http://technet.microsoft.com/en-us/library/cc776617(WS.10).aspx"&gt;Active Directory Federation Services - ADFS&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Management&lt;/h2&gt;  &lt;p&gt;Every system exposes a different set of APIs and a different administration console to change its configuration – which obviously adds to the complexity; e.g., Windows Server for configuring network shares, SQL Server Management Studio for managing your SQL Server Databases; and IIS Manager for the Windows Server AppFabric based Services. &lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Cloud Solutions &lt;/h1&gt;  &lt;p&gt;Cloud solutions typically access local resources and services, but they can eventually interact with remote services running on-premises or in the cloud. Cloud applications usually hosted by a ‘provider managed’ runtime environment that provides hosting services, computational services, storage services, queues, management services, and load-balancers. In summary, cloud applications consist of two main components: those that execute application code and those that provide data used by the application. To quickly acquaint you with the cloud components, here is a contrast with popular on-premises technologies: &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Table 2: Contrast key On-Premises and Cloud Technologies&lt;/em&gt;     &lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="139"&gt;           &lt;p&gt;&lt;b&gt;Category&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="102"&gt;           &lt;p&gt;&lt;b&gt;On-Premises &lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="114"&gt;           &lt;p&gt;&lt;b&gt;Cloud &lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="139"&gt;           &lt;p&gt;&lt;b&gt;Application Hosting&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="102"&gt;           &lt;p&gt;Windows Server&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="114"&gt;           &lt;p&gt;Windows Azure &lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="139"&gt;           &lt;p&gt;&lt;b&gt;Message Queue&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="102"&gt;           &lt;p&gt;MSMQ&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="114"&gt;           &lt;p&gt;Azure Queue&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="139"&gt;           &lt;p&gt;&lt;b&gt;Unstructured Data Store&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="102"&gt;           &lt;p&gt;Windows Folder&lt;/p&gt;            &lt;p&gt;Windows Drives&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="114"&gt;           &lt;p&gt;Azure Blobs&lt;/p&gt;            &lt;p&gt;Azure Table&lt;/p&gt;            &lt;p&gt;Azure Drive (XDrive)&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="139"&gt;           &lt;p&gt;&lt;b&gt;Relational Data Store&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="102"&gt;           &lt;p&gt;SQL Server&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="114"&gt;           &lt;p&gt;SQL Azure&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="139"&gt;           &lt;p&gt;&lt;b&gt;Application Cache&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="102"&gt;           &lt;p&gt;AppFabric Cache&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="114"&gt;           &lt;p&gt;Azure AppFabric Cache&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;em&gt;NOTE: This table is not intended to compare and contrast all Azure technologies. Some of them may not have an equivalent on-premise counterpart. &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The graphic below presents an architectural solution for ‘Content Delivery’. While Content creation and its management is via on-premises applications; the content storage (Azure Blob Storage) and delivery is via Cloud – Azure Platform infrastructure. In the following sections we will review the components that enable this architecture. &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0063" border="0" alt="clip_image0063" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6470.clip_5F00_image0063_5F00_14EBF876.jpg" width="409" height="327" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Figure 2: Typical Cloud Solution&lt;/em&gt;&lt;/p&gt;  &lt;h2&gt;Running Applications In Windows Azure&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://www.microsoft.com/windowsazure/"&gt;Windows Azure&lt;/a&gt; is the underlying operating system for running your cloud services on the &lt;a href="http://www.microsoft.com/en-us/appfabric/azure/default.aspx"&gt;Windows Azure AppFabric&lt;/a&gt; Platform. The three core services of Windows Azure in brief are as follows:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;b&gt;Compute&lt;/b&gt;: The compute or hosting service offers scalable hosting of services on 64-bit Windows Server platform with Hyper-V support. The platform is virtualized and designed to scale dynamically based on demand. The Azure platform runs web roles on Internet Information Server (IIS) and worker roles as Windows Services. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Storage&lt;/b&gt;: There are three types of storage supported in Windows Azure: &lt;a href="http://msdn.microsoft.com/en-us/library/dd179360.aspx"&gt;Table Services&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/dd135731.aspx"&gt;Blob Services&lt;/a&gt;, and &lt;a href="http://msdn.microsoft.com/en-us/library/dd179409.aspx"&gt;Queue Services&lt;/a&gt;. Table Services provide storage capabilities for structured data, whereas Blob Services are designed to store large unstructured files such as videos, images, batch files in the cloud. Table Services are not to be confused with SQL Azure; typically you can store the high-volume data in low-cost Azure Storage and use (relatively) expensive SQL Azure to store indexes to this data. Finally, Queue Services are the asynchronous communication channels for connecting between Services and applications not only in Windows Azure but also from on-premise applications. &lt;a href="http://blogs.msdn.com/b/windowsazureappfabric/archive/2010/10/28/introduction-to-windows-azure-appfabric-caching-ctp.aspx?wa=wsignin1.0"&gt;Caching Services&lt;/a&gt;, currently available via &lt;a href="http://portal.appfabriclabs.com/"&gt;Windows Azure AppFabric LABS&lt;/a&gt;, is another strong storage option. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Management&lt;/b&gt;: The management service supports automated infrastructure and service management capabilities to Windows Azure cloud services. These capabilities include automatic and transparent provisioning of virtual machines and deploying services in them, as well as configuring switches, access routers, and load balancers. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;A detailed review on the above three core services of Windows Azure is available in the subsequent sections. Application code execution on Windows Azure is facilitated by &lt;a href="http://msdn.microsoft.com/en-us/library/dd179341.aspx"&gt;Web and Worker roles&lt;/a&gt;. Typically, you would host Websites (ASP.NET, MVC2, CGI, etc.) in a Web Role and host background or computational processes in a Worker role. The on-premises equivalent for a Worker role is a Windows Service. This architecture leaves a gray area — &lt;i&gt;where should you &lt;/i&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb332338.aspx"&gt;&lt;i&gt;host WCF Services&lt;/i&gt;&lt;/a&gt;&lt;i&gt;?&lt;/i&gt; The answer is – it depends! Let me elaborate. When building on-premises services, you can host a WCF Service in a Windows Service. For example, in BizTalk, a WCF Receive Location can be hosted within an in-process host instance that runs as a Windows Service). In Windows Azure you can host a WCF Service as Worker role. While you can host a WCF Service (REST or SOAP) in either a Worker Role or Web role, you typically host these services in a Web role; the one exception is when your WCF service specifically needs to communicate via TCP/IP endpoints. Web roles are capable of exposing HTTP and HTTP(S) endpoints; Worker roles add the ability to expose TCP endpoints. &lt;/p&gt;  &lt;h2&gt;Storing &amp;amp; Retrieving Cloud Hosted Data&lt;/h2&gt;  &lt;p&gt;Applications that require data storage in the cloud can leverage a variety of technologies including &lt;a href="http://www.microsoft.com/en-us/sqlazure/default.aspx"&gt;SQL Azure&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/dd179355.aspx"&gt;Windows Azure Storage&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/windowsazureappfabric/archive/2010/10/28/introduction-to-windows-azure-appfabric-caching-ctp.aspx?wa=wsignin1.0"&gt;Azure AppFabric Cache&lt;/a&gt;, Virtual Machine (VM) instance local storage, &lt;a href="http://msdn.microsoft.com/en-us/library/ee758708.aspx"&gt;Instance Local Storage&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/windowsazure/archive/2010/02/02/beta-release-of-windows-azure-drive.aspx"&gt;Azure Drive (XDrive)&lt;/a&gt;. Determining the right technology is a balancing exercise in managing trade-offs, costs, and capabilities. The following sections will attempt to provide prescriptive guidance on what usage scenario each storage option is best suited for. The key takeaway is this: whenever possible, co-locate data and the consuming application. Your data in the cloud, stored in SQL Azure or Windows Azure Storage, should be accessible via the ‘local’ Azure “fabric” to your applications. This has positive performance and a beneficial cost model when both the application and the data live within the same datacenter. Co-location is enabled via the 'Region' you choose for the Microsoft Data Center. &lt;/p&gt;  &lt;h3&gt;SQL Azure&lt;/h3&gt;  &lt;p&gt;SQL Azure provides an RDBMS in the cloud, and functions for all intents and purposes similarly to your on-premises version of SQL Server. This means that your applications can access data in SQL Azure using the Tabular Data Stream (&lt;a href="http://msdn.microsoft.com/en-us/library/aa174503(SQL.80).aspx"&gt;TDS&lt;/a&gt;) protocol; or, in other words, your application uses the same data access technologies (e.g. ADO.NET, LINQ to SQL, EF, etc.) used by on-premises applications to access information on a local SQL Server. The only thing you need to do is change the SQL Client connection strings you’ve been using. You just have to change the values to point to the server database hosted by SQL Azure. Of course I am glossing over some details like the SQL Azure connection string which contains other specific settings such as encryption, explicit username (in very strict format username@servername) and password – I am sure you get the drift here.&amp;#160; SQL Azure Labs demonstrate an alternative mechanism for allowing your application to interact with SQL Azure via &lt;a href="http://msdn.microsoft.com/en-us/data/ee844254.aspx"&gt;OData&lt;/a&gt;. OData provides the ability to perform CRUD operations using REST and can retrieve query results formatted as AtomPub or JSON. Via .NET programming, you can interact at a higher level using a &lt;i&gt;DataServicesContext&lt;/i&gt; and LINQ.&lt;/p&gt;  &lt;h4&gt;Securing Access&lt;/h4&gt;  &lt;p&gt;When using TDS, access is secured using SQL Accounts (i.e., your SQL Login and password must be in the connection string), however there is one additional layer of security you will need to be aware of. In most on-premises architectures, your SQL Server database lives behind a firewall, or at most in a DMZ, which you would rarely expose. However, no matter where they are located, these repositories are not directly accessible to applications living outside the corporate boundaries. Of course, even for on-premises solutions you can use IPSEC to restrict the range of machines that can access the SQL Server machine. Eventually, access to these databases is mediated and controlled by web services (SOAP, WCF).&lt;/p&gt;  &lt;p&gt;&lt;i&gt;What happens when your database lives on Azure, in an environment effectively available to the &lt;/i&gt;&lt;i&gt;entire big bad&lt;/i&gt;&lt;i&gt; world?&lt;/i&gt; SQL Azure also provides a firewall that you can configure to restrict access to a set of IP address ranges, which you would configure to include the addresses used by your on-premises applications. In the graphic below notice the ‘Firewall Settings’ tab where the IP Address Range is specified. &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0083" border="0" alt="clip_image0083" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4152.clip_5F00_image0083_5F00_51C07A48.jpg" width="390" height="192" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Figure 3: SQL Azure Firewall Settings &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;When using OData, access is secured by configuration. You can enable anonymous access whereby the anonymous account maps to a SQL Login created on your database, or you can map &lt;a href="http://acs.codeplex.com/wikipage?title=Service%20Identities"&gt;Access Control Service (ACS) identities&lt;/a&gt; to specific SQL Logins, whereby ACS takes care of the authentication. In the OData approach, the Firewall access rules are effectively circumvented because only the OData service itself needs to have access to the database hosted by SQL Azure from within the datacenter environment. &lt;/p&gt;  &lt;h4&gt;Management &lt;/h4&gt;  &lt;p&gt;You manage your SQL Azure database the same way you might administer an on-premises SQL Server database, by using SQL Server Management Studio (SSMS). Alternately, and provided you allowed Microsoft Services in the SQL Azure firewall, you can use the Database Manager for SQL Azure (codename “&lt;a href="http://blogs.msdn.com/b/sqlazure/archive/2010/10/29/10083115.aspx"&gt;Project Houston&lt;/a&gt;”) which provides the environment for performing many of the same tasks you would perform via SSMS. The &lt;a href="http://blogs.msdn.com/b/sqlazure/archive/2010/12/01/10099203.aspx"&gt;&lt;b&gt;Database Manager for SQL Azure&lt;/b&gt;&lt;/a&gt; is a part of the Windows Azure platform developer portal, and provides a lightweight, web-based database management and querying service for SQL Azure databases. This allows customers to have a streamlined experience within the web browser without having to download any tools.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0103" border="0" alt="clip_image0103" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4251.clip_5F00_image0103_5F00_408C9CA5.jpg" width="427" height="302" /&gt;&lt;/p&gt;  &lt;p&gt;Figure 4: Database Manager for SQL Azure (Source - PDC 10)&lt;/p&gt;  &lt;p&gt;One of the primary technical differences between the traditional SSMS management option is the required use of port 1433; in contrast, “Houston” is web-based and leverages port 80. An awesome demo on the capabilities of the Database Manager is available &lt;a href="http://player.microsoftpdc.com/Session/fda31e30-994a-4407-bbc1-2e2ec0cd7187"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;h4&gt;Typical Usage &lt;/h4&gt;  &lt;p&gt;SQL Azure is best suited for storing data that is relational, specifically where your applications expect the database server to perform the join computation and return only the processed results. SQL Azure is a good choice for scenarios with high transaction throughput (view case studies &lt;a href="http://www.microsoft.com/windowsazure/evidence/default.aspx?%24facet0%24=Company&amp;amp;%24view%24=1&amp;amp;Technology=EQ.SQL%20Azure"&gt;here&lt;/a&gt;) since it has a flat-rate pricing structure based on the size of data stored. Additionally, query evaluation is distributed across multiple nodes. &lt;/p&gt;  &lt;h3&gt;Windows Azure Storage (Blobs, Tables, Queues)&lt;/h3&gt;  &lt;p&gt;Windows Azure Storage provides storage services for data in the form of metadata enriched blobs, dictionary-like tables, and simple persistent queues. You access data via HTTP or HTTP(S) by leveraging the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.aspx"&gt;&lt;b&gt;StorageClient&lt;/b&gt;&lt;/a&gt; library which provides 3 different classes, respectively &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.cloudblobclient.aspx"&gt;&lt;i&gt;CloudBlobClient&lt;/i&gt;&lt;/a&gt;&lt;i&gt;, &lt;/i&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.cloudtableclient.aspx"&gt;&lt;i&gt;CloudTableClient&lt;/i&gt;&lt;/a&gt;&lt;i&gt;, &lt;/i&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.cloudqueueclient.aspx"&gt;&lt;i&gt;CloudQueueClient&lt;/i&gt;&lt;/a&gt;), to access storage services. For example, the &lt;i&gt;CloudTableClient&lt;/i&gt; class provides a DataServices context that enables use of LINQ for querying table data. All data stored by Windows Azure Storage can also be accessed via REST. The AppFabric CAT (team) plans to provide code samples via this blog site to demonstrate this functionality – stay tuned. &lt;/p&gt;  &lt;h4&gt;Securing Access&lt;/h4&gt;  &lt;p&gt;Access to any of the Windows Azure Storage blobs, tables, or queues is provided through symmetric key authentication whereby an &lt;a href="http://msdn.microsoft.com/en-us/library/ff934690.aspx"&gt;account name and account key pair &lt;/a&gt;must be included with each request. In addition, access to the Azure blobs can be secured via the mechanism known as the &lt;a href="http://msdn.microsoft.com/en-us/library/ee395415.aspx"&gt;Shared Access Signature&lt;/a&gt;. &lt;/p&gt;  &lt;h4&gt;Management&lt;/h4&gt;  &lt;p&gt;Currently there is no single tool for managing Windows Azure Storage. There are quite a few samples as well as third-party tools. The graphic below is from the Azure Storage Explorer tool, available for &lt;a href="http://azurestorageexplorer.codeplex.com/"&gt;download&lt;/a&gt; via Codeplex. &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0123" border="0" alt="clip_image0123" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1033.clip_5F00_image0123_5F00_6B1857B5.jpg" width="394" height="290" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Figure 5: Azure Storage Explorer (Source – Codeplex)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;In general, a Windows Azure storage account, which wraps access to all three forms of storage and services, is created through the Windows Azure Portal, but is managed using the API’s. &lt;/p&gt;  &lt;h4&gt;Typical Usage&lt;/h4&gt;  &lt;p&gt;Windows Azure storage provides unique value propositions that make it fit within your architecture for diverse reasons. &lt;/p&gt;  &lt;h5&gt;Blob Storage&lt;/h5&gt;  &lt;p&gt;Charges for blob storage are based on both amount of storage used, and by the number of storage transactions, But the pricing model is designed to scale transparently to any size. This makes it best suited to the task of storing files and larger objects (high resolution videos, radiology scans, etc.) that can be cached or are otherwise not frequently accessed. &lt;/p&gt;  &lt;h5&gt;Table Storage&lt;/h5&gt;  &lt;p&gt;Table storage is billed the same way as blob storage, but its unique approach to indexing at large scale makes it useful in situations where: (a) you need to efficiently access data from datasets larger than the 50 GB per database maximum of SQL Azure; and (b) where you don’t expect to be performing joins, or are comfortable enabling the client to download a larger chunk of data and perform the joins and computations on the client side. &lt;/p&gt;  &lt;h5&gt;Queue Storage&lt;/h5&gt;  &lt;p&gt;Queues are best suited for storing pointers to work that needs to be done, due to their limited storage capacity of a maximum of 8K per message, in a manner ensuring ordered access. Often, you will use queues to drive the work performed by your Worker roles, but they can also be used to drive the work performed by your on-premises services. Bottom-line: Queues can be effectively used by a Web Role to exchange control messages in an asynchronous manner with a Worker Role running within the same application, or to exchange messages with on-premises applications&lt;/p&gt;  &lt;h3&gt;Azure AppFabric Cache&lt;/h3&gt;  &lt;p&gt;The Azure AppFabric Cache, currently in CTP/Beta as of November 2010, should give you the same high-performance, in-memory, distributed cache available with Windows Server AppFabric, as a hosted service. (The technology is in pre-release mode and hence the caveat!) Since this is an Azure AppFabric Service, you are not responsible for managing servers participating in the data cache cluster. Your Windows Azure applications can access the cached data through the client libraries in the Windows Azure AppFabric SDK. &lt;/p&gt;  &lt;h4&gt;Securing Access&lt;/h4&gt;  &lt;p&gt;Access to a cache is secured by a combination of generated authentication tokens with authorization rules (e.g., Read/Write versus Read only) as defined in the Access Control Service.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0143" border="0" alt="clip_image0143" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4572.clip_5F00_image0143_5F00_1CC34F3E.jpg" width="590" height="263" /&gt;Figure 6: Access Control for Cache &lt;/p&gt;  &lt;h4&gt;Management&lt;/h4&gt;  &lt;p&gt;At this time, creation of a cache, as well securing access to it, is performed via the &lt;a href="https://portal.appfabriclabs.com/"&gt;Windows Azure AppFabric labs portal&lt;/a&gt;. Subsequent to its release this will be available in the commercial &lt;a href="https://appfabric.azure.com/"&gt;Azure AppFabric portal&lt;/a&gt;.&lt;/p&gt;  &lt;h4&gt;Typical Usage &lt;/h4&gt;  &lt;p&gt;Clearly the cache is best suited for persisting data closer to your application, whether its data stored in SQL Azure, Windows Azure Storage, or as the result of a call to another service—or a combination of all of them. This approach is called the &lt;b&gt;cache-aside model&lt;/b&gt;, whereby requests for data made by your application first check the cache and only query the actual data source, and subsequently add it to the cache, if it’s not present. Typically we are seeing caches used in the following scenarios:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;As a &lt;b&gt;scalable session store&lt;/b&gt; for your web applications running on ASP.NET. &lt;/li&gt;    &lt;li&gt;As an &lt;b&gt;output cache&lt;/b&gt; for your web application. &lt;/li&gt;    &lt;li&gt;For &lt;b&gt;objects&lt;/b&gt; created from &lt;i&gt;resultsets&lt;/i&gt; from SQL or from costly web service calls, stored in cache and called from your web or worker role. &lt;/li&gt;    &lt;li&gt;As a &lt;b&gt;scratch pad&lt;/b&gt; in the cloud for your applications to use. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Using VM local storage &amp;amp; Azure Drives &lt;/h3&gt;  &lt;p&gt;When you create an instance in Windows Azure, you are creating an instance of a &lt;a href="http://blogs.msdn.com/b/usisvde/archive/2010/03/29/vm-support-in-windows-azure.aspx"&gt;Virtual Machine (VM)&lt;/a&gt;. VM, just like its on-premises counterpart, can make use of locally attached drives for storage or network shares. Windows &lt;a href="http://blogs.msdn.com/b/windowsazure/archive/2010/02/02/beta-release-of-windows-azure-drive.aspx"&gt;Azure Drives&lt;/a&gt; are similar, but not exactly the same as, network shares. They are an NTFS formatted drive stored as a page blob in Windows Azure Storage, and accessed from your VM instance by drive letter. These drives can be mounted exclusively to a single VM instance with read/write privileges, or to multiple VM instances as read-only drives. When such a drive is mounted, it caches data read in local VM storage, which enhances the read performance of subsequent accesses for the same data.&lt;/p&gt;  &lt;h4&gt;Securing Access&lt;/h4&gt;  &lt;p&gt;An Azure Cloud Drive is really just a façade on top of a page blob, so access to the drive effectively amounts to having access to the blob store using Windows Storage Account credentials (i.e., account name and account key).&lt;/p&gt;  &lt;h4&gt;Management &lt;/h4&gt;  &lt;p&gt;For blobs, there is limited tooling for managing Azure drives outside of the StorageClient API’s. In fact, there is no portal for creating Azure Cloud drives. However, there are samples on Codeplex that help you create and manage Azure drives. The &lt;b&gt;Windows Azure MMC Snap-In&lt;/b&gt; is available and can be downloaded from &lt;a href="http://code.msdn.microsoft.com/windowsazuremmc"&gt;here&lt;/a&gt; – and the graphic below provides you a quick peek into the familiar look/feel of the MMC. &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0163" border="0" alt="clip_image0163" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0044.clip_5F00_image0163_5F00_1CFFD273.jpg" width="371" height="269" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Figure 7: Windows Azure MMC Snap-In (Source - MSDN) &lt;/em&gt;&lt;/p&gt;  &lt;h4&gt;Typical Usage &lt;/h4&gt;  &lt;p&gt;Cloud drives have a couple of unique attributes that make them interesting choices in &lt;i&gt;hybrid&lt;/i&gt; architecture. To begin with, if you need drive-letter based access to your data from your Windows Azure application and you want it to survive VM instance failure, a cloud drive is your best option. Beyond that, you can mount a cloud drive to instances as read-only. This enables sharing of large reference files across multiple Windows Azure roles. What’s more, you can create a VHD, for example, using Window 7’s Disk Management MMC and load your VHD to the blob storage for use by your VM instances, effectively cloning an on-premises drive and extending its use into the cloud.&lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Hybrid Cloud Solutions: Exposing On-premises Services to Azure Hosted Services&lt;/h1&gt;  &lt;p&gt;Unlike ‘pure’ cloud solutions, &lt;i&gt;hybrid &lt;/i&gt;solutions have a set of “on-premises” 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. For the purposes of this article, and as illustrated in the diagram below, we will focus on the scenario where your on-premises applications are services hosted in &lt;b&gt;Windows Server AppFabric&lt;/b&gt; and then communicate to other portions of your hybrid solution running in the cloud.&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Fig-42" border="0" alt="Fig-42" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6242.Fig_2D00_42_5F00_478B8D83.png" width="557" height="444" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Figure 8: Typical Hybrid Cloud Solution&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Traditionally, to connect your on-premises applications to the off-premises applications (cloud or otherwise), you would begin by “poking” a hole in your firewall and configuring NAT routing so that Internet clients can talk to your services directly. This approach has numerous issues and limitations, not the least of which is the management overhead, security concerns, and configuration challenges. &lt;/p&gt;  &lt;h2&gt;Connectivity &lt;/h2&gt;  &lt;p&gt;So the big question here is: How&lt;i&gt; do I get my on-&lt;/i&gt;&lt;i&gt;premises&lt;/i&gt;&lt;i&gt; services to talk to my Azure hosted services?&amp;#160; &lt;/i&gt;There are two approaches you can take: You can use the &lt;b&gt;Azure AppFabric Service Bus&lt;/b&gt;, or you can use &lt;b&gt;Windows Azure Connect&lt;/b&gt;.&lt;/p&gt;  &lt;h3&gt;Using Azure AppFabric Service Bus&lt;/h3&gt;  &lt;p&gt;If your on-premises solution includes WCF Services, WCF Workflow Services, SOAP Services, or REST services that communicate via HTTP(S) or TCP you can use the Service Bus to create an externally accessible endpoint in the cloud through which your services can be reached. Clients of your solution, whether they are other Windows Azure hosted services, or Internet clients, simply communicate with that end-point, and the &lt;a href="http://www.microsoft.com/en-us/appfabric/azure/middleware-services.aspx#ServiceBus"&gt;AppFabric Service Bus&lt;/a&gt; takes care of relaying traffic securely to your service and returning replies to the client. The graphic below (from &lt;a href="http://www.microsoft.com/en-us/appfabric/azure/middleware-services.aspx#ServiceBus"&gt;http://www.microsoft.com/en-us/appfabric/azure/middleware-services.aspx#ServiceBus&lt;/a&gt;) demonstrates the Service Bus functionality. &lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image0203" border="0" alt="clip_image0203" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3034.clip_5F00_image0203_5F00_2A55BFAC.jpg" width="590" height="390" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Figure 9: Windows Azure AppFabric Service Bus (Source - Microsoft.com) &lt;/em&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The key value proposition of leveraging the Service Bus is that it is designed to transparently communicate across firewalls, NAT gateways, or other challenging network boundaries that exist between the client and the on-premises service. You get the following additional benefits: &lt;/li&gt;    &lt;li&gt;The actual endpoint address of your services is never made available to clients. &lt;/li&gt;    &lt;li&gt;You can move your services around because the clients are only bound to the Service Bus endpoint address, which is a virtual, not a physical, address. &lt;/li&gt;    &lt;li&gt;If both the client and the service happen to be on the same LAN and could therefore communicate directly, the Service Bus can set them up with a direct link that removes the hop out to the cloud and back and thereby improves throughput and latency. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Securing Access to Service Bus Endpoints&lt;/h4&gt;  &lt;p&gt;Access to the Service Bus is controlled via the &lt;b&gt;Access Control Service&lt;/b&gt;. Applications that use the Windows Azure AppFabric Service Bus are required to perform security tasks for configuration/registration, or for invoking service functionality. Security tasks include both authentication and authorization using tokens from the Windows Azure AppFabric Access Control service. When permission to interact with the service has been granted by the AppFabric Service Bus, the service has its own security considerations that are associated with the authentication, authorization, encryption, and signatures required by the message exchange itself. This second set of security issues has nothing to do with the functionality of the AppFabric Service Bus; it is purely a consideration of the service and its clients. There are four kinds of authentication currently available to secure access to the Service Bus: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SharedSecret, a slightly more complex but easy-to-use form of username/password authentication. &lt;/li&gt;    &lt;li&gt;SAML, which can be used to interact with SAML 2.0 authentication systems. &lt;/li&gt;    &lt;li&gt;SimpleWebToken, uses the OAuth Web Resource Authorization Protocol (WRAP) and Simple Web Tokens (SWT). &lt;/li&gt;    &lt;li&gt;Unauthenticated, that enables interaction with the service endpoint without any authentication behavior. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Selection of the authentication mode is generally dictated by application connecting to the Service Bus. You can read more on this topic &lt;a href="http://msdn.microsoft.com/en-us/library/dd582773.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;h4&gt;Cost Considerations&lt;/h4&gt;  &lt;p&gt;Service Bus usage is charged by the number of concurrent connections to the Service Bus endpoint. This means that when an on-premises or cloud-hosted service registers with the Service Bus and opens its listening endpoint, it is considered as one connection. When a client subsequently connects to that Service Bus endpoint, it’s counted as a second connection. One very important point falls out of this that may affect your architecture: you will want to minimize concurrent connections to the Service Bus in order to keep the subscription costs down. It may be more likely that you would want to use the Service Bus in the middle tier more like a VPN to on-premises services rather than allowing unlimited clients to connect through the Service Bus to your on-premises service. To reiterate, the key value proposition of the Service Bus is &lt;a href="http://en.wikipedia.org/wiki/Service-orientation"&gt;&lt;i&gt;Service Orientation&lt;/i&gt;&lt;/a&gt;; it makes it possible to expose application Services using interoperable protocols with value-added virtualization, discoverability, and security.&lt;/p&gt;  &lt;h3&gt;Using Windows Azure Connect&lt;/h3&gt;  &lt;p&gt;Recently announced at PDC 10, and expected for release by the end of 2010, is an alternative means for connecting your cloud services to your on-premises services. &lt;a href="http://www.microsoft.com/windowsazure/virtualnetwork/default.aspx"&gt;Windows Azure Connect&lt;/a&gt; effectively offers IP-level, secure, VPN-like connections from your Windows Azure hosted roles to your on-premises services. This service is not available yet and pricing details have not been released. From the information available to date, you can conclude that Windows Azure Connect would be used for connecting middle-tier services, rather than public clients, to your on-premises solutions. &lt;b&gt;While the Service Bus is focused on connectivity &lt;/b&gt;&lt;b&gt;for on-premise Services exposed as Azure endpoints without having to deal with firewall and NAT setup,&lt;/b&gt;&lt;b&gt; Windows Azure Connect provides broad connectivity between your Web/Worker roles and on-premises systems like SQL Server, Active Directory or LOB applications.&lt;/b&gt;&lt;/p&gt;  &lt;h4&gt;Securing the solution&lt;/h4&gt;  &lt;p&gt;Given the distributed nature of the &lt;i&gt;hybrid&lt;/i&gt; (on-premises and cloud) solution, your approach to security should match it - this means your architecture should leverage Federated Identity. This essentially means that you are outsourcing authentication and possibly authorization. If you want to flow your authenticated on-premises identities, such as domain credentials, into Azure hosted web sites or services, you will need a local identity (akin to presenting a claim issued by a local security token service) providing a security &lt;a href="http://msdn.microsoft.com/en-us/library/ee748489.aspx"&gt;Identity Provider Security&lt;/a&gt; Token Service (IP-STS) such as Active Directory Federation Services 2.0 (ADFS 2.0). Your services, whether on-premises or in the cloud, can then be configured to trust credentials, in the form of claims, issued by the IP-STS. Think of the IP-STS as simply the component that can tell if a username and password credentials are valid. In this approach, clients authenticate against the IP-STS; for example, by sending their Windows credentials to ADFS, and if valid, they receive claims they can subsequently present to your websites or services for access. Your websites or services only have to evaluate these claims when executing authorization logic - &lt;a href="http://msdn.microsoft.com/en-us/library/ee748484.aspx"&gt;Windows Identity Foundation&lt;/a&gt; (WIF) provides these facilities. &lt;/p&gt;  &lt;p&gt;For additional information, review this session - &lt;a href="http://europe.msteched.com/Topic/List?keyword=SIA305"&gt;SIA305 Windows Identity Foundation and Windows Azure for Developers&lt;/a&gt;. In this session you can learn how Windows Identity Foundation can be used to secure your Web Roles hosted in Windows Azure, how you can take advantage of existing on-premises identities, and how to make the most of the features such as certificate management and staged environments. learn about how Windows Identity Foundation can be used to secure your Web Roles hosted in Windows Azure, how you can take advantage of existing on-premises identities, and how to make the best of features in our cloud offering, such as certificate management and staged environments learn about how Windows Identity Foundation can be used to secure your Web Roles hosted in Windows Azure, how you can take advantage of existing on-premises identities, and how to make the best of features in our cloud offering, such as certificate management and staged environments learn about how Windows Identity Foundation can be used to secure your Web Roles hosted in Windows Azure, how you can take advantage of existing on-premises identities, and how to make the best of features in our cloud offering, such as certificate management and staged environments&lt;/p&gt;  &lt;p&gt;In the next release (version 2) of AppFabric Azure Access Control Service, a similar approach can be taken by using the Access Control Service (ACS v2) to act as your &lt;a href="http://msdn.microsoft.com/en-us/library/ee748489.aspx"&gt;IP-STS&lt;/a&gt; and thereby replacing ADFS. With ACS, you can define service identities that are essentially logins secured by either a username and password, or a certificate. The client calls out to ACS first to authenticate, and the client thereafter presents the claims received by ACS in the call to your service or website.&lt;/p&gt;  &lt;p&gt;Finally, more advanced scenarios can be put into place that uses ACS as your Relaying-Party Security Token Service (RP-STS) as the authority for all your apps, both on-premises and in the cloud. ACS is then configured to trust identities issued from other identity providers and convert them to the claims expected by your applications. For example, you can take this approach to enable clients to authenticate using Windows Live ID, Google, and Yahoo, while still working with the same set of claims you built prior to supporting those services. &lt;/p&gt;  &lt;p&gt;&lt;i&gt;Port Bridge&lt;/i&gt;, a point-to-point tunneling scenario, is perfect when the application is not exposed as a WCF service or doesn’t speak HTTP. Port bridge is perfect for protocols such as SMTP, SNMP, POP, IMAP, RDP, TDS and SSH. You can read more about this &lt;a href="http://blogs.msdn.com/b/clemensv/archive/2009/11/18/port-bridge.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;h2&gt;Optimizing Bandwidth – Data transfer Costs&lt;/h2&gt;  &lt;p&gt;One huge issue to reconcile in &lt;i&gt;hybrid &lt;/i&gt;solutions is the bandwidth – this is unique to &lt;i&gt;hybrid. &lt;/i&gt;&lt;/p&gt;  &lt;h3&gt;Keeping Data Transfers In Your Datacenter&lt;/h3&gt;  &lt;p&gt;The amount of data transferred in and out of a datacenter is billable, so an approach to optimizing your bandwidth cost is to keep as much traffic from leaving the datacenter as possible. This means architecting designs that transfer most data across the Azure “fabric” within affinity groups, and minimizing traffic between disparate data centers and to external sites. An affinity group ensures that your cloud services and storage are hosted together on the Windows Azure infrastructure. Windows Azure roles, Windows Azure storage, and SQL Azure services can be configured at creation time to live within a specific datacenter. By ensuring the Azure hosted components within your &lt;i&gt;hybrid&lt;/i&gt; solution that communicate with each other live in the same datacenter, you effectively eliminate the data transfer costs.&amp;#160; &lt;/p&gt;  &lt;h3&gt;Caching Data, On-Premises And In The Cloud&lt;/h3&gt;  &lt;p&gt;The second approach to optimizing bandwidth costs is to use &lt;i&gt;caching&lt;/i&gt;. This means leveraging &lt;b&gt;Windows Server AppFabric Cache&lt;/b&gt;, an on-premises technology, to minimize calls to SQL Azure or Azure Storage. Similarly, it also means utilizing the &lt;b&gt;Azure AppFabric Cache&lt;/b&gt; from Azure roles to minimize calls to SQL Azure, Azure Storage, or to on-premises services via Service Bus.&lt;/p&gt;  &lt;h3&gt;Optimizing Resources&lt;/h3&gt;  &lt;p&gt;One of the most significant cost-optimization features of Windows Azure roles is their support for dynamic scaling, up and down. This means adding more instances as your load increases and removing them as the load decreases. Supporting load-based dynamic scaling can be accomplished using the &lt;a href="http://msdn.microsoft.com/en-us/library/ee460799.aspx"&gt;Windows Azure management API&lt;/a&gt; and SQL Azure storage. While there is no out-of-the box support for this, there is a fair amount of guidance on how to implement this within your solutions (see the Additional References section for one such example). The typical approach is to configure your Azure Web and Worker roles to log health metrics (e.g., CPU load, memory usage, etc.) to a table in SQL Azure. You then have another Worker role that is responsible for periodically polling this table and when certain thresholds are reached or exceeded, it would increase or decrease the instance count for the monitored service using the Windows Azure management APIs.&amp;#160; &lt;/p&gt;  &lt;h2&gt;Monitoring &amp;amp; Diagnostics &lt;/h2&gt;  &lt;p&gt;For on-premises services, you can use &lt;b&gt;Windows Server AppFabric Monitoring&lt;/b&gt; which logs tracking events into your on-premises instance of SQL Server, and this data can be viewed both through IIS Manager and by querying the monitoring database. For Azure roles in production you can leverage &lt;a href="http://msdn.microsoft.com/en-us/library/ee758705.aspx"&gt;Windows Azure Diagnostics&lt;/a&gt;, wherein your instances periodically load batches to Azure storage. For SQL Azure you can examine SQL Azure query performance by querying the related &lt;a href="http://msdn.microsoft.com/en-us/library/ff394114.aspx"&gt;Dynamic Management Views&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;IntelliTrace is very useful for debugging solutions. With IntelliTrace debugging, you can log extensive debugging information for a Role instance while it is running in Windows Azure. If you need to track down a problem, you can then use the IntelliTrace logs to step through your code from within Visual Studio as though it were running in Windows Azure. In effect, IntelliTrace records key code execution and environment data while your service is running, and allows you to replay the recorded data from within Visual Studio. For more information on IntelliTrace, see &lt;a href="http://msdn.microsoft.com/en-us/library/dd264915.aspx"&gt;Debugging with IntelliTrace&lt;/a&gt;.&lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Summary&lt;/h1&gt;  &lt;p&gt;Based off the discussions above, let’s consolidate our findings into this easy to read table. &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Table 3: In Summary&lt;/em&gt;     &lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="91"&gt;           &lt;p&gt;&lt;b&gt;Typical&lt;/b&gt;&lt;/p&gt;            &lt;p&gt;&lt;b&gt;Scenario&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="76"&gt;           &lt;p&gt;&lt;b&gt;Architectural Pattern&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="108"&gt;           &lt;p&gt;&lt;b&gt;Application Host&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;&lt;b&gt;Data Store(s)&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;&lt;b&gt;Access Control&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="136"&gt;           &lt;p&gt;&lt;b&gt;Management&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="91"&gt;           &lt;p&gt;&lt;b&gt;EAI and Process Control&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="76"&gt;           &lt;p&gt;On Premise&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="108"&gt;           &lt;p&gt;IIS, Windows Server, BizTalk Server&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;AppFabric Cache, SQL Server&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;Active Directory, SQL Login&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="136"&gt;           &lt;p&gt;SQL Server Management Studio, &lt;/p&gt;            &lt;p&gt;IIS – Manager&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="91"&gt;           &lt;p&gt;&lt;b&gt;Web content delivery &lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="76"&gt;           &lt;p&gt;Cloud&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="108"&gt;           &lt;p&gt;Windows Azure – Web or Worker Roles&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;SQL Azure,&lt;/p&gt;            &lt;p&gt;Azure Storage, &lt;/p&gt;            &lt;p&gt;AppFabric Cache&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;Account name/key pair (limited IP Address access),&lt;/p&gt;            &lt;p&gt;SQL Login, &lt;/p&gt;            &lt;p&gt;Access Control Services&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="136"&gt;           &lt;p&gt;SQL Server Management Studio, &lt;/p&gt;            &lt;p&gt;Database Manager, &lt;/p&gt;            &lt;p&gt;Windows Azure Portal&lt;/p&gt;            &lt;p&gt;Management API.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="91"&gt;           &lt;p&gt;&lt;b&gt;Multi-location devices/ Appliance Management&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="76"&gt;           &lt;p&gt;&lt;i&gt;Hybrid&lt;/i&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="108"&gt;           &lt;p&gt;IIS, Windows Server, BizTalk Server, &lt;/p&gt;            &lt;p&gt;Windows Azure – Web or Worker Roles&lt;/p&gt;            &lt;p&gt;Service Bus&lt;/p&gt;            &lt;p&gt;Connect&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;AppFabric Cache, SQL Server, SQL Azure,&lt;/p&gt;            &lt;p&gt;Azure Storage, &lt;/p&gt;            &lt;p&gt;AppFabric Cache&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="113"&gt;           &lt;p&gt;ADFS 2.0,&lt;/p&gt;            &lt;p&gt;Access Control Services&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="136"&gt;           &lt;p&gt;SQL Server Management Studio, &lt;/p&gt;            &lt;p&gt;Database Manager, &lt;/p&gt;            &lt;p&gt;Windows Azure Portal, &lt;/p&gt;            &lt;p&gt;IIS - Manager&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;It’s clear that the &lt;i&gt;Hybrid&lt;/i&gt; Cloud Architectural pattern is ideally suited for connecting on-premises based appliances and applications with its cloud counterparts. This &lt;i&gt;hybrid&lt;/i&gt; pattern is ideal since it leverages the best of both: traditional on-premises applications and new distributed/multi-tenant cloud applications. &lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Let’s Make Plans To Build This Out Now!&lt;/h1&gt;  &lt;p&gt;We have presented a survey of available technologies to build out the &lt;i&gt;hybrid &lt;/i&gt;applications; other recent announcements at &lt;a href="http://www.microsoft.com/windowsazure/pdcannouncements/"&gt;PDC 10&lt;/a&gt; are worth considering before you move forward. &lt;/p&gt;  &lt;p&gt;First, you should consider the &lt;i&gt;Composition Model&lt;/i&gt; within the &lt;a href="http://www.microsoft.com/en-us/appfabric/azure/composite-apps.aspx"&gt;Windows Azure Composite Applications Environment&lt;/a&gt;. The Composition Model ties together your entire Azure hosted services (roles, storage, SQL Azure, etc.) as one composite application enabling you to see the end to end picture in a single designer in Visual Studio. The Composition Model is a set of .NET Framework extensions and builds on the familiar Azure Service Model concepts and adds new capabilities for describing the application infrastructure, its components, and relationships among the components, in order to treat the composite application as a single logical identity.&lt;/p&gt;  &lt;p&gt;Second, if you were making calls back to an on-premises instance of Windows Server AppFabric&lt;a href="http://blogs.msdn.com/b/murrayg/archive/2009/06/23/windows-azure-s-net-workflow-service-to-support-net-4-0-workflows.aspx"&gt;, Windows Workflow is fully supported on Azure&lt;/a&gt; as part of the composition model, and so you may choose to move the relevant Workflows directly into the cloud. This is huge, very huge since it enables &lt;i&gt;develop once and deploy as needed&lt;/i&gt;!&lt;/p&gt;  &lt;p&gt;Third, there is a new role in town - the Windows Azure Compute &lt;a href="http://www.microsoft.com/windowsazure/compute/default.aspx"&gt;VM Role&lt;/a&gt;. This enables us to host 3&lt;sup&gt;rd&lt;/sup&gt; party and archaic Line-of-business applications—and fully participate (wow - &lt;i&gt;without a major code do-over!&lt;/i&gt;) in the &lt;i&gt;hybrid cloud solution. &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;And last but not least, Windows Azure is also providing the Remote Desktop functionality, which enables you to connect to a running instance of your application or service to monitor activity and troubleshoot common problems. The &lt;a href="http://www.microsoft.com/windowsazure/compute/default.aspx"&gt;Remote Desktop Protocol Access&lt;/a&gt; while super critical to the VM instance is also available to Web and Worker roles too. This in turn enables another related new feature, which is the availability of the full IIS instead of just the core that was available to web roles.&amp;#160; &lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Additional References&lt;/h1&gt;  &lt;p&gt;While web links for additional/background information are embedded into the text; the following additional references are provided as resources to move forward on your journey. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/wazplatformtrainingcourse.aspx"&gt;Windows Azure, SQL Azure &amp;amp; Azure AppFabric&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://www.sqlazurelabs.com/"&gt;SQL Azure Labs&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/windowsazure/netservices.aspx"&gt;Windows Azure AppFabric Service Bus&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://acs.codeplex.com/documentation"&gt;Windows Azure AppFabric Access Control Service&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.msteched.com/2010/Europe/SIA305"&gt;Windows Identity Foundation and Windows Azure for Developers&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bit.ly/cSXOaC"&gt;Windows Azure Connect talk at PDC 10&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/gg232759.aspx"&gt;MSDN Magazine Article on Health Based Scaling&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bit.ly/dkAzfB"&gt;Azure AppFabric Cache Talk at PDC 10&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bit.ly/8ZnXbT"&gt;Identity &amp;amp; Access Control in the Cloud at PDC 10&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Stay Tuned!&lt;/h1&gt;  &lt;p&gt;This is the beginning; our team is currently working on the next blog that builds on this topic. The blog will take a scenario driven approach in building a Hybrid Windows Azure Application. &lt;/p&gt;  &lt;h3&gt;&amp;#160;&lt;/h3&gt;  &lt;h2&gt;Acknowledgements&lt;/h2&gt;  &lt;p&gt;Significant contributions from &lt;a href="http://blogs.msdn.com/members/leprino/"&gt;Paolo Salvatori&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/members/valerym/"&gt;Valery Mizonov&lt;/a&gt;, Keith Bauer, &lt;a href="http://blogs.msdn.com/members/ramaramani/"&gt;Rama Ramani&lt;/a&gt;, Zoiner Tejada and &lt;a href="http://social.msdn.microsoft.com/profile/sidney%20h/"&gt;Sidney Higa&lt;/a&gt; are acknowledged. &lt;/p&gt;  &lt;p&gt;&lt;i&gt;&lt;font size="3"&gt;Namaste!&lt;/font&gt;&lt;/i&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10098143" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Azure+Service+Bus/">Azure Service Bus</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/Reference/">Reference</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>BizTalk Server–distinguished field</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/30/biztalk-server-distinguished-field.aspx</link><pubDate>Tue, 30 Nov 2010 01:16:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10098060</guid><dc:creator>Quoc Bui</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10098060</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10098060</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/30/biztalk-server-distinguished-field.aspx#comments</comments><description>&lt;p&gt;The distinguished field is used to expose the value of a node of a message instance to BizTalk Server system. However, if there is a record that has a parent node that has multiple instances, then that record won’t be able to be highlighted as distinguished. An error message of “&lt;font color="#ff0000"&gt;The node can occur potentially multiple times in the instance. Only nodes which are guaranteed to be unique can be promoted&lt;/font&gt;.“ will appear.&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/5811.image_5F00_4E6F9E89.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0143.image_5F00_thumb_5F00_62C53E47.png" width="547" height="438" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This constraint was purposely designed to remove any ambiguity in accessing the data. However, despite that, should the developer still desire to use the node, then the record’s XPath query can still be used. The article &lt;a title="Using XPaths in Message Assignments" href="http://msdn.microsoft.com/en-us/library/aa561906.aspx" target="_blank"&gt;Using XPaths in Message Assignments&lt;/a&gt; describes how XPath queries can be leveraged in BizTalk Server.&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:0767317B-992E-4b12-91E0-4F059A8CECA8:dde41801-e950-4954-bf0d-3afcdd183925" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/BizTalk+Server" rel="tag"&gt;BizTalk Server&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Distinguished" rel="tag"&gt;Distinguished&lt;/a&gt;,&lt;a href="http://technorati.com/tags/fields" rel="tag"&gt;fields&lt;/a&gt;,&lt;a href="http://technorati.com/tags/XPath" rel="tag"&gt;XPath&lt;/a&gt;,&lt;a href="http://technorati.com/tags/queries" rel="tag"&gt;queries&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10098060" 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/Reference/">Reference</category></item><item><title>Windows Azure AppFabric Caching Service - soup to nuts primer</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/29/azure-appfabric-caching-service-soup-to-nuts-primer.aspx</link><pubDate>Mon, 29 Nov 2010 19:59:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10097956</guid><dc:creator>Rama Ramani</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/rsscomments.aspx?WeblogPostID=10097956</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10097956</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/29/azure-appfabric-caching-service-soup-to-nuts-primer.aspx#comments</comments><description>&lt;h1&gt;Introduction
&lt;/h1&gt;&lt;p&gt;One of the important reasons to move an application to the cloud is scalability (outside of other benefits that the cloud provides). When the application is deployed to the cloud, it is critical to maintain performance - the system needs to handle the increase in load and importantly maintain low latency response times. This is currently needed for most applications, be it a website selling books or a large social networking website or a complex map reduce algorithm. Distributed Caching as a technology enables applications to scale elastically while maintaining the application performance. Previously, Windows Server AppFabric enabled you to use distributed caching on-premises. Now, distributed caching is available on the cloud for Azure applications!
&lt;/p&gt;&lt;p&gt;Here are some scenarios to leverage the Windows Azure AppFabric Caching Service:
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;ASP.NET application running as a web role needing a scalable session repository 
&lt;/li&gt;&lt;li&gt;Windows Azure hosted application frequently accessing reference data
&lt;/li&gt;&lt;li&gt;&lt;div&gt;Windows Azure hosted application aggregating objects from various services and data stores 
&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href="http://www.microsoft.com/en-us/appfabric/azure/middleware-services.aspx"&gt;&lt;em&gt;Windows Azure AppFabric Caching&lt;/em&gt;&lt;/a&gt; is Microsoft's distributed caching &lt;strong&gt;P&lt;/strong&gt;latform &lt;strong&gt;A&lt;/strong&gt;s &lt;strong&gt;A&lt;/strong&gt;
		&lt;strong&gt;S&lt;/strong&gt;ervice that can be easily configured and leveraged by your applications. It provides elastic scale, agile apps development, familiar programming model and best of all, managed &amp;amp; maintained by Microsoft. 
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7534.112910_5F00_1959_5F00_WindowsAzur1.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;At this time, this service is in labs release and can be used for development &amp;amp; test purposes only. 
&lt;/p&gt;&lt;h1&gt;Configuring the Cache endpoint
&lt;/h1&gt;&lt;ol&gt;&lt;li&gt;Go to https://portal.appfabriclabs.com/ and login using your Live ID
&lt;/li&gt;&lt;li&gt;&lt;div&gt;Create a Project and then add a unique Service Namespace to it, for instance 'TestAzureCache1'. 
&lt;/div&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/7446.112910_5F00_1959_5F00_WindowsAzur2.png" alt=""/&gt;
			&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;When you click on the &lt;em&gt;Cache&lt;/em&gt; endpoint, you should see the service URL and the authentication access token as follows:
&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1667.112910_5F00_1959_5F00_WindowsAzur3.png" alt=""/&gt;
			&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;At this point, you are done setting up the cache endpoint. Comparing this to installing and configuring the cache cluster on-premises shows the agility that cloud platforms truly provide.
&lt;/p&gt;&lt;h1&gt;Developing an application
&lt;/h1&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=D89640FC-C552-446E-AEAD-B1E0D940F31B" target="_blank"&gt;Download the Windows Azure AppFabric SDK&lt;/a&gt; to get started.
&lt;/li&gt;&lt;li&gt;&lt;div&gt;Copy the app.config or web.config from the portal shown above and use it from your client application
&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6545.112910_5F00_1959_5F00_WindowsAzur4.png" alt=""/&gt;
			&lt;/p&gt;&lt;/li&gt;&lt;li&gt;In your solution, add references to Microsoft.ApplicationServer.Caching.Client and Microsoft.ApplicationServer.Caching.Core from C:\Program Files\Windows Azure AppFabric SDK\V2.0\Assemblies\Cache 
&lt;/li&gt;&lt;li&gt;&lt;div&gt;Add the namespace to the beginning of your source code and develop the application in a similar manner to developing &lt;a href="http://msdn.microsoft.com/en-us/library/ee790941.aspx"&gt;on-premises application&lt;/a&gt;
			&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Consolas; font-size:9pt"&gt;&lt;span style="color:blue"&gt;using&lt;/span&gt; Microsoft.ApplicationServer.Caching;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;* At this point, Azure AppFabric caching service does not have all the features that Windows Server AppFabric Cache supports. . For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/gg278356.aspx"&gt;http://msdn.microsoft.com/en-us/library/gg278356.aspx&lt;/a&gt;.
&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;div&gt;If you are developing the application via code instead of config, here are set of code for accessing the caching service. Only the statements highlighted need to be modified as per your configured endpoint.
&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;span style="color:blue"&gt;&lt;span style="font-family:Consolas; font-size:9pt"&gt;    &lt;/span&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt; private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;void&lt;/span&gt; PrepareClient()
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;        {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;        &lt;span style="color:green"&gt;// Insert the Service URL from the labs portal&lt;/span&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:blue; background-color:yellow"&gt;string&lt;/span&gt;&lt;span style="background-color:yellow"&gt; hostName = &lt;span style="color:#a31515"&gt;"TestAzureCache1.cache.appfabriclabs.com"&lt;/span&gt;;&lt;/span&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;int&lt;/span&gt; cachePort = 22233;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;DataCacheServerEndpoint&lt;/span&gt;&amp;gt; server = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;DataCacheServerEndpoint&lt;/span&gt;&amp;gt;();
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            server.Add(&lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheServerEndpoint&lt;/span&gt;(hostName, cachePort));
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheFactoryConfiguration&lt;/span&gt; config = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheFactoryConfiguration&lt;/span&gt;();
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:green"&gt;//Insert the Authentication Token from the labs portal&lt;/span&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:blue; background-color:yellow"&gt;string&lt;/span&gt;&lt;span style="background-color:yellow"&gt; authenticationToken = &amp;lt;&lt;span style="color:#a31515"&gt;To Be Filled Out&amp;gt;&lt;/span&gt;;&lt;/span&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.SecurityProperties = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheSecurity&lt;/span&gt;(authenticationToken);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.Servers = server;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.IsRouting = &lt;span style="color:blue"&gt;false&lt;/span&gt;;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.RequestTimeout = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;(0, 0, 45);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.ChannelOpenTimeout = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;(0, 0, 45);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.MaxConnectionsToServer = 5;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.TransportProperties = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheTransportProperties&lt;/span&gt;() { MaxBufferSize = 100000 };
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            config.LocalCacheProperties = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheLocalCacheProperties&lt;/span&gt;(10000, &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;(0, 5, 0), &lt;span style="color:#2b91af"&gt;DataCacheLocalCacheInvalidationPolicy&lt;/span&gt;.TimeoutBased);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheFactory&lt;/span&gt; myCacheFactory = &lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;DataCacheFactory&lt;/span&gt;(config);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;            myDefaultCache = myCacheFactory.GetCache(&lt;span style="color:#a31515"&gt;"default"&lt;/span&gt;);
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Lucida Console; font-size:10pt"&gt;        }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;h1&gt;Performance data
&lt;/h1&gt;&lt;p&gt;By now, you must be thinking if this is indeed this easy, what is the catch? :) :) There is none. Here are some performance numbers that I ran, hopefully this makes you feel at ease. 
&lt;/p&gt;&lt;p&gt;This is an ASP.NET application running as a web role in Windows Azure accessing the cache service. The &lt;em&gt;Object count&lt;/em&gt; parameter is used to instantiate an object which has an array of int[] and string[]. For example, when &lt;em&gt;Object count&lt;/em&gt; is set to 100 the application will instantiate int[100] and string[100] with each array item is initialized to a string ~6 bytes. So approximately, the parameter &lt;em&gt;'Object count'&lt;/em&gt; * 10 is the pre-serialized object size. When storing the object in the caching service, the KEY is generated using RAND and then depending on the &lt;em&gt;Operations &lt;/em&gt;dropdown, the workload is run for a set of iterations based on the &lt;em&gt;'Iterations'&lt;/em&gt; parameter. Finally, the average latency is computed. The web role is running in South Central US data center in the same DC where the caching service is also deployed in order to avoid any external network latencies. For all these tests, the local cache feature is disabled.
&lt;/p&gt;&lt;div&gt;&lt;table style="border-collapse:collapse" border="0"&gt;&lt;colgroup&gt;&lt;col style="width:83px"/&gt;&lt;col style="width:114px"/&gt;&lt;col style="width:120px"/&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;&lt;tr&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  solid 0.5pt; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;&lt;strong&gt;Operation&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;&lt;strong&gt;Object Size 
&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;(pre-serialized)&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;&lt;strong&gt;Avg Latency (ms)&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;PUT&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;~1KB&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;4.5 - 6.5&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;GET&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;~ 1 KB&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;4.8 - 5.1&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;PUT&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;~10 KB&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;7.4 - 8.9&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;GET&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;~10 KB&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;7.6 - 10.3&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;PUT&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;~100 KB&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;38.9 - 45.6&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;GET&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;~100 KB&lt;/p&gt;&lt;/td&gt;&lt;td style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt"&gt;&lt;p&gt;4.6 - 7.3&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5074.112910_5F00_1959_5F00_WindowsAzur5.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0184.112910_5F00_1959_5F00_WindowsAzur6.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3005.112910_5F00_1959_5F00_WindowsAzur7.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;Now that you have some cache in the cloud, get your apps going! 
&lt;/p&gt;&lt;p style="background: white"&gt;&lt;span style="color:#333333; font-family:Segoe UI; font-size:10pt"&gt;&lt;em&gt;Authored by: Rama Ramani &lt;br/&gt;Reviewed by: Christian Martinez, Jason Roth&lt;/em&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10097956" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Cache/">Cache</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Azure+AppFabric+Cache/">Azure AppFabric Cache</category></item><item><title>StreamInsight: Understanding dynamic query composition</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/22/streaminsight-understanding-dynamic-query-composition.aspx</link><pubDate>Mon, 22 Nov 2010 23:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10095174</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=10095174</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10095174</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/22/streaminsight-understanding-dynamic-query-composition.aspx#comments</comments><description>&lt;p&gt;Been tied up with &lt;a href="http://www.sqlpass.org/summit/na2010/"&gt;PASS&lt;/a&gt; for the past (pun intended) couple of weeks, so it’s time to get a bit caught up on writing.&amp;#160; One of the key technical features of StreamInsight is the ability for one query to consume the output of another, enabling the system to avoid having to process events twice, and opening up a new world of flexibility.&amp;#160; The feature that unlocks these capabilities is Dynamic Query Composition.&amp;#160; That being said, some of the nuances of how StreamInsight constructs queries and flows events is not always obvious.&amp;#160; As this has resulted in me making a few sub-optimal design choices in the past &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/4454.wlEmoticon_2D00_smile_5F00_187CAE4F.png" /&gt;, I figured I’d put together a little article demonstrating the subtle nuances involved when using (or not using) DQC.&lt;/p&gt;  &lt;p&gt;For more background on DQC, please refer to:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff518536.aspx"&gt;Composing Queries at Runtime&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Take the diagram below, illustrating a common query composition pattern.&amp;#160; Given a single input stream (represented by the &lt;em&gt;inputAdapter &lt;/em&gt;shape in the diagram), we would like to consume the stream of events from that adapter in both &lt;em&gt;queryOne &lt;/em&gt;and &lt;em&gt;queryTwo&lt;/em&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/7674.image_5F00_16CBE27B.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/1321.image_5F00_thumb_5F00_0DFBDA2F.png" width="656" height="181" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;At first glance, this query syntax would seem to fit the bill (note that I’m using the new IObservable support for the input adapter, but using the classic adapter syntax to create the queries bound to an output adapter, to explicitly show query creation):&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:c807a3a2-cbca-4e78-a8a7-5da3b1c55ad8" 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: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&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:#008000"&gt;// Convert the data source into a temporal stream&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; orderStream = ordersSimple.ToPointStream(cepApp, s =&amp;gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;PointEvent&lt;/span&gt;.CreateInsert(s.StartTime, s),&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;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// Create a query in two parts&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; queryOne = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; e &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; orderStream &lt;span style="color:#0000ff"&gt;where&lt;/span&gt; e.OrderID &amp;gt; 50 &lt;span style="color:#0000ff"&gt;select&lt;/span&gt; e;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; queryTwo = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; e &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; queryOne.TumblingWindow(&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromDays(1), &lt;span style="color:#2b91af"&gt;HoppingWindowOutputPolicy&lt;/span&gt;.ClipToWindowEnd)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    OrderCount = e.Count()&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:#008000"&gt;// Convert these templates into queries, bound to an output adapter&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; tracerConfig = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;TracerConfig&lt;/span&gt;()&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        DisplayCtiEvents = &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;        SingleLine = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        TracerKind = &lt;span style="color:#2b91af"&gt;TracerKind&lt;/span&gt;.Console&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; queryOneRun = queryOne.ToQuery(cepApp, &lt;span style="color:#a31515"&gt;&amp;quot;QueryOne&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;TracerFactory&lt;/span&gt;), tracerConfig, &lt;span style="color:#2b91af"&gt;EventShape&lt;/span&gt;.Point,&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;StreamEventOrder&lt;/span&gt;.FullyOrdered);&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; queryTwoRun = queryTwo.ToQuery(cepApp, &lt;span style="color:#a31515"&gt;&amp;quot;QueryTwo&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;TracerFactory&lt;/span&gt;), tracerConfig, &lt;span style="color:#2b91af"&gt;EventShape&lt;/span&gt;.Interval,&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;StreamEventOrder&lt;/span&gt;.FullyOrdered);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;However, this wouldn’t produce the desired result.&amp;#160; Instead, the StreamInsight engine will construct the query pattern seen in the diagram below – where &lt;em&gt;queryTwo&lt;/em&gt; composes the &lt;strong&gt;design &lt;/strong&gt;of &lt;em&gt;queryOne&lt;/em&gt;, but not the runtime stream (i.e. creates two adapter instances).&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/6433.image_5F00_590ED4F1.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/5543.image_5F00_thumb_5F00_5B6856EF.png" width="590" height="209" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This can be verified by using the debugger to check the input source of the query.&amp;#160; For details on how to use the debugger, see my blog post here.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open the Event Flow Debugger, and connect to your StreamInsight instance (walkthrough on using the Event Flow Debugger &lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/21/streaminsight-getting-started-with-using-the-event-flow-debugger-viewing-diagnostics-and-exposing-the-management-service.aspx"&gt;here&lt;/a&gt;). &lt;/li&gt;    &lt;li&gt;Navigate to your &lt;em&gt;queryTwo &lt;/em&gt;definition, and &lt;strong&gt;Show Query&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;As seen in the diagram below, if the input adapter is an actual input adapter (and not a published stream) you have two independent streams each with their own input adapter. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="802"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="400"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3718.image_5F00_198171A1.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/5556.image_5F00_thumb_5F00_0C3AE88E.png" width="537" height="473" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="400"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0576.image_5F00_2A38F682.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/8270.image_5F00_thumb_5F00_014DE179.png" width="296" height="583" /&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;In order to have the two queries compose at runtime, we need to:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Publish the results of the first query as a published stream with a strongly typed output (published schemas cannot have anonymous types) &lt;/li&gt;    &lt;li&gt;Consume the published stream as the input source of the second query. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Updating the query syntax to take advantage of DQC looks like:&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:333cda39-e023-48cd-bcc4-5a39db9e2f96" 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: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&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:#008000"&gt;// Create a simple data source (oData feed), using a non-anonymous&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// type&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; ordersSimple = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; o &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; northwind.Orders&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#0000ff"&gt;where&lt;/span&gt; o.OrderDate != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; o.ShippedDate != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#0000ff"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;NorthwindOrderResult&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    {&lt;/li&gt; &lt;li&gt;                        StartTime = (&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;)o.OrderDate,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        EndTime = (&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;)o.ShippedDate,&lt;/li&gt; &lt;li&gt;                        OrderID = o.OrderID,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                        ShipRegion = o.ShipRegion,&lt;/li&gt; &lt;li&gt;                        CompanyName = o.Customer.CompanyName&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    };&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// Convert the data source into a temporal stream&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; orderStream = ordersSimple.ToPointStream(cepApp, s =&amp;gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;PointEvent&lt;/span&gt;.CreateInsert(s.StartTime, 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;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;// Create a query &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; queryOne = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; e &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; orderStream &lt;span style="color:#0000ff"&gt;where&lt;/span&gt; e.OrderID &amp;gt; 50 &lt;span style="color:#0000ff"&gt;select&lt;/span&gt; e;                     &lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; queryOneRun = queryOne.ToQuery(cepApp, &lt;span style="color:#a31515"&gt;&amp;quot;QueryOne&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;TracerFactory&lt;/span&gt;), tracerConfig, &lt;span style="color:#2b91af"&gt;EventShape&lt;/span&gt;.Point,&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;StreamEventOrder&lt;/span&gt;.FullyOrdered);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;// Convert the query&amp;#39;s output into a published stream (with a &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;// non-anonymous type)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; queryOneStream = queryOneRun.ToStream&amp;lt;&lt;span style="color:#2b91af"&gt;NorthwindOrderResult&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;// Bind the second query to the published stream&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; queryTwo = &lt;span style="color:#0000ff"&gt;from&lt;/span&gt; e &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; queryOneStream.TumblingWindow(&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromDays(1), &lt;span style="color:#2b91af"&gt;HoppingWindowOutputPolicy&lt;/span&gt;.ClipToWindowEnd)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    OrderCount = e.Count()&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:#008000"&gt;// Run the second query&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; queryTwoRun = queryTwo.ToQuery(cepApp, &lt;span style="color:#a31515"&gt;&amp;quot;QueryTwo&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;TracerFactory&lt;/span&gt;), tracerConfig, &lt;span style="color:#2b91af"&gt;EventShape&lt;/span&gt;.Interval,&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#2b91af"&gt;StreamEventOrder&lt;/span&gt;.FullyOrdered);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now that we’ve updated the query structures to use DQC, let’s take another look at the query structure in the debugger.&amp;#160; Note that the input source for the second query is now a &lt;strong&gt;published stream &lt;/strong&gt;(as it is now bound to a URI source, not a direct input adapter).&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="800"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="400"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/5852.image_5F00_2D1E3568.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/7610.image_5F00_thumb_5F00_1BEA57C5.png" width="554" height="559" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="400"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8524.image_5F00_67D5B871.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/2337.image_5F00_thumb_5F00_05D3C666.png" width="363" height="564" /&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;There we go – we can now feed the run-time results of one query into another query using &lt;em&gt;Dynamic Query Composition&lt;/em&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10095174" 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/Dynamic+Query+Composition/">Dynamic Query Composition</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 1</title><link>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</link><pubDate>Mon, 22 Nov 2010 23:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10095507</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=10095507</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10095507</wfw:comment><comments>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#comments</comments><description>&lt;h1&gt;Introduction&lt;/h1&gt;  &lt;p align="justify"&gt;Some time ago, I was asked by a customer whether or not BizTalk WCF Adapters support the &lt;a href="http://msdn.microsoft.com/en-us/library/aa751829.aspx"&gt;Duplex Message Exchange Pattern.&lt;/a&gt; The latter 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. This form of bi-directional communication is useful for services that must communicate directly to the client or for providing an asynchronous experience to either side of a message exchange, including event-like behavior. The BizTalk WCF Adapters support this message exchange pattern, but unfortunately this feature is undocumented. Therefore, I decided to create a full demo where a client .NET application exchange messages with an Orchestration via a two-way Request-Response WCF Receive Location that supports callbacks and duplex communication. Subsequently, I decided to extend this demo and introduce a &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx"&gt;WCF Workflow Service&lt;/a&gt; between the WinForm client application and the underlying Orchestration to implement a more complex scenario The final objective was to investigate how exploiting the &lt;a href="http://msdn.microsoft.com/en-us/library/dd456784.aspx"&gt;Correlation&lt;/a&gt; mechanisms provided by WF 4.0 to get a workflow running within IIS/AppFabric to exchange messages with a downstream orchestration in an asynchronous mode.&lt;/p&gt;  &lt;p align="justify"&gt;This article will be composed of 3 parts:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Part 1: 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;.&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/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;Part 2&lt;/a&gt;: 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;.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&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;Part 3&lt;/a&gt;: 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;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h1 align="justify"&gt;Why Duplex Message Exchange Pattern?&lt;/h1&gt;  &lt;p align="justify"&gt;The Duplex Message Exchange Pattern is fully supported by WCF and is extensively documented on MSDN. As I already mentioned in the introduction, the Duplex pattern allows two applications to act both as service endpoints and send messages to each other independently in an asynchronous way. There are many reasons for using the Duplex Message Exchange Pattern when communicating with a BizTalk solution: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;If an orchestration invoked by the consumer application takes seconds to minutes to complete. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;If you are invoking an orchestration within an ASP.NET page, use asynchronous pages.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;If you are invoking an orchestration from a single threaded application, such as a Windows Forms or Windows Presentation Foundation (WPF) application. When using the event-based asynchronous calling model, the result event is raised on the UI thread, adding responsiveness to the application without requiring you to handle multiple threads yourself.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;   &lt;br /&gt;In general, if you have a choice between a synchronous and asynchronous call, you should choose the latter approach. In fact, a synchronous call typically blocks the client thread till the operation completes, whereas an asynchronous call is non-blocking and only initiates the operation. This way the consumer application can continue its execution without waiting for the call to complete and get notified by the service when the result of its request is ready.&lt;/p&gt;  &lt;p align="justify"&gt;For more information on how implementing the Duplex Message Exchange Pattern with WCF, you can read the following articles:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;&amp;quot;&lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms734701.aspx"&gt;Synchronous and Asynchronous Operations&lt;/a&gt;&lt;/em&gt;&amp;quot; topic on MSDN.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&amp;quot;&lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms733070.aspx"&gt;Designing Service Contracts&lt;/a&gt;&lt;/em&gt;&amp;quot; topic on MSDN.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;“&lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms731184.aspx"&gt;How to: Create a Duplex Contract&lt;/a&gt;&lt;/em&gt;” topic on MSDN.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;“&lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms731064.aspx"&gt;Duplex Services&lt;/a&gt;&lt;/em&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/aa751829.aspx"&gt;&lt;em&gt;Choosing a Message Exchange Pattern&lt;/em&gt;&lt;/a&gt;” topic on MSDN.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h1 align="justify"&gt;Using a Duplex Channel to communicate with a BizTalk Application&lt;/h1&gt;  &lt;p align="justify"&gt;The following picture represents the architecture of the first use case. The idea behind the application is quite straightforward: a Windows Forms application submits a question to an orchestration called &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; 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; &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/1325.WCFNetTcpAdabterSyncMagic8BallOrchestration_5F00_5A91EFFB.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="WCFNetTcpAdabterSyncMagic8BallOrchestration" border="0" alt="WCFNetTcpAdabterSyncMagic8BallOrchestration" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1300.WCFNetTcpAdabterSyncMagic8BallOrchestration_5F00_thumb_5F00_0CB00243.jpg" width="880" height="187" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;&lt;span style="font-weight: bold"&gt;Message Flow&lt;/span&gt;&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 Two-Way WCF-NetTcp Receive Location. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;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;The response message is retrieved by the WCF-NetTcp Receive Location. &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 finally returned to the original caller. &lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;h1 align="justify"&gt;WCF Receive Locations&lt;/h1&gt;  &lt;p align="justify"&gt;In order to establish an asynchronous communication, the client application and service, in our case BizTalk Server, have to meet the following conditions:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div align="justify"&gt;They need to be online simultaneously.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;They need to use the same WCF binding.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;The selected binding must support sessions and duplex contracts. WCF provides a rich set of built-in bindings that support the Duplex MEP. For more information, you can read “&lt;a href="http://msdn.microsoft.com/en-us/library/ms730879.aspx"&gt;System-Provided Bindings&lt;/a&gt;” topic on MSDN. &lt;/li&gt;    &lt;li&gt;The client application needs to implement a Service Contract to submit the request message to BizTalk and expose a Callback Contract to receive the response message from BizTalk Server asynchronously. &lt;/li&gt; &lt;/ol&gt;  &lt;p align="justify"&gt;To satisfy the second and third conditions, I have created 3 different Two-Way Request-Response Receive Locations with the following characteristics:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;The 3 Receive Locations are children of the same Receive Port called &lt;strong&gt;DuplexMEP.Sync.ReceivePort&lt;/strong&gt;.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;They use the &lt;strong&gt;XmlReceive&lt;/strong&gt; pipeline to process the inbound message and the &lt;strong&gt;PassThruTrasmit&lt;/strong&gt; pipeline to process the outbound message.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The &lt;strong&gt;DuplexMEP.Sync.WCF-NetTcp.ReceiveLocation &lt;/strong&gt;uses the WCF-NetTcp Adapter and is hosted by the BizTalkServerReceiveHost64 in-process host.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The &lt;strong&gt;DuplexMEP.Sync.WCF-NetNamedPipe.ReceiveLocation&lt;/strong&gt; uses the WCF-NetNamedPipe Adapter and is hosted by the BizTalkServerReceiveHost64 in-process host.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The &lt;strong&gt;DuplexMEP.Sync.WCF-Custom.WsDualHttpBinding.ReceiveLocation&lt;/strong&gt; uses the WCF-CustomIsolated Adapter in conjunction with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding.aspx"&gt;WsDualHttpBinding&lt;/a&gt; and is hosted by the BizTalkServerIsolatedHost.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;The following picture shows the 3 Receive Locations inside the BizTalk Administration Console:&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/7840.SyncWCFReceiveLocations_5F00_175D33CB.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="SyncWCFReceiveLocations" border="0" alt="SyncWCFReceiveLocations" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4062.SyncWCFReceiveLocations_5F00_thumb_5F00_4A1D1472.jpg" width="880" height="154" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;table style="width: 99%" border="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/3580.Quotes_5F00_Icon_5F00_5FD6D702.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/6622.Quotes_5F00_Icon_5F00_thumb_5F00_2EF41F97.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note            &lt;br /&gt;&lt;/strong&gt;You should select the most appropriate WCF Adapter and binding based on your needs:           &lt;ul type="circle"&gt;           &lt;li&gt;             &lt;div align="justify"&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding.aspx"&gt;WsDualHttpBinding&lt;/a&gt; binding is designed for interoperability with advanced web services that need to support WS-* standards. It uses the HTTP protocol for the transport and the text message encoding. &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.nettcpbinding.aspx"&gt;NetTcpBinding&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx"&gt;NetNamedPipeBinding&lt;/a&gt;, on the other hand, are designed for efficient and performant communication with other WCF applications across machines or on the same machine respectively. They both use the binary message encoding that guarantees better performance than the text message encoding. &lt;/div&gt;           &lt;/li&gt;         &lt;/ul&gt;          &lt;p align="justify"&gt;Bindings have different characteristics in terms of response time and throughput, so the general advice to increase performance is using the NetTcpBinding and NetNamedPipeBinding whenever possible. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h1 align="justify"&gt;   &lt;br /&gt;Schemas&lt;/h1&gt;  &lt;p align="justify"&gt;The request messages sent by the &lt;strong&gt;Windows Forms Client Application&lt;/strong&gt; have the following format:&lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;Request Message&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;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Request&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep&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;Id&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;9aff8596-ec87-494d-801e-30f286d449a4&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Id&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;Question&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Will the world end in 2012?&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Question&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;Delay&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Delay&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;Request&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;The corresponding response messages returned by the &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; orchestration have the following format:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;Response Message&lt;/strong&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;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Response&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep&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;Id&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;9aff8596-ec87-494d-801e-30f286d449a4&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Id&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;Answer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Most likely&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Answer&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;Response&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;Both message types are defined by an XML Schema contained in the &lt;strong&gt;Schemas&lt;/strong&gt; project that you can find in the companion code for this article.&lt;/p&gt;

&lt;h1 align="justify"&gt;Orchestration&lt;/h1&gt;

&lt;p align="justify"&gt;The following picture shows the structure of the &lt;strong&gt;SyncMagic8Ball&lt;/strong&gt; orchestration. &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/7120.SyncMagic8BallOrchestration_5F00_4C19C7A1.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/7673.SyncMagic8BallOrchestration_5F00_thumb_5F00_2CC6FB01.jpg" width="600" height="762" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;As you can easily notice, the orchestration uses the Two-Way Request-Response Logical Port to receive the inbound request message and 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;, &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; 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;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; &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;, &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; XPathHelper.GetValue(RequestMessage, 0, &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; &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 align="justify"&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 align="center"&gt;&lt;a href="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;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="DebugView" border="0" alt="DebugView" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/2451.DebugView_5F00_thumb_5F00_019E98BC.jpg" width="795" height="336" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&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 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/6064.Quotes_5F00_Icon_5F00_thumb_5F00_620CC2FE.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&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;lu type="disc"&gt;&lt;/lu&gt;&lt;/p&gt;

        &lt;ul type="circle"&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;lu&gt;&lt;/lu&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&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.&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&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/2476.Quotes_5F00_Icon_5F00_0C9BC877.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/2476.Quotes_5F00_Icon_5F00_thumb_5F00_14CFEE0E.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note 
            &lt;br /&gt;&lt;/strong&gt;To extract the value of individual fields from the inbound document, I could have used &lt;strong&gt;&lt;a href="http://support.microsoft.com/kb/942250"&gt;Distinguished Fields&lt;/a&gt;&lt;/strong&gt; defined on the XML Schema for the request message. These are context properties whose name is defined by the XPath Expression used to retrieve data from an input XML document. If the XML Schema of the document is quite complex, the XPath Expression in question can be very long and therefore the corresponding Distinguished Field can occupy a significant amount of space in the message context. Therefore, I recommend to implement the following best practices in any BizTalk application: &lt;/p&gt;

        &lt;ul type="circle"&gt;
          &lt;li&gt;Eliminate unnecessary and unused &lt;strong&gt;Distinguished Fields&lt;/strong&gt;. &lt;/li&gt;

          &lt;li&gt;Use a different technique to access the value of individual elements and attributes within an Xml document. &lt;/li&gt;
        &lt;/ul&gt;

        &lt;p&gt;When the document in question is extremely small, you can also load the message into an &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx"&gt;XmlDocument&lt;/a&gt;&lt;/strong&gt; object and use the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/h0hw012b.aspx"&gt;SelectSingleNode&lt;/a&gt;&lt;/strong&gt; method to extract the information you need using an XPath Expression. However, the general advice is to minimize the usage of XmlDocument variables in orchestrations and in .NET code. Loading a message into an &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx"&gt;XmlDocument&lt;/a&gt;&lt;/strong&gt; variable has significant overhead, especially for large messages.&amp;#160; This overhead is in terms of memory usage and system resources required to build the in-memory structures.&amp;#160; The use of an &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx"&gt;XmlDocument&lt;/a&gt;&lt;/strong&gt; instance forces the message content to be entirely loaded into memory in order to build the object graph for the DOM.&amp;#160; The total amount of memory used by an instance of this class can be around 10 times the actual message size. For more information and evidence, see the following articles I wrote on this topic: &lt;/p&gt;

        &lt;ul type="circle"&gt;
          &lt;li&gt;”&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/06/23/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration.aspx"&gt;4 Different ways to process an XLANGMessage within an helper component invoked by an orchestration Part 1&lt;/a&gt;” on the AppFabric CAT blog. &lt;/li&gt;

          &lt;li&gt;”&lt;a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/06/23/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration-part-2.aspx"&gt;4 Different ways to process an XLANGMessage within an helper component invoked by an orchestration Part 2&lt;/a&gt;” on the AppFabric CAT blog. &lt;/li&gt;
        &lt;/ul&gt;

        &lt;p&gt;The request message in my demo is relatively small; nevertheless,&amp;#160; I decided to use an helper class that adopts a streaming approach to extract data from the &lt;strong&gt;XLANGMessage&lt;/strong&gt; passed in as argument:&lt;/p&gt;

        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; XPathHelper
{
    &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; MessageCannotBeNull = &lt;span class="str"&gt;&amp;quot;[XPathReader] The message cannot be null.&amp;quot;&lt;/span&gt;;
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
        
    &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Static Methods
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetValue(XLANGMessage message, &lt;span class="kwrd"&gt;int&lt;/span&gt; partIndex, &lt;span class="kwrd"&gt;string&lt;/span&gt; xpath)
    {
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (message == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ApplicationException(MessageCannotBeNull);
            }
            &lt;span class="kwrd"&gt;using&lt;/span&gt; (Stream stream = message[partIndex].RetrieveAs(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Stream)) &lt;span class="kwrd"&gt;as&lt;/span&gt; Stream)
            {
                XmlTextReader xmlTextReader = &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlTextReader(stream);
                XPathCollection xPathCollection = &lt;span class="kwrd"&gt;new&lt;/span&gt; XPathCollection();
                XPathReader xPathReader = &lt;span class="kwrd"&gt;new&lt;/span&gt; XPathReader(xmlTextReader, xPathCollection);
                xPathCollection.Add(xpath);
                &lt;span class="kwrd"&gt;while&lt;/span&gt; (xPathReader.Read())
                {
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (xPathReader.HasAttributes)
                    {
                        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; xPathReader.AttributeCount; i++)
                        {
                            xPathReader.MoveToAttribute(i);
                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (xPathReader.Match(xPathCollection[0]))
                            {
                                &lt;span class="kwrd"&gt;return&lt;/span&gt; xPathReader.GetAttribute(i);
                            }
                        }
                    }
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (xPathReader.Match(xPathCollection[0]))
                    {
                        &lt;span class="kwrd"&gt;return&lt;/span&gt; xPathReader.ReadString();
                    }
                }
            }
        }
        &lt;span class="kwrd"&gt;finally&lt;/span&gt;
        {
            message.Dispose();
        }
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;
    }
    &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;Set Response&lt;/strong&gt; Message Assignment shape invokes the &lt;strong&gt;SetResponse&lt;/strong&gt; static method exposed by the &lt;strong&gt;ResponseHelper&lt;/strong&gt; class to generate the response message:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;ResponseHelper 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;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ResponseHelper
{
    &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; MessageFormat = &lt;span class="str"&gt;&amp;quot;[ResponseManager] {0}&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; ResponseNamespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.appfabric.cat/10/samples/duplexmep&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; Response = &lt;span class="str"&gt;&amp;quot;Response&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; Id = &lt;span class="str"&gt;&amp;quot;Id&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; Answer = &lt;span class="str"&gt;&amp;quot;Answer&amp;quot;&lt;/span&gt;;
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

    &lt;span class="preproc"&gt;#region&lt;/span&gt; Static Constructor
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] answers = &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; Static Constructor
    &lt;span class="kwrd"&gt;static&lt;/span&gt; ResponseHelper()
    {
        answers = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[]{&lt;span class="str"&gt;&amp;quot;As I see it, yes&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;It is certain&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;It is decidedly so&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Most likely&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Outlook good&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Signs point to yes&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Without a doubt&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Yes&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Yes – definitely&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;You may rely on it&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Reply hazy, try again&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Ask again later&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Better not tell you now&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Cannot predict now&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Concentrate and ask again&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Don't count on it&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;My reply is no&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;My sources say no&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Outlook not so good&amp;quot;&lt;/span&gt;,
                                &lt;span class="str"&gt;&amp;quot;Very doubtful&amp;quot;&lt;/span&gt;};
    }
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

    &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Static Methods
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetResponse(XLANGMessage message, &lt;span class="kwrd"&gt;string&lt;/span&gt; id)
    {
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            VirtualStream stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; VirtualStream();
            &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlWriter writer = XmlWriter.Create(stream))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement(Response, ResponseNamespace);
                writer.WriteStartElement(Id, ResponseNamespace);
                writer.WriteString(id);
                writer.WriteEndElement();
                writer.WriteStartElement(Answer, ResponseNamespace);
                Random random = &lt;span class="kwrd"&gt;new&lt;/span&gt; Random(&lt;span class="kwrd"&gt;unchecked&lt;/span&gt;((&lt;span class="kwrd"&gt;int&lt;/span&gt;)DateTime.Now.Ticks));
                writer.WriteString(answers[random.Next(0, 20)]);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            stream.Seek(0, SeekOrigin.Begin);
            message[0].LoadFrom(stream);
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
            LogHelper.WriteLine(ex.Message);
        }
        &lt;span class="kwrd"&gt;finally&lt;/span&gt;
        {
            message.Dispose();
        }
    }
    &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;As you can see, the &lt;strong&gt;ResponseHelper&lt;/strong&gt; class uses a &lt;a href="http://technet.microsoft.com/en-us/library/microsoft.biztalk.streaming.virtualstream(BTS.70).aspx"&gt;VirtualStream&lt;/a&gt; object an &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx"&gt;XmlWriter&lt;/a&gt; class instance to initialize the content of the response message. Once again, the response message in this case is so small that I could have used an &lt;strong&gt;XmlDocument&lt;/strong&gt; object to load the content of the response message. However, my intention was to show you how to take advantage of the streaming approach to read and write the content of an &lt;strong&gt;XLANGMessage&lt;/strong&gt; object within an orchestration.&lt;/p&gt;

&lt;p align="justify"&gt;Let’s take a look at the code used by the &lt;strong&gt;Windows Forms Client Application&lt;/strong&gt; to send a request message and receive the corresponding response using a Callback contract.&lt;/p&gt;

&lt;h1 align="justify"&gt;Data and Message Contracts&lt;/h1&gt;

&lt;p align="justify"&gt;I started defining the Data and Message Contracts for the request and response messages. These 2 types of contracts have different roles in WCF:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;strong&gt;Data Contracts &lt;/strong&gt;provide a mechanism to map .NET CLR types that are defined in code and XML Schemas (XSD) defined by the W3C organization (&lt;a href="http://www.w3c.org"&gt;www.w3c.org&lt;/a&gt;). Data contracts are published in the service’s metadata, allowing clients to convert the neutral, technology-agnostic representation of the data types to their native representations.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Message Contracts &lt;/strong&gt;describe the structure of SOAP messages sent to and from a service and enable you to inspect and control most of the details in the SOAP header and body. Whereas data contracts enable interoperability through the XML Schema Definition (XSD) standard, message contracts enable you to interoperate with any system that communicates through SOAP. Using message contracts gives you complete control over the SOAP message sent to and from a service by providing access to the SOAP headers and bodies directly. This allows the use of simple or complex types to define the exact content of the SOAP parts. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more information on Data and Message Contracts, you can read the following articles:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&amp;quot;&lt;a href="http://msdn.microsoft.com/en-us/library/ms733127.aspx"&gt;Using Data Contracts&lt;/a&gt;&amp;quot; topic on MSDN. &lt;/li&gt;

  &lt;li&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ms730255.aspx"&gt;Using Message Contracts&lt;/a&gt;” topic on MSDN. &lt;/li&gt;

  &lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;In my solution, I created 2 separate projects called &lt;strong&gt;DataContracts&lt;/strong&gt; and &lt;strong&gt;MessageContracts&lt;/strong&gt; respectively. For your convenience, I included below the code of the 4 classes used to define the Data and Message Contract of the request and response messages.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;BizTalkRequest Class&lt;/strong&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;pre class="csharpcode"&gt;[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 align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BizTalkResponse 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;[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;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BizTalkRequestMessage 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;[MessageContract(IsWrapped=&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BizTalkRequestMessage
{
    &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
    &lt;span class="kwrd"&gt;private&lt;/span&gt; BizTalkRequest request;
    &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; BizTalkRequestMessage()
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.request = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; BizTalkRequestMessage(BizTalkRequest request)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.request = request;
    }
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

    &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
    [MessageBodyMember(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; BizTalkRequest Request
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.request;
        }
        set
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.request = &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;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BizTalkResponseMessage 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;[MessageContract(IsWrapped = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BizTalkResponseMessage
{
    &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
    &lt;span class="kwrd"&gt;private&lt;/span&gt; BizTalkResponse response;
    &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; BizTalkResponseMessage()
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.response = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; BizTalkResponseMessage(BizTalkResponse response)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.response = response;
    }
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

    &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
    [MessageBodyMember(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; BizTalkResponse Response
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.response;
        }
        set
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.response = &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;Indeed, I could have used just Data Contracts to model messages as Message Contracts add a degree of complexity. So why I decided to use Message Contracts? Well, the reason is quite straightforward. By assigning &lt;strong&gt;false&lt;/strong&gt; to the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.messagecontractattribute.iswrapped.aspx"&gt;IsWrapped&lt;/a&gt;&lt;/strong&gt; property exposed by the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms586728.aspx"&gt;MessageContractAttribute&lt;/a&gt;&lt;/strong&gt;, you specify that the message body won’t be contained in a wrapper element. Typically, the wrapper element of a request message is the name of the operation invoked and it’s defined in the WSDL. Setting the value of the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.messagecontractattribute.iswrapped.aspx"&gt;IsWrapped&lt;/a&gt;&lt;/strong&gt; property to &lt;strong&gt;false&lt;/strong&gt;, you can simply select the &lt;strong&gt;Body&lt;/strong&gt; option in both the &lt;strong&gt;Inbound BizTalk message body&lt;/strong&gt; and &lt;strong&gt;Outbound WCF message body&lt;/strong&gt; sections on the &lt;strong&gt;Messages&lt;/strong&gt; tab when configuring a WCF Receive Location. On the contrary, you should define a &lt;strong&gt;Path&lt;/strong&gt; in the &lt;strong&gt;Inbound BizTalk message body&lt;/strong&gt; section to extract the payload from the inbound message, and specify a template in the &lt;strong&gt;Outbound WCF message body &lt;/strong&gt;section to include the outgoing response message within a wrapper element.&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/4786.MessagesTab_5F00_67022548.jpg"&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="MessagesTab" border="0" alt="MessagesTab" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6457.MessagesTab_5F00_thumb_5F00_09668E37.jpg" width="480" height="643" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;table style="width: 99%" border="0" cellpadding="5" bgcolor="#f4f4f4"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/6471.Quotes_5F00_Icon_5F00_76353BBD.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/5383.Quotes_5F00_Icon_5F00_thumb_5F00_656D910F.gif" width="23" height="15" /&gt;&lt;/a&gt;&amp;#160;&lt;strong&gt;Note&amp;#160; &lt;br /&gt;&lt;/strong&gt;The namespace of the Message and Data Contract classes match those defined by the XML Schemas that model the request and response messages in the BizTalk Server application.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h1 align="justify"&gt;Service Contracts&lt;/h1&gt;

&lt;p align="justify"&gt;The next step was to define the &lt;a href="http://msdn.microsoft.com/en-us/library/ms733070.aspx"&gt;Service Contracts&lt;/a&gt; used by the client application to exchange messages with BizTalk Server. To this purpose, I created a new project in my solution called &lt;strong&gt;ServiceContracts&lt;/strong&gt;, and then I started off by defining the Service Contract Interface that models the server side of the duplex contract. I declared the signature of a One-Way method called &lt;strong&gt;AskQuestion&lt;/strong&gt;. I specified a parameter of type &lt;strong&gt;BizTalkRequestMessage&lt;/strong&gt; (see the Data and Message Contracts section) and void as return type. Then I decorated the method with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.xmlserializerformatattribute.aspx"&gt;XmlSerializerFormatAttribute&lt;/a&gt; to indicate to the WCF Runtime to use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt; instead of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;DataContractSerializer&lt;/a&gt;. Please note that the WCF Adapters and BizTalk in general use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt;, thus I had to explicitly set the correct serializer in the contract definition. Next, I decorated the method with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.aspx"&gt;OperationContractAttribute&lt;/a&gt; to indicate that the method is one way and to specify the WS-Addressing Action of the request message. Finally I decorated the interface with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.aspx"&gt;ServiceContractAttribute&lt;/a&gt;. &lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;IMagic8BallBizTalk Interface&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;[ServiceContract(Namespace = &lt;span class="str"&gt;&lt;a href="http://microsoft.appfabric.cat/10/samples/duplexmep"&gt;http://microsoft.appfabric.cat/10/samples/duplexmep&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; SessionMode = SessionMode.Required,
                 CallbackContract = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IMagic8BallBizTalkCallback),
                 ConfigurationName = &lt;span class="str"&gt;&amp;quot;IMagic8BallBizTalk&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IMagic8BallBizTalk
{
    [XmlSerializerFormat]
    [OperationContract(Action = &lt;span class="str"&gt;&amp;quot;AskQuestion&amp;quot;&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; AskQuestion(BizTalkRequestMessage requestMessage);
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Then I defined the the callback interface as follows:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;IMagic8BallBizTalkCallback Interface&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;[ServiceContract(Namespace = &lt;span class="str"&gt;&lt;a href="http://microsoft.appfabric.cat/10/samples/duplexmep"&gt;http://microsoft.appfabric.cat/10/samples/duplexmep&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; ConfigurationName = &lt;span class="str"&gt;&amp;quot;IMagic8BallBizTalkCallback&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IMagic8BallBizTalkCallback
{
    [XmlSerializerFormat]
    [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(BizTalkResponseMessage responseMessage);
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;Finally, I linked the two interfaces into a Duplex Contract by assigning the type of the callback interface to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.callbackcontract.aspx"&gt;CallbackContract&lt;/a&gt; property in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.aspx"&gt;ServiceContractAttribute&lt;/a&gt; that decorates the &lt;strong&gt;IMagic8BallBizTalk &lt;/strong&gt;interface. &lt;/p&gt;

&lt;h1 align="justify"&gt;Callback Contract Implementation&lt;/h1&gt;

&lt;p align="justify"&gt;The next step was to implement the &lt;strong&gt;IMagic8BallBizTalkCallback &lt;/strong&gt;callback interface in order to receive response messages from BizTalk Server. To this purpose&amp;#160; I created a new class in the &lt;strong&gt;Client&lt;/strong&gt; project called &lt;strong&gt;Magic8BallBizTalkCallback &lt;/strong&gt;that implements the I&lt;strong&gt;Magic8BallBizTalkCallback &lt;/strong&gt;callback interface.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;Magic8BallBizTalkCallback 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;[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, &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; ResponseFormat, &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; responseMessage.Response.Id, &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; responseMessage.Response.Answer));
        }
    }
    &lt;span class="preproc"&gt;#endregion&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; 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;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;In particular, when the WCF Receive Location invokes the &lt;strong&gt;AskQuestionResponse&lt;/strong&gt; method to return a response message, the callback is handled by a &lt;strong&gt;ThreadPool&lt;/strong&gt; thread other than the main thread running the client application. Since the &lt;strong&gt;InternalWriteToLog&lt;/strong&gt; method is used to write the answer on a &lt;strong&gt;ListBox&lt;/strong&gt; control owned by the main thread, the &lt;strong&gt;WriteToLog&lt;/strong&gt; method exposed by the &lt;strong&gt;MainForm&lt;/strong&gt; class uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx"&gt;InvokeRequired&lt;/a&gt; property to check whether it's necessary to use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.invoke.aspx"&gt;Invoke&lt;/a&gt; method because the caller is on a different thread than the main thread.&lt;/p&gt;

&lt;h1 align="justify"&gt;Invoking BizTalk Server&lt;/h1&gt;

&lt;p align="justify"&gt;The next step was to write the code to invoke one of the 3 WCF Receive Locations exposed by by BizTalk application.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;btnAsk_Click Method&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;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="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="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="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(cboEndpoint.Text))
        {
            WriteToLog(NoEndpointsFound);
        }

        DuplexChannelFactory&amp;lt;IMagic8BallBizTalk&amp;gt; channelFactory = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            BizTalkRequest request = &lt;span class="kwrd"&gt;new&lt;/span&gt; BizTalkRequest(txtQuestion.Text, delay);
            BizTalkRequestMessage requestMessage = &lt;span class="kwrd"&gt;new&lt;/span&gt; BizTalkRequestMessage(request);
            WriteToLog(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(CultureInfo.CurrentCulture, &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; RequestFormat, &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; cboEndpoint.Text, &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; request.Id, &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; request.Question));
            InstanceContext context = &lt;span class="kwrd"&gt;new&lt;/span&gt; InstanceContext(&lt;span class="kwrd"&gt;new&lt;/span&gt; Magic8BallBizTalkCallback(&lt;span class="kwrd"&gt;this&lt;/span&gt;));
            channelFactory = &lt;span class="kwrd"&gt;new&lt;/span&gt; DuplexChannelFactory&amp;lt;IMagic8BallBizTalk&amp;gt;(context, cboEndpoint.Text);
            IMagic8BallBizTalk channel = channelFactory.CreateChannel();
            channel.AskQuestion(requestMessage);
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (FaultException ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (channelFactory != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                channelFactory.Abort();
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (CommunicationException ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (channelFactory != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                channelFactory.Abort();
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (TimeoutException ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (channelFactory != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                channelFactory.Abort();
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
            WriteToLog(ex.Message);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (channelFactory != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                channelFactory.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;As you may have noticed, the method &lt;strong&gt;btnAsk_Click &lt;/strong&gt;performs the following actions in order:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Creates a data contract object (&lt;strong&gt;BizTalkRequest&lt;/strong&gt;) &lt;/li&gt;

  &lt;li&gt;Creates a message contract object (&lt;strong&gt;BizTalkRequestMessage&lt;/strong&gt;). &lt;/li&gt;

  &lt;li&gt;Creates a new instance of the &lt;strong&gt;Magic8BallBizTalkCallback&lt;/strong&gt; type to handle callbacks. &lt;/li&gt;

  &lt;li&gt;Creates a new &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontext.aspx"&gt;InstanceContext&lt;/a&gt; object. In particular, the &lt;strong&gt;Magic8BallBizTalkCallback&lt;/strong&gt; object is passed in as argument to the constructor of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontext.aspx"&gt;InstanceContext&lt;/a&gt; object. &lt;/li&gt;

  &lt;li&gt;Instantiates a &lt;a href="http://msdn.microsoft.com/en-us/library/ms576164.aspx"&gt;DuplexChannelFactory&lt;/a&gt; to create a duplex channel of type &lt;strong&gt;IMagic8BallBizTalk&lt;/strong&gt;.&amp;#160; In particular, the first argument specifies the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontext.aspx"&gt;InstanceContext&lt;/a&gt; that the client uses to listen for messages from the connected service, in our case BizTalk Server. &lt;/li&gt;

  &lt;li&gt;Creates a new duplex channel. &lt;/li&gt;

  &lt;li&gt;Invokes the &lt;strong&gt;AskQuestion&lt;/strong&gt; method. &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;Configuration File&lt;/h1&gt;

&lt;p&gt;The final step was to define the client endpoints in the client configuration file in order to invoke the 3 WCF Receive Locations exposed by the BizTalk application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configuration File&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;&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;netNamedPipeBinding&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;netNamedPipeBinding&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;netNamedPipeBinding&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;wsDualHttpBinding&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;wsDualHttpBinding&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;wsDualHttpBinding&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;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: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;IMagic8BallBizTalk&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;NetTcpEndpointBizTalk&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.pipe://localhost/magic8ballbiztalk/sync&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netNamedPipeBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netNamedPipeBinding&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallBizTalk&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;NetNamedPipeEndpointBizTalk&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;http://localhost/magic8ballbiztalk/syncmagic8ball.svc&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;wsDualHttpBinding&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;wsDualHttpBinding&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IMagic8BallBizTalk&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WsDualHttpEndpointBizTalk&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;We are now ready to test the solution.&lt;/p&gt;

&lt;h1&gt;Testing the Solution&lt;/h1&gt;

&lt;p&gt;To test the application, you can proceed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Configure and 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 the following endpoints: 
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;NetTcpEndpointBizTalk&lt;/strong&gt; to invoke the &lt;strong&gt;DuplexMEP.Sync.WCF-NetTcp.ReceiveLocation&lt;/strong&gt;. &lt;/li&gt;

      &lt;li&gt;&lt;strong&gt;NetNamedPipeEndpointBizTalk&lt;/strong&gt; to invoke the &lt;strong&gt;DuplexMEP.Sync.WCF-NetNamedPipe.ReceiveLocation&lt;/strong&gt;. &lt;/li&gt;

      &lt;li&gt;&lt;strong&gt;WsDualHttpEndpointBiztalk&lt;/strong&gt; to invoke the&lt;strong&gt; DuplexMEP.Sync.WCF-Custom.WsDualHttpBinding.ReceiveLocation&lt;/strong&gt;. &lt;/li&gt;
    &lt;/ul&gt;
  &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/3252.Client_5F00_30808BD2.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="Client" border="0" alt="Client" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8154.Client_5F00_thumb_5F00_5D65C8E0.jpg" width="639" height="518" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&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 BizTalk in an asynchronous way. Therefore, the client application doesn't need to wait for the response to the previous question before posing a new one.&lt;/p&gt;

&lt;p align="justify"&gt;In order for the demo to work, it’s important that the &lt;strong&gt;Delay&lt;/strong&gt; in seconds that you specify in the client application is less than the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.binding.receivetimeout.aspx"&gt;ReceiveTimeout&lt;/a&gt;&lt;/strong&gt; configured in the WCF Receive Location. When using a WCF Adapter other than the &lt;strong&gt;WCF-Custom&lt;/strong&gt; and &lt;strong&gt;WCF-CustomIsolated&lt;/strong&gt;, you cannot specify a custom &lt;strong&gt;ReceiveTimeout&lt;/strong&gt;. The following picture shows the Binding tab of a WCF-NetTcp Receive Location. &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/5355.BindingTab_5F00_1CB356A4.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="BindingTab" border="0" alt="BindingTab" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/0576.BindingTab_5F00_thumb_5F00_28587809.jpg" width="480" height="643" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;As a consequence, the default 10 minutes timeout will be used. Therefore, if you need to increase the &lt;strong&gt;ReceiveTimeout&lt;/strong&gt; beyond 10 minutes, you can replace the WCF Adapter in question with the &lt;strong&gt;WCF-Custom&lt;/strong&gt; and &lt;strong&gt;WCF-CustomIsolated &lt;/strong&gt;adapter and select the same binding. This way, you can specify a custom value for the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.binding.receivetimeout.aspx"&gt;ReceiveTimeout&lt;/a&gt;&lt;/strong&gt; property exposed by the binding, as shown in the following picture:&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/8422.WCF_2D00_CustomBindingTab_5F00_741428F5.jpg"&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="WCF-CustomBindingTab" border="0" alt="WCF-CustomBindingTab" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83-metablogapi/1104.WCF_2D00_CustomBindingTab_5F00_thumb_5F00_3DB2DB19.jpg" width="480" height="643" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Conclusions&lt;/h1&gt;

&lt;p align="justify"&gt;In this article we have seen 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;. 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;next article&lt;/a&gt; of the series, we’ll see how to implement an asynchronous communication between our 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 meantime, &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;Acknowledge review and comments from &lt;a href="http://blogs.msdn.com/members/valerym/"&gt;Valery Mizonov&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/members/Christian.Martinez/"&gt;Christian Martinez&lt;/a&gt;. Thanks guys!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10095507" 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/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></item><item><title>A Configurable AppFabric Cache Attribute For Your WCF Services</title><link>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/10/a-configurable-cache-attribute-for-your-wcf-services.aspx</link><pubDate>Wed, 10 Nov 2010 21:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10089138</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=10089138</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/appfabriccat/commentapi.aspx?WeblogPostID=10089138</wfw:comment><comments>http://blogs.msdn.com/b/appfabriccat/archive/2010/11/10/a-configurable-cache-attribute-for-your-wcf-services.aspx#comments</comments><description>&lt;p&gt;&lt;span style="background-color: #ffffff; color: #ffffff;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Doing a search online for WCF and Cache will eventually lead you to a number of links* demonstrating the use of an &lt;/span&gt;&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ioperationinvoker.aspx"&gt;&lt;span style="color: #743399;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;IOperationInvoker&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; implementation to manage caching.&amp;nbsp;With AppFabric Cache&amp;nbsp;rapidly becoming a mainstream enterprise technology I felt&amp;nbsp;this to be an ideal time to revisit this concept.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;I chose to offer the following features in my &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14512"&gt;implementation&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Using the default or a named cache&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Using a cache region&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Action keyed caching&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Choice of using one or more parameters to the operation as a key&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Choice of&amp;nbsp;XML serialized keys or a more compact form&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Segoe; font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Choice of &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;&lt;span style="color: #743399;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;XmlSerializer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; or&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;&lt;span style="color: #743399;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;DataContractSerializer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;when using the XML serialization option&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Using an &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ioperationinvoker.aspx"&gt;&lt;span style="color: #743399;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;IOperationInvoker&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;implementation allows for the following pattern&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-83/1778.CacheProcess.png" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="file:///C:/Users/chmar/AppData/Local/Temp/WindowsLiveWriter1286139640/supfiles3D7EFBFD/CacheProcess[208].png"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Using the custom invoker in your code is straightforward and natural as the following snippet from the test service provided with the code attached to this blog demonstrates&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;         /// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// This method is for testing cache retrieval by key.&lt;/span&gt;
        &lt;span class="rem"&gt;///&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="catGuy"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
        [&lt;span style="color: #4bacc6;"&gt;OperationContract&lt;/span&gt;]
        [&lt;span style="color: #4bacc6;"&gt;AppFabricCacheBehavior&lt;/span&gt;]
        &lt;span style="color: #4bacc6;"&gt;CatMember&lt;/span&gt; GetCat(&lt;span class="kwrd"&gt;long&lt;/span&gt; catGuy);

        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// This method is for testing demonstrating cache by Action.&lt;/span&gt;
        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
        [&lt;span style="color: #4bacc6;"&gt;OperationContract&lt;/span&gt;]
        [&lt;span style="color: #4bacc6;"&gt;AppFabricCacheBehavior&lt;/span&gt;(CacheByAction=&lt;span class="kwrd"&gt;true&lt;/span&gt;)]
        &lt;span style="color: #4bacc6;"&gt;List&amp;lt;&lt;/span&gt;&lt;span class="kwrd"&gt;long&lt;/span&gt;&lt;span style="color: #4bacc6;"&gt;&amp;gt;&lt;/span&gt; GetIds();&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: x-small;"&gt;&lt;span style="font-size: small;"&gt;As you&amp;nbsp; can see it&amp;rsquo;s only a matter of supplying an additional attribute along with your &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.aspx"&gt;&lt;span style="color: #743399;"&gt;&lt;span style="font-size: small;"&gt;OperationContract&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;..&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe;"&gt;&lt;span style="font-size: small;"&gt;The behavior code itself is very simple and contains descriptions of what the attribute parameters do&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    [&lt;span style="color: #4bacc6;"&gt;AttributeUsage(&lt;/span&gt;AttributeTargets.Method&lt;span style="color: #4bacc6;"&gt;)&lt;/span&gt;]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AppFabricCacheBehavior : Attribute, IOperationBehavior
    {
        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// If this property is true the only key considered is Action.&lt;/span&gt;
        &lt;span class="rem"&gt;/// A common use case scenario is a method that returns a slowly changing drop down list.&lt;/span&gt;
        &lt;span class="rem"&gt;/// Setting this will cause all other non AppFabric Cache specific options to be ignored.&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;bool&lt;/span&gt; CacheByAction { get; set; }

        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// If this property is true then either DataContractSerializer or XmlSerializer will be used on keys and then concatenated.&lt;/span&gt;
        &lt;span class="rem"&gt;/// By default this is false and the key will be a simple string concatenation &lt;/span&gt;
        &lt;span class="rem"&gt;/// You should set this to true when using complex type(s) as a key.&lt;/span&gt;
        &lt;span class="rem"&gt;/// Avoid setting this to true when you are using primitive type(s) as a key.&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;bool&lt;/span&gt; SerializeKeysToXml { get; set; }

        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// Substitutes XmlSerializer for DataContractSerializer when SerializeKeysToXml is true.&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;bool&lt;/span&gt; UseXmlSerializer { get; set; }

        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// Retrieves items from the named cache if not null. If CacheName is not specified DefaultCache will be used. &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;string&lt;/span&gt; CacheName { get; set; }

        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// Retrieves items from the named region.  &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;string&lt;/span&gt; CacheRegion { get; set; }

        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// Indexes of the objects to generate key from. If not specified it will default to KeyIndexes = new int[]{0}.  &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;int&lt;/span&gt;[] KeyIndexes { get; set; }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
        {
            
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {
            
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {
            dispatchOperation.Invoker = &lt;span class="kwrd"&gt;new&lt;/span&gt; AppFabricCachingInvoker(&lt;span class="kwrd"&gt;this&lt;/span&gt;, dispatchOperation.Invoker,dispatchOperation.Action);
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Validate(OperationDescription operationDescription)
        {
            
        }
    }&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: x-small;"&gt;&lt;span style="font-size: small;"&gt;The only real work being done in this class is forwarding the original Invoker and passing in the Action&lt;/span&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-family: Segoe; font-size: medium;"&gt;Attribute Parameter&amp;nbsp;Use Cases&amp;nbsp;and Observations&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe;"&gt;&lt;span style="font-size: small;"&gt;While I was researching this article I&amp;nbsp;noticed in some implementations they would unconditionally &amp;nbsp;serialize all the parameters to XML and then concatenate them into a giant key.&amp;nbsp;I still allow&amp;nbsp;you to do this in my implementation if you choose to but I also give you a choice to use a simpler more compact format that will greatly reduce the memory usage when using primitive types. In&amp;nbsp;simple test cases this cuts memory&amp;nbsp;usage in 1/2 and I suspect in cases with very&amp;nbsp;large payloads the effect is even more&amp;nbsp;dramatic.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe;"&gt;&lt;span style="font-size: small;"&gt;I also noticed some of the implementations did not take into account methods using zero parameters in their key calculations.&amp;nbsp;It is a common occurrence to&amp;nbsp;see Web Services built with zero parameter methods in order to provide for retrieving lists and such. By setting&amp;nbsp;CacheByAction=true&amp;nbsp;in the supplied code you will bypass key calculation logic and immediately use the Action parameter passed in as a key instead.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe;"&gt;&lt;span style="font-size: small;"&gt;Test runs on my system ran approximately 3 times faster for cached responses versus having to access the database. As with any performance testing however, you will need to test in your own environment to see the effect a solution like the one presented might have.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-family: Segoe; font-size: medium;"&gt;Try It Out&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;Please&amp;nbsp;give the &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;amp;DownloadId=14512"&gt;code&lt;/a&gt; a test run and&amp;nbsp;drop a comment if you would like a new feature or find what you think is a bug.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-family: Segoe; font-size: medium;"&gt;&lt;/span&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: xx-small;"&gt;*The following links all demonstrate a form of caching using an IOperationInvoker implementation&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: xx-small;"&gt;&lt;span style="font-family: Times New Roman; color: #26252a;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span lang="EN" style="color: #333333; mso-ansi-language: EN;"&gt;&lt;a href="http://madridcentral.com/blogs/chris/archive/2006/01/22/46.aspx"&gt;&lt;span style="color: #743399;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;Windows Communication Foundation Extensibility&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: xx-small;"&gt;&lt;span lang="EN" style="color: #333333; mso-ansi-language: EN;"&gt;&lt;/span&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="line-height: 125%; color: #26252a;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span lang="EN" style="color: #333333; mso-ansi-language: EN;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163302.aspx#S6" style="FONT-FAMILY: "&gt;Extending WCF with Custom Behaviors&lt;/a&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt; by &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="color: #26252a;"&gt;Aaron Skonnard&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: xx-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="color: #26252a;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span lang="EN" style="color: #333333; mso-ansi-language: EN;"&gt;&lt;a href="http://sankarsan.wordpress.com/2009/01/18/developing-custom-operationinvoker/"&gt;&lt;span style="color: #743399;"&gt;Developing Custom OperationInvoker&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt; by Sankarsan&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Segoe; font-size: xx-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span lang="EN" style="color: #333333; mso-ansi-language: EN;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;&lt;span style="line-height: 125%; color: #26252a;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span lang="EN" style="color: #333333; mso-ansi-language: EN;"&gt;&lt;a href="http://blogical.se/blogs/mikael/archive/2010/09/12/use-appfabric-cache-to-cache-your-wcf-service-response.aspx"&gt;&lt;span style="color: #743399;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt;Use AppFabric Cache to cache your WCF Service response&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: xx-small;"&gt; by Mikael H&amp;aring;kansson&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="line-height: 125%; color: #26252a; font-size: 7pt;"&gt;&lt;span style="font-family: arial,helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Thanks to Paolo Salvatori,&amp;nbsp; Valery Mizonov, and Quoc Bui for their review&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph"&gt;&lt;span style="line-height: 125%; font-family: 'Times New Roman','serif'; color: #26252a; font-size: 7pt;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoListParagraph"&gt;&lt;span style="line-height: 125%; font-family: 'Times New Roman','serif'; color: #26252a; font-size: 7pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: #ffffff; color: #ffffff;"&gt;Built for Quoc&lt;/span&gt;&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=10089138" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/AppFabric/">AppFabric</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/WCF/">WCF</category><category domain="http://blogs.msdn.com/b/appfabriccat/archive/tags/Cache/">Cache</category></item></channel></rss>
