<?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>Matt W's Windows Workflow Place : Orcas</title><link>http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx</link><description>Tags: Orcas</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Advanced Workflow Service Talk (Demo 4 of 4)</title><link>http://blogs.msdn.com/mwinkle/archive/2008/08/11/advanced-workflow-service-talk-demo-4-of-4.aspx</link><pubDate>Mon, 11 Aug 2008 18:52:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8848313</guid><dc:creator>mwinkle</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/8848313.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=8848313</wfw:commentRss><description>&lt;p&gt;When we start doing this two way style of messaging, we now open up to start modeling some interesting business problems.&amp;#160; In the previous post, you'll note that I did not include the code, because I mentioned we needed to be more clever in scenarios where we listen in parallel.&amp;#160; &lt;/p&gt;  &lt;p&gt;First, a brief diversion into how the Receive activity works.&amp;#160; Everybody remembers the workflow queues, the technology that underlies all communication between a host and a workflow instance.&amp;#160; The Receive activity works by creating a queue that the WorkflowServiceHost (specifically the WorkflowOperationInvoker) will use to send the message received off the wire into the workflow.&amp;#160; Now, the Receive activity normally just creates a queue that is named the same as the operation the Receive activity is bound to.&amp;#160; However, if we have two Receive activities listening for the same operation at the same time, no longer is a single queue useful to route responses back as we want to route to the correct Receive activity instance.&amp;#160; &lt;/p&gt;  &lt;p&gt;There is property on the Receive activity called ContextToken.&amp;#160; Normally this is null in the simple case.&amp;#160; However, when we want our Receive activity to operate in parallel, we need to indicate that it needs to be smarter when it creates a queue.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServiceTalkDemo4of4_9005/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="227" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServiceTalkDemo4of4_9005/image_thumb.png" width="409" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;By setting this property (you can just type in a name, and then select the common owner all of the parallel receive's share.&amp;#160; This will cause the Receive activity to create a queue named [OperationName] +[ConversationId], the conversation ID takes the form of a GUID, and is the second element inside a context token.&amp;#160; &lt;/p&gt;  &lt;p&gt;The sample that I show for this talk is simply the &lt;a href="http://msdn.microsoft.com/en-us/library/bb410775.aspx"&gt;conversations sample inside the SDK&lt;/a&gt;.&amp;#160; This is the sample to check out to understand all sorts of interesting ways to use the context tokens to model your processes.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb410775.aspx"&gt;&lt;img alt="Conversations Sample Architecture" src="http://i.msdn.microsoft.com/Bb410775.7f198cc1-b77a-4460-a007-4ac0ac91a109(en-us,VS.90).gif" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now, there are two conversation patterns here.&amp;#160; One is the one shown above, which I refer to as an &lt;em&gt;n&lt;/em&gt;-party conversation where &lt;em&gt;n&lt;/em&gt; is fixed at design time.&amp;#160; We can accomplish this with the parallel activity.&amp;#160; The other is where &lt;em&gt;n&lt;/em&gt; is arbitrary (imagine you send out to business partners stored in the database).&amp;#160; The way to do this is to use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.activities.replicatoractivity.aspx"&gt;Replicator&lt;/a&gt; activity.&amp;#160; The Replicator is a little known gem shipped in 3.0 that essentially gives you &amp;quot;ForEach&amp;quot; semantics.&amp;#160; But, by flipping the &lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.activities.replicatoractivity.executiontype.aspx"&gt;ExecutionType&lt;/a&gt; switch to parallel, I now get the behavior of a parallel, but operating with an arbitrary &lt;em&gt;n&lt;/em&gt; branches. &lt;/p&gt;  &lt;p&gt;So, in order to enable conversations, we need to tell our receive activity to be a little smarter about how it generates its queue name, and then we simply follow the duplex pattern we discussed in the last &lt;a href="http://blogs.msdn.com/mwinkle/archive/2008/08/06/advanced-workflow-services-talk-demo-2-of-4.aspx#comments"&gt;two&lt;/a&gt; &lt;a href="http://blogs.msdn.com/mwinkle/archive/2008/08/07/advanced-workflow-services-talk-demo-3-of-4.aspx"&gt;posts&lt;/a&gt;.&amp;#160; Once we do that, we're in good shape to start modeling some more interesting communication patterns between multiple parties.&amp;#160; &lt;/p&gt;  &lt;h3&gt;Where can we go from here? &lt;/h3&gt;  &lt;p&gt;   &lt;br /&gt;We can just make the patterns more interesting.&amp;#160; One interesting one would be the combination of the long running work with cancellation and a &lt;a href="http://blogs.msdn.com/mwinkle/archive/2007/06/27/implementing-the-n-of-m-pattern-in-wf.aspx"&gt;Voting activity&lt;/a&gt; in order to coordinate the responses and allow for progress to be made when some of the branches complete (if I have 3 yes votes, I can proceed).&amp;#160; The power of building composite activities is that it gives me a uniform programming model (and a single threaded one to boot) in order to handle the coordination of different units of work.&amp;#160; Get out there and write some workflows :-) &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8848313" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/patterns/default.aspx">patterns</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/presentations/default.aspx">presentations</category></item><item><title>Advanced Workflow Services Talk (Demo 3 of 4)</title><link>http://blogs.msdn.com/mwinkle/archive/2008/08/07/advanced-workflow-services-talk-demo-3-of-4.aspx</link><pubDate>Fri, 08 Aug 2008 00:17:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8841711</guid><dc:creator>mwinkle</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/8841711.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=8841711</wfw:commentRss><description>&lt;p&gt;So, we've seen in part 1 how to manage context, we saw in part 2 how we can take that basic knowledge to do duplex messaging.&amp;#160; Once we start doing duplex work, there are some interesting patterns, and the first one is one that we like to call &amp;quot;long running work&amp;quot;.&amp;#160; Why are we interested in this?&amp;#160; Well, as you probably know, the execution of a workflow is single threaded (this is a feature, not a bug).&amp;#160; We also don't have a mechanism to force the workflow to be &amp;quot;pinned&amp;quot; in memory.&amp;#160; What this means is that things like the asynchronous programming model&amp;#160; (APM), can't be used, since there isn't a guarantee that there will be something to call back when we are done.&amp;#160; What this means is that the send activity can not take advantage of the APM to be more thread friendly.&lt;/p&gt;  &lt;p&gt;We may want to do things in parallel, like this&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo3of4_D4A0/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="309" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo3of4_D4A0/image_thumb.png" width="616" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If each of these branches takes 3 seconds, the whole of this workflow will complete in about 9 seconds.&amp;#160; The general expectation is that in parallel, this would happen at the length of the longest branch + some minor delta for overhead.&amp;#160; The trouble is, APM programming is tricky, especially relative to the layout above.&lt;/p&gt;  &lt;p&gt;In order to model APM style service calls, but allowing for the service operations to be extremely long running, where extremely is defined as &amp;quot;long enough to where I would want to be able to persist.&amp;quot;&amp;#160; The approach then is to model this as disjoint send and receive activities.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo3of4_D4A0/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="386" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo3of4_D4A0/image_thumb_1.png" width="632" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;One intermediate step is to simply use one way messaging, but the problem there is that in a lot of cases, I'm looking for some information being sent back to me.&amp;#160; &lt;/p&gt;  &lt;p&gt;I'll hold off on the code for the above, the fact we are listening in parallel for the same operation requires us to be a little more clever. &lt;/p&gt;  &lt;p&gt;Let's look first at our contract, and then our service implementation:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Long_Running_Work&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    [ServiceContract]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ILongRunningWork&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        [OperationContract]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;string&lt;/span&gt; TakeAWhile(&lt;span class="kwrd"&gt;int&lt;/span&gt; i);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; OneWayTakeAWhile( &lt;span class="kwrd"&gt;int&lt;/span&gt; i);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; TakeAWhileAndTellMeLater(IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;,&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; contextToken, &lt;span class="kwrd"&gt;int&lt;/span&gt; i);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    [ServiceContract]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IReverseContract&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; TakeAWhileAndTellMeLaterDone(&lt;span class="kwrd"&gt;string&lt;/span&gt; s);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;   &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;And now for the implementation of these;&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Long_Running_Work&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Service1 : ILongRunningWork&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Service1()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;           &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &lt;span class="preproc"&gt;#region&lt;/span&gt; ILongRunningWork Members&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; TakeAWhile(&lt;span class="kwrd"&gt;int&lt;/span&gt; i)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Starting TakeAWhile&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            System.Threading.Thread.Sleep(&lt;span class="kwrd"&gt;new&lt;/span&gt; TimeSpan(0, 0, 3));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; i.ToString();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OneWayTakeAWhile( &lt;span class="kwrd"&gt;int&lt;/span&gt; i)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Starting One Way TakeAWhile&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;            System.Threading.Thread.Sleep(&lt;span class="kwrd"&gt;new&lt;/span&gt; TimeSpan(0, 0, 3));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Ending One Way TakeAWhile&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TakeAWhileAndTellMeLater(IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; context, &lt;span class="kwrd"&gt;int&lt;/span&gt; i)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Received the context Token&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;            System.Threading.Thread.Sleep(&lt;span class="kwrd"&gt;new&lt;/span&gt; TimeSpan(0, 0, 3));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Need to Message Back Now {0}&amp;quot;&lt;/span&gt;, i.ToString());&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;            &lt;span class="rem"&gt;// could investigate a more useful pooling of these if we &lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;            &lt;span class="rem"&gt;// really wanted to worry about perf&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;            IReverseContractClient ircc = &lt;span class="kwrd"&gt;new&lt;/span&gt; IReverseContractClient(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;                &lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpContextBinding(),&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;                &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(&lt;span class="str"&gt;&amp;quot;net.tcp://localhost:10003/ReverseContract&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;                );&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  43:  &lt;/span&gt;            IContextManager icm = ircc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  44:  &lt;/span&gt;            icm.SetContext(context);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  45:  &lt;/span&gt;            ircc.TakeAWhileAndTellMeLaterDone(i.ToString());&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  46:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  47:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  48:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  49:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  50:  &lt;/span&gt;        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  51:  &lt;/span&gt;    } &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  52:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  53:  &lt;/span&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; IReverseContractClient : ClientBase&amp;lt;IReverseContract&amp;gt;, IReverseContract&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  54:  &lt;/span&gt;   {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  55:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; IReverseContractClient() : &lt;span class="kwrd"&gt;base&lt;/span&gt;(){}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  56:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; IReverseContractClient(System.ServiceModel.Channels.Binding binding, EndpointAddress address) : &lt;span class="kwrd"&gt;base&lt;/span&gt;(binding, address) { }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  57:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  58:  &lt;/span&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; IReverseContract Members&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  59:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  60:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  61:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  62:  &lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TakeAWhileAndTellMeLaterDone(&lt;span class="kwrd"&gt;string&lt;/span&gt; s)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  63:  &lt;/span&gt;       {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  64:  &lt;/span&gt;           &lt;span class="kwrd"&gt;base&lt;/span&gt;.Channel.TakeAWhileAndTellMeLaterDone(s);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  65:  &lt;/span&gt;       }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  66:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  67:  &lt;/span&gt;       &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  68:  &lt;/span&gt;   }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  69:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  70:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Basically, we sit around and wait.&amp;#160; You'll also note in the TakeAWhileAndTellMeLater, we take in a context token (similar to our previous approach), and we will use that to new up a client at the end and call back in after setting the context.&amp;#160; Look at lines 39-44 above.&amp;#160; The nice thing about this is that my above workflow client can actually go idle, persist, and react to a message being delivered later on.&lt;/p&gt;

&lt;p&gt;One thing to note is that one should not place a delay between any of the Send and Receives.&amp;#160; This could cause the workflow to go idle, which may allow you to miss messages.&amp;#160; This is generally considered, a bad thing.&amp;#160; The reason this occurs is that the WorkflowOperationInvoker will use EnqueueOnIdle which means that when teh workflow goes idle, the message will be enqueued.&amp;#160; If the queue hasn't been created by the Receive activity, the message will not get delivered.&lt;/p&gt;

&lt;p&gt;For the final workflow above (the TakeAWhileAndTellMeLater workflow), I will need to spin this up in a WorkflowServiceHost (a la the Duplex Sample in part 2).&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (WorkflowServiceHost wsh = &lt;span class="kwrd"&gt;new&lt;/span&gt; WorkflowServiceHost(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CallLongRunningComponents.WorkflowWithmessaging)))
{
    wsh.AddServiceEndpoint(
            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Long_Running_Work.IReverseContract),
            &lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpContextBinding(),
           &lt;span class="str"&gt;&amp;quot;net.tcp://localhost:10003/ReverseContract&amp;quot;&lt;/span&gt;
            );
    &lt;span class="rem"&gt;// don't forget to open up the wsh&lt;/span&gt;
    WorkflowRuntime wr = wsh.Description.Behaviors.Find&amp;lt;WorkflowRuntimeBehavior&amp;gt;().WorkflowRuntime;

    wsh.Open();


    WorkflowInstance wi = wr.CreateWorkflow(
        &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CallLongRunningComponents.WorkflowWithmessaging));
    wr.WorkflowCompleted += ((o, e) =&amp;gt; waitHandle.Set());
    wr.WorkflowIdled += ((o, e) =&amp;gt; Console.WriteLine(&lt;span class="str"&gt;&amp;quot;We're idled&amp;quot;&lt;/span&gt;));
        

    wi.Start();




    waitHandle.WaitOne();

}&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Why do I think this is cool? &lt;/p&gt;

&lt;p&gt;Two reasons:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If I assume that I can modify the called service to callback to me (or put such a wrapper at a runtime service level), this is easier to model than the APM (that code included at the end of this post) &lt;/li&gt;

  &lt;li&gt;This gives me a natural way to start exposing more advanced control over a service call.&amp;#160; Rather than just a send and receive, I can use a send and a listen, and in the listen have a receive, a cancel message receive, and a delay in order to expose more fine grained control points for my workflow, and model the way the process should work very explicitly and declaratively. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo3of4_D4A0/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="503" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo3of4_D4A0/image_thumb_2.png" width="449" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;Code for APM approach:&lt;/h4&gt;

&lt;p&gt;call some services and wait:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press &amp;lt;enter&amp;gt; to execute APM approach&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;Console.ReadLine();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;waitHandle = &lt;span class="kwrd"&gt;new&lt;/span&gt; AutoResetEvent(&lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;Stopwatch sw = &lt;span class="kwrd"&gt;new&lt;/span&gt; Stopwatch();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;sw.Start();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;lrwc = &lt;span class="kwrd"&gt;new&lt;/span&gt; WorkflowHost.ServiceReference1.LongRunningWorkClient();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;lrwc.BeginTakeAWhile(1, HandleClientReturn, &lt;span class="str"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;lrwc.BeginTakeAWhile(2, HandleClientReturn, &lt;span class="str"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;lrwc.BeginTakeAWhile(3, HandleClientReturn, &lt;span class="str"&gt;&amp;quot;three&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;lrwc.BeginTakeAWhile(4, HandleClientReturn, &lt;span class="str"&gt;&amp;quot;four&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&lt;span class="kwrd"&gt;while&lt;/span&gt; (!areDone)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    System.Threading.Thread.Sleep(25);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;APM approach compelted in {0} milliseconds&amp;quot;&lt;/span&gt;, sw.ElapsedMilliseconds);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;All Done, press &amp;lt;enter&amp;gt; to exit&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;Console.ReadLine();&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Ignore the busy wait on line 11, I should use a waithandle here but was having trouble getting it to work correctly (this is hard code).&lt;/p&gt;

&lt;p&gt;The callback and respective state:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; ServiceReference1.LongRunningWorkClient lrwc;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; Int32 countOfFinished = 0;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; HandleClientReturn(IAsyncResult result)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; s = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)result.AsyncState;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; resultString = lrwc.EndTakeAWhile(result);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;received {0}&amp;quot;&lt;/span&gt;, resultString);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (Interlocked.Increment(&lt;span class="kwrd"&gt;ref&lt;/span&gt; countOfFinished) == 4)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        areDone = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;I have had some people say that line 9 should use &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.interlocked.compareexchange.aspx"&gt;Interlocked.CompareExchange&lt;/a&gt; in order to do this correctly, but the point is that this is tricky code, that modeling in WF is pretty nice.&amp;#160; [ignoring for the moment the work required to realize the assumption that we can make the service message back.]&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8841711" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/presentations/default.aspx">presentations</category></item><item><title>Q &amp; A on Advanced Workflow Services talk</title><link>http://blogs.msdn.com/mwinkle/archive/2008/08/07/q-a-on-advanced-workflow-services-talk.aspx</link><pubDate>Thu, 07 Aug 2008 22:13:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8841511</guid><dc:creator>mwinkle</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/8841511.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=8841511</wfw:commentRss><description>&lt;p&gt;Martin posted an interesting question &lt;a href="http://blogs.msdn.com/mwinkle/archive/2008/08/06/advanced-workflow-services-talk-demo-2-of-4.aspx#8840881"&gt;here&lt;/a&gt; on my last post:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;&amp;lt;quote&amp;gt;&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;The first thing that we need to do in order to enable this duplex messaging to occur is that the &amp;quot;client&amp;quot; workflow has to explicitly provide its context token to the service so that the service can address the appropriate instance of the client workflow.&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Note, in the real world, you'll probably need to supply more than just the context token, you will need some address and binding information.&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;&amp;lt;/quote&amp;gt;&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Shouldn't we have this built into a custom binding? (or an extra binding element) So with every call from the client the (WF)context information is included. And the developer is not required to follow a (artificial) state machine.&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Note, at the time, when the service calls back, the endpoint (and the binding) of the client may have changed... So we may need dynamic name-endpoint resolution (sounds like DNS?)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Martin&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The question here is generally also asked as &amp;quot;wait, why do I need to explicitly provide a context token and change the contract to have this context thing?&amp;quot;&amp;#160; This is a common question, as changing the contract to reflect implementation details is generally a no-no.&amp;#160; There's one part I left out as well, so let me add that here:&lt;/p&gt;  &lt;p&gt;In the real world, one may also wish to not change the contract (or may not have the ability to).&amp;#160; In that case, we still need to explicitly provide the context token and endpoint information in order to allow me to call back.&amp;#160; There are a few ways to do this, of varying complexity and implication:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Put this into the message header and have the other side extract this information and use it the same way.&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;There are two downsides to this approach:&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;It still requires management of the other side to agree upon where the context token is being place.&lt;/li&gt;        &lt;li&gt;The WF Messaging activities don't give me an easy way to reach in and get to header information, but one could certainly look at some infrastructure level extensions to manage this.&amp;#160; This idea of making duplex easier is one thing that Ed will be talking about in his &lt;a href="http://channel9.msdn.com/pdc2008/TL06/"&gt;Oslo workflow services talk at PDC&lt;/a&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt;    &lt;li&gt;Create a custom binding element.&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;There is one downside with this approach:&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;You're creating a custom channel, custom binding element, and all the other stuff that goes along with creating a channel.&amp;#160; This is very hard work.&amp;#160; If the answer is &amp;quot;you've got to write a channel to do it,&amp;quot; we need to do a better job making it easier (see earlier point about Ed's talk).&lt;/li&gt;     &lt;/ul&gt;      &lt;li&gt;If that's the behavior that you want, you are certainly welcome do go down that path, it would be great to hear about your experiences doing it!&lt;/li&gt;      &lt;li&gt;The upside to this approach:&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;You're creating a layer of near infinite extensibility, allowing you to handle simple things to the complex dynamic endpoint resolution behavior, once you invest the cost once to create the channel that would sit there and do that.&lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;This is also the same approach one could take with using an implicit, or content based correlation scheme.&amp;#160; In that case, you create an intermediary that is responsible for translating message contents into the &amp;quot;addressing&amp;quot; information for the instance.&amp;#160; That intermediary can be a service, it could be a channel, and once you put that intermediary in place, you are free to do as sophisticated or as simple work as possible.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8841511" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category></item><item><title>Advanced Workflow Services Talk (Demo 2 of 4)</title><link>http://blogs.msdn.com/mwinkle/archive/2008/08/06/advanced-workflow-services-talk-demo-2-of-4.aspx</link><pubDate>Wed, 06 Aug 2008 21:30:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8838441</guid><dc:creator>mwinkle</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/8838441.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=8838441</wfw:commentRss><description>&lt;p&gt;A continuation of my series of demos from my advanced workflow services talk.&amp;#160; Here we focus on duplex message exchange patterns.&lt;/p&gt;  &lt;p&gt;Duplex messaging is something that we model at the application level (as opposed to the infrastructure level) because we want to model that message exchange at the level of the application.&amp;#160; Here's some scenarios where I could use duplex messaging:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;[concrete] I submit an order, and you tell me when it ships &lt;/li&gt;    &lt;li&gt;[abstract] I ask you do to do some long running work, let me know when it is done &lt;/li&gt;    &lt;li&gt;[abstract] I ask you to start doing something, you update me on the status &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;One may ask the question, &amp;quot;But, what about the wsHttpDualBinding, or WCF duplex bindings.&amp;quot;&amp;#160; That's a valid question, but it's important to point out that those bindings are really used to describe the behavior of a given proxy instance (and associated service artifacts).&amp;#160; When my proxy dies, or the underlying connection goes away, I lose the ability for the service to call back to me.&amp;#160; Additionally, this binds me to listen in the same way that I sent out the initial message.&amp;#160; &lt;/p&gt;  &lt;p&gt;By modeling this at the application layer, we do lose some of the &amp;quot;automagicity&amp;quot; of the WCF duplex behavior, but I get more flexibility, and I get the ability to sustain potentially repeated recycling of the services and clients.&amp;#160; Also, you could imagine a service that I call that turns around and calls a third party service.&amp;#160; That third party service could call back directly to the client that made the initial call.&amp;#160; Note, once we start doing duplex communication (and we'll encounter this in part 4, conversations), is that the definition of &amp;quot;client&amp;quot; and &amp;quot;service&amp;quot; become a bit muddier.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So, to the code:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Ingredients:&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;My service workflow, I listen for three different messages (start, add item, complete ), and then I will send the message back to the client: &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo2of4_C68C/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="855" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo2of4_C68C/image_thumb.png" width="450" border="0" /&gt;&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;You'll note that there is a loop so that we can keep adding items until we eventually get the complete order message and we then exit the loop. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;A &amp;quot;client&amp;quot; workflow, which will call this service: &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo2of4_C68C/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="667" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo2of4_C68C/image_thumb_1.png" width="234" border="0" /&gt;&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;You'll note, some of &lt;strong&gt;&lt;em&gt;the magic happens here&lt;/em&gt;&lt;/strong&gt;.&amp;#160; After I start, add and complete the order, you'll see that instead of sending messages, I'll now flip around and wait on the receive in order to receive the shipping cost from the service. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Details&lt;/h4&gt;  &lt;p&gt;The first thing that we need to do in order to enable this duplex messaging to occur is that the &amp;quot;client&amp;quot; workflow has to explicitly provide its context token to the service so that the service can address the appropriate instance of the client workflow.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Note, in the real world, you'll probably need to supply more than just the context token, you will need some address and binding information.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Let's look at the contract of the service:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;[ServiceContract(Namespace =&lt;span class="str"&gt;&amp;quot;http://microsoft.com/dpe/samples/duplex&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt;  IOrderProcessing
{
    [OperationContract()]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; SubmitOrder(&lt;span class="kwrd"&gt;string&lt;/span&gt; customerName, &lt;font color="#ff0000"&gt;IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; context&lt;/font&gt;);

    [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt; )]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; AddItem(OrderItem orderItem);

    [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt; )]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; CompleteOrder();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;You'll note that on the SubmitOrder method, I pass in a context token.&amp;#160; This is my callback correlation identifier, this is how I will figure out what instance on the client side I want to talk to.&amp;#160; Now, I need to do some work to get the context token in order to send, so let's look at how we do this:&lt;/p&gt;

&lt;p&gt;On the client side, on the first Send activity, let's hook the BeforeSend event.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo2of4_C68C/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="292" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo2of4_C68C/image_thumb_2.png" width="278" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Let's look at the implementation of GrabToken:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GrabToken(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, SendActivityEventArgs e)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    ContextToSend = receiveActivity1.Context;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Received token to send along&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; DependencyProperty ContextToSendProperty = DependencyProperty.Register(&lt;span class="str"&gt;&amp;quot;ContextToSend&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(System.Collections.Generic.IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, System.String&amp;gt;), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(OrderSubmitter.Workflow1));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;[BrowsableAttribute(&lt;span class="kwrd"&gt;true&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;[CategoryAttribute(&lt;span class="str"&gt;&amp;quot;Parameters&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; System.Collections.Generic.IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, String&amp;gt; ContextToSend&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    get&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; ((System.Collections.Generic.IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;)(&lt;span class="kwrd"&gt;base&lt;/span&gt;.GetValue(OrderSubmitter.Workflow1.ContextToSendProperty)));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    set&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        &lt;span class="kwrd"&gt;base&lt;/span&gt;.SetValue(OrderSubmitter.Workflow1.ContextToSendProperty, &lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;First, note that on lines 7-22 we declare a dependency property call ContextToSend.&amp;#160; Think of this simply as a bindable storage space.&amp;#160; On line 3, we go and assign to that the value of receiveActivity1.Context.&amp;#160; &amp;quot;But Matt, couldn't I just build a context token off the workflow ID?&amp;quot;&amp;#160; You could, but you're only going to be correct in the &amp;quot;simple scenario.&amp;quot;&amp;#160;&amp;#160; You can see we then take that ContextToSend, and pass that into the context parameter for the service operation. &lt;strong&gt;Always walk up and ask a Receive activity for its context token, don't try to build one on your own.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, on the service side, we need to extract that, and we need to apply the value to the send activity in the service workflow that needs to call back.&amp;#160; We basically can do the reverse:&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; codeActivity1_ExecuteCode(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span class="rem"&gt;//set callback context&lt;/span&gt;
    sendActivity1.Context = callbackContext;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;This is inside a code activity in the first receive activity.&amp;#160; callbackContext is a dependency property that is bound to the inbound context on the Receive activity.&amp;#160; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The final trick is that both workflows have to be hosted inside a WorkflowServiceHost.&amp;#160; This makes sense for the &amp;quot;service&amp;quot; workflow, since it will be message activated.&amp;#160; On the client side, we have to do a little bit of work in order to get to the workflow runtime to spin up a workflow instance.&amp;#160; In the early betas, we had an easy way to get to the runtime, WorkflowServiceHost.WorkflowRuntime.&amp;#160; In order to conform more with the extensibility of WCF, this has been moved to the extensions of the service host.&amp;#160; We get there by:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;using&lt;/span&gt; (WorkflowServiceHost wsh = &lt;span class="kwrd"&gt;new&lt;/span&gt; WorkflowServiceHost(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Workflow1)))&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press &amp;lt;ENTER&amp;gt; to start the workflow&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        Console.ReadLine();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        wsh.Open();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        WorkflowRuntime wr = wsh.Description.Behaviors.Find&amp;lt;WorkflowRuntimeBehavior&amp;gt;().WorkflowRuntime;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        WorkflowInstance wi = wr.CreateWorkflow(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Workflow1));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        AutoResetEvent waitHandle = &lt;span class="kwrd"&gt;new&lt;/span&gt; AutoResetEvent(&lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        wr.WorkflowCompleted += &lt;span class="kwrd"&gt;delegate&lt;/span&gt; { waitHandle.Set(); };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        wr.WorkflowTerminated += &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, WorkflowTerminatedEventArgs e) { Console.WriteLine(&lt;span class="str"&gt;&amp;quot;error {0}&amp;quot;&lt;/span&gt;, e); waitHandle.Set(); };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        wi.Start();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        waitHandle.WaitOne();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Workflow Completed&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        Console.ReadLine();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;On line 3, you'll see we new up a WorkflowServiceHost based on the service type (it will do this to find and open the respective endpoints).&amp;#160; On line 8, we reach in and grab the WorkflowRuntimeBehavior and get the WorkflowRuntime, and we use that to create an instance of the workflow.&amp;#160; &lt;/p&gt;

&lt;p&gt;So, here's what we have done:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Figure out how to grab the context token from a Receive activity &lt;/li&gt;

  &lt;li&gt;Modify the contract to explicitly send the &amp;quot;callback info&amp;quot; to the service &lt;/li&gt;

  &lt;li&gt;On the service side, figure out how to grab that and apply it to a Send activity &lt;/li&gt;

  &lt;li&gt;Finally, on the client side, how to manually kick off workflows, rather than waiting for them to be message activated (the usual path we have is the infrastructure creating the workflow instance).&amp;#160; &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8838441" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/presentations/default.aspx">presentations</category></item><item><title>Advanced Workflow Services Talk (Demo 1 of 4)</title><link>http://blogs.msdn.com/mwinkle/archive/2008/08/05/advanced-workflow-services-talk-demo-1-of-4.aspx</link><pubDate>Tue, 05 Aug 2008 20:44:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8834527</guid><dc:creator>mwinkle</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/8834527.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=8834527</wfw:commentRss><description>&lt;p&gt;So, last week I wrapped up a conversation at TechReady, our internal conference, where I was talking about the integration between WF and WCF in .NET 3.5.&amp;#160; This talk was somewhat bittersweet, it's the last conference where I'm scheduled to talk about WF 3.0/3.5, I'll start talking about WF 4.0 at PDC this fall.&amp;#160; &lt;/p&gt;  &lt;p&gt;There are a series of 4 demos that we'll talk about in this series:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Basic Context Management &lt;/li&gt;    &lt;li&gt;Simple Duplex &lt;/li&gt;    &lt;li&gt;Long Running Work Pattern &lt;/li&gt;    &lt;li&gt;Conversations Pattern &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I've gotten a lot of requests to post the code samples, so I want to do that here:&lt;/p&gt;  &lt;h1&gt;Sample 1, Basic Management of Context&lt;/h1&gt;  &lt;p&gt;The goal of this sample is to show the way that the context channel works, and how to interact with it from imperative code.&lt;/p&gt;  &lt;h3&gt;Ingredients: &lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;One basic workflow service that simply has two Receive activities bound to the same operation inside of a sequence. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo1ofn_AAA5/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="380" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/AdvancedWorkflowServicesTalkDemo1ofn_AAA5/image_thumb.png" width="279" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Inside each Receive, I have placed a Code Activity that simply outputs a little bit of info (the vars declared on lines 1 and 2 are used by the Receive activities: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;div class="csharpcode"&gt;     &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; String returnValue = &lt;span class="kwrd"&gt;default&lt;/span&gt;(System.String);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; String inputMessage = &lt;span class="kwrd"&gt;default&lt;/span&gt;(System.String);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; codeActivity1_ExecuteCode(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;{&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    returnValue = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;first activity {0}&amp;quot;&lt;/span&gt;, inputMessage);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    Output(inputMessage + &lt;span class="str"&gt;&amp;quot; Activity 1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;}&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Output(&lt;span class="kwrd"&gt;string&lt;/span&gt; message)&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;{&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Workflow {0} : Message {1}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;.WorkflowInstanceId, message);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;}&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; codeActivity2_ExecuteCode(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;{&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    returnValue = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;second activity {0}&amp;quot;&lt;/span&gt;, inputMessage);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    Output(inputMessage + &lt;span class="str"&gt;&amp;quot; Activity 2&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;}&lt;/pre&gt;
  &lt;/div&gt;
  &lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Instructions: &lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Create a client type that will call the service for us 
    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; IWorkflowClient : ClientBase&amp;lt;Intro1.IWorkflow1&amp;gt;, Intro1.IWorkflow1
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IWorkflowClient() : &lt;span class="kwrd"&gt;base&lt;/span&gt;() { }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IWorkflowClient(Binding binding, EndpointAddress address) : &lt;span class="kwrd"&gt;base&lt;/span&gt;(binding, address) { }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Hello(&lt;span class="kwrd"&gt;string&lt;/span&gt; message)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.Channel.Hello(message);
    }
}&lt;/pre&gt;
    &lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/li&gt;

  &lt;li&gt;Create a utility function CheckAndPrintContext() 
    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CheckAndPrintContext(IContextManager icm)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != icm) Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Context contains {0} elements&amp;quot;&lt;/span&gt;, icm.GetContext().Count);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != icm)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (icm.GetContext().Count &amp;gt; 0)
        {
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; xmlName &lt;span class="kwrd"&gt;in&lt;/span&gt; icm.GetContext().Keys)
            {
                Console.WriteLine(&lt;span class="str"&gt;&amp;quot;key : {0}&amp;quot;&lt;/span&gt;, xmlName);
                Console.WriteLine(&lt;span class="str"&gt;&amp;quot;value : {0}&amp;quot;&lt;/span&gt;, icm.GetContext()[xmlName]);
            }
        }
    }
}&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;ul&gt;
    &lt;li&gt;The thing to note here is that we need to traverse the dictionary, since there could be more than one key in here, although there won't be in this sample. &lt;/li&gt;
  &lt;/ul&gt;

  &lt;li&gt;Now, let's run the three different bits of code, we want to first show the happy path, show how to break it, and then show how to explicitly manage the context token &lt;/li&gt;

  &lt;li&gt;
    &lt;h4&gt;Scenario 1: The Happy Path&lt;/h4&gt;

    &lt;div class="csharpcode"&gt;
      &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DemoOne()&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press Enter to Send a Message and reuse proxy&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="rem"&gt;// Console.ReadLine();&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    Debugger.Break();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    IWorkflowClient iwc = &lt;span class="kwrd"&gt;new&lt;/span&gt; IWorkflowClient(&lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpContextBinding(),&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(&lt;span class="str"&gt;&amp;quot;net.tcp://localhost:10001/Intro1&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    IContextManager icm = iwc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != icm) Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Context contains {0} elements&amp;quot;&lt;/span&gt;, icm.GetContext().Count);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; s = iwc.Hello(&lt;span class="str"&gt;&amp;quot;message1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;the service returned the message '{0}'&amp;quot;&lt;/span&gt;, s);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    CheckAndPrintContext(icm);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    s = iwc.Hello(&lt;span class="str"&gt;&amp;quot;message2&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    icm = iwc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    CheckAndPrintContext(icm);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;the service returned the message '{0}'&amp;quot;&lt;/span&gt;, s);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press Enter to Continue&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;}&lt;/pre&gt;
    &lt;/div&gt;
    &lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

    &lt;ul&gt;
      &lt;li&gt;What's going on here? 
        &lt;ul&gt;
          &lt;li&gt;Line 5, a more convenient way in demos to hit a breakpoint &lt;/li&gt;

          &lt;li&gt;Line 10: Call the service &lt;/li&gt;

          &lt;li&gt;Line 12: CheckAndPrint the Context Token.&amp;#160; In this case, this will print the Guid of the initiated workflow that is contained in the token &lt;/li&gt;

          &lt;li&gt;Line 13: Call the service a second time 
            &lt;ul&gt;
              &lt;li&gt;Look at the service window, you'll see that this message has been routed to the same instance of the workflow. &lt;/li&gt;

              &lt;li&gt;You can also see in Line 16 that the second activities return message is included. &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;h4&gt;Scenario 2: The Path Grows Darker&lt;/h4&gt;

    &lt;div class="csharpcode"&gt;
      &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;// show this not working using a second client&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DemoTwo()&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press Enter to Send a Message (it will break this time)&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="rem"&gt;//Console.ReadLine();&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    Debugger.Break();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    IWorkflowClient iwc = &lt;span class="kwrd"&gt;new&lt;/span&gt; IWorkflowClient(&lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpContextBinding(),&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(&lt;span class="str"&gt;&amp;quot;net.tcp://localhost:10001/Intro1&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    IContextManager icm = iwc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != icm) Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Context contains {0} elements&amp;quot;&lt;/span&gt;, icm.GetContext().Count);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; s = iwc.Hello(&lt;span class="str"&gt;&amp;quot;message1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;the service returned the message '{0}'&amp;quot;&lt;/span&gt;, s);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    CheckAndPrintContext(icm);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    iwc = &lt;span class="kwrd"&gt;new&lt;/span&gt; IWorkflowClient(&lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpContextBinding(),&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;       &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(&lt;span class="str"&gt;&amp;quot;net.tcp://localhost:10001/Intro1&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    s = iwc.Hello(&lt;span class="str"&gt;&amp;quot;message2&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;the service returned the message '{0}'&amp;quot;&lt;/span&gt;, s);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    icm = iwc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    CheckAndPrintContext(icm);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press Enter to Continue&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;}&lt;/pre&gt;
    &lt;/div&gt;
    &lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

    &lt;ul&gt;
      &lt;li&gt;What's going on here? (Same until line 14) 
        &lt;ul&gt;
          &lt;li&gt;Line 14: Let's create a new proxy.&amp;#160; &lt;/li&gt;

          &lt;li&gt;Line 15: Call the service using the new proxy.&amp;#160; You'll note on the server side that a second workflow instance has been created.&amp;#160; This is where we break. &lt;/li&gt;

          &lt;li&gt;Line 19: On the client side, you'll see that the second GUID being returned &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;h4&gt;Scenario 3: Finding the Light&lt;/h4&gt;

    &lt;div class="csharpcode"&gt;
      &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;// show this working with a second client by caching the context&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DemoThree()&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press Enter to Send a Message (we'll cache the context and apply it to the new proxy)&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="rem"&gt;// Console.ReadLine();&lt;/span&gt;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    Debugger.Break();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    IWorkflowClient iwc = &lt;span class="kwrd"&gt;new&lt;/span&gt; IWorkflowClient(&lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpContextBinding(),&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(&lt;span class="str"&gt;&amp;quot;net.tcp://localhost:10001/Intro1&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    IContextManager icm = iwc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != icm) Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Context contains {0} elements&amp;quot;&lt;/span&gt;, icm.GetContext().Count);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; s = iwc.Hello(&lt;span class="str"&gt;&amp;quot;message1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;the service returned the message '{0}'&amp;quot;&lt;/span&gt;, s);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    CheckAndPrintContext(icm);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &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; context = icm.GetContext();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    icm = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    iwc = &lt;span class="kwrd"&gt;new&lt;/span&gt; IWorkflowClient(&lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpContextBinding(),&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;       &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(&lt;span class="str"&gt;&amp;quot;net.tcp://localhost:10001/Intro1&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    icm = iwc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    icm.SetContext(context);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    s = iwc.Hello(&lt;span class="str"&gt;&amp;quot;message2&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;the service returned the message '{0}'&amp;quot;&lt;/span&gt;, s);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;    icm = iwc.InnerChannel.GetProperty&amp;lt;IContextManager&amp;gt;();&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;    CheckAndPrintContext(icm);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press Enter to Exit&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

      &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;}&lt;/pre&gt;
    &lt;/div&gt;
    &lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

    &lt;ul&gt;
      &lt;li&gt;Line 14 is where the magic happens, here' we grab the context token from the IContextManager.&amp;#160; &lt;/li&gt;

      &lt;li&gt;Line 19 is where the magic completes, we apply this token to the new proxy.&amp;#160; Note, this proxy could be running on different machine somewhere, but one I get the context token, I can use it to communicate with the same workflow instance that the first call did. &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, what have we shown:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Manipulating context in workflow and imperative code 
    &lt;ul&gt;
      &lt;li&gt;How to extract the context token &lt;/li&gt;

      &lt;li&gt;How to explicitly set the context token &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;The caching behavior of the context channel (as seen in Scenario 1) &lt;/li&gt;

  &lt;li&gt;The behavior of the context channel to return the context token only on the activating message &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8834527" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/presentations/default.aspx">presentations</category></item><item><title>Workflows that don't start with a Receive</title><link>http://blogs.msdn.com/mwinkle/archive/2008/01/17/workflows-that-don-t-start-with-a-receive.aspx</link><pubDate>Thu, 17 Jan 2008 22:13:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7143004</guid><dc:creator>mwinkle</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/7143004.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=7143004</wfw:commentRss><description>&lt;p&gt;A question recently came up on an internal list about how to start a workflow to do some work and then have it accept a message via a Receive activity.&amp;#160; This led to an interesting discussion that provides some insight into how the WorkflowServiceHost instantiates workflows in conjunction with the ContextChannel.&lt;/p&gt;  &lt;h2&gt;Creating a Message Activated Workflow&lt;/h2&gt;  &lt;p&gt;By default, the WorkflowServiceHost will create a workflow when the following two conditions are true:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The message received is headed for an operation that is associated with a RecieveActivity that has the CanCreateInstance property set to true&lt;/li&gt;    &lt;li&gt;The message contains no context information&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;It is interesting to note that you don't even need to use a binding element collection that contains a ContextBindingElement.&amp;#160; The ContextBindingElement is responsible for creating the ContextChannel.&amp;#160; The job of the ContextChannel is to do two things on the Receive side&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Extract the context information and pass that along up the stack (hand it off into the service model)&lt;/li&gt;    &lt;li&gt;On the creation, &lt;strong&gt;and only on the creation,&lt;/strong&gt; of a new instance, return the context information to the caller in the header of the response.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So, if we want to create workflows based on messages dropped into an MSMQ queue, we can do that by not trying to add the ContextBindingElement into a custom binding on top of the netMsmqBinding, and associating the operation with a Receive activity with the CanCreateInstance equaling true. Note, that any subsequent communication with the workflow will have to occur with a communication channel over which we can pass context.&lt;/p&gt;  &lt;h2&gt;Creating a Non-Message Activated Workflow&lt;/h2&gt;  &lt;p&gt;In the case that this post is about, we do not want to activate off an inbound message.&amp;#160; The way to do this doesn't require much additional work.&amp;#160; We first need to make sure we don't have any of our Receive activities marked with CanCreateInstance to true.&amp;#160; This means that no message coming in can activate the workflow.&amp;#160; Our workflow will then do some work prior to executing the Receive activity and waiting for the next message.&amp;#160; Our workflow will look like this (pretty simple)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/WorkflowsthatdontstartwithaReceive_9DEA/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="328" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/WorkflowsthatdontstartwithaReceive_9DEA/image_thumb.png" width="224" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;When we want to start a workflow, we need to reach into the workflow service host and extract the workflow runtime and initiate the workflow:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;WorkflowServiceHost myWorkflowServiceHost = &lt;span class="kwrd"&gt;new&lt;/span&gt; WorkflowServiceHost(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Workflow1), &lt;span class="kwrd"&gt;null&lt;/span&gt;);
&lt;span class="rem"&gt;// do some work to set up workflow service host&lt;/span&gt;
myWorkflowServiceHost.Open();
&lt;span class="rem"&gt;// on some reason to start the workflow&lt;/span&gt;
WorkflowRuntime wr = myWorkflowServiceHost.Description.Behaviors.Find&amp;lt;WorkflowRuntimeBehavior&amp;gt;().WorkflowRuntime;
WorkflowInstance wi = wr.CreateWorkflow(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Workflow1));
wi.Start();
// need to send wi.InstanceId somewhere &lt;span class="kwrd"&gt;for&lt;/span&gt; others to communicate with it&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;The last note is important.&amp;#160; In order for a client to eventually be able to communicate to the workflow, the workflow instance Id will need to be relayed to that client.&amp;#160; &lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7143004" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category></item><item><title>VS 2008 RTM's!</title><link>http://blogs.msdn.com/mwinkle/archive/2007/11/19/vs-2008-rtm-s.aspx</link><pubDate>Mon, 19 Nov 2007 21:53:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6406914</guid><dc:creator>mwinkle</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/6406914.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=6406914</wfw:commentRss><description>&lt;p&gt;As widely reported on blogs &lt;a href="http://blogs.msdn.com/somasegar/archive/2007/11/19/visual-studio-2008-and-net-framework-3-5-shipped.aspx"&gt;far&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/pandrew/archive/2007/11/19/visual-studio-2008-and-net-framework-3-5-rtm.aspx"&gt;wide&lt;/a&gt;, Visual Studio 2008 has been released to manufacturing (or shipped, available, ready to get, etc).&amp;#160; MSDN subscribers can do their part to degrade the global bandwidth supply and get in the download queue via the subscription center, trial editions are available &lt;a href="http://msdn2.microsoft.com/en-us/vstudio/products/aa700831.aspx"&gt;here&lt;/a&gt;.&amp;#160; One can also simply get the updated version of the .NET Framework, .NET 3.5 &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&amp;amp;displaylang=en"&gt;here&lt;/a&gt;, and I'd strongly recommend the web setup to only get the bits you need on the machine, and not ones you may already have.&lt;/p&gt;  &lt;p&gt;While you're waiting for those bits to get downloaded, you might find yourself with some free time watching the status bar slowly move in the direction of completion.&amp;#160; Maybe I can interest you in some quality work that has been done by my former team (more on that in the next day or two).&amp;#160; &lt;/p&gt;  &lt;p&gt;First, I would grab the &lt;a href="http://go.microsoft.com/?linkid=7602397"&gt;VS 2008 Training Kit&lt;/a&gt;, which consists of a metric boatload of labs, content, presentations and sample code to get you excited.&amp;#160; This is something my colleague, &lt;a href="http://blogs.msdn.com/daiken/archive/2007/11/19/visual-studio-2008-training-kit-now-available.aspx"&gt;David Aiken&lt;/a&gt;, has been hard at work putting together.&amp;#160; In David's words:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The Visual Studio 2008 and .NET Framework 3.5 Training Kit includes presentations, hands-on labs, and demos. This content is designed to help you learn how to utilize the Visual Studio 2008 features and a variety of framework technologies including: LINQ, C# 3.0, Visual Basic 9, WCF, WF, WPF, ASP.NET AJAX, VSTO, CardSpace, SilverLight, Mobile and Application Lifecycle Management.&lt;/p&gt;    &lt;p&gt;This content was developed over the last few months. As part of the development process, we presented many of the topics to real people we invited to Redmond. In September we recorded these sessions and are making these available on Channel 9. There will be several videos posted each Monday for the next few weeks. Today I posted:&lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;&lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357679"&gt;Lap around Visual Studio 2008 &amp;amp; .NET Framework 3.5&lt;/a&gt; presented by &lt;a href="http://blogs.msdn.com/jamescon"&gt;James Conard&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357685"&gt;What's new in C# 3.0?&lt;/a&gt;&amp;#160; presented by &lt;a href="http://blogs.msdn.com/lukeh"&gt;Luke Hoban&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357687"&gt;What's new in Visual Basic 9.0?&lt;/a&gt; presented by &lt;a href="http://blogs.msdn.com/vbteam"&gt;Amanda Silver&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357691"&gt;.NET Framework 3.5 Enhancements&lt;/a&gt; presented by &lt;a href="http://blogs.msdn.com/jackg"&gt;Jack Gudenkauf&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357683"&gt;.NET Language Integrated Query (LINQ)&lt;/a&gt; presented by &lt;a href="http://blogs.msdn.com/lucabol"&gt;Luca Bolognese&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357689"&gt;Using LINQ with Relational Data&lt;/a&gt;&amp;#160; presented by Mike Pizzo &lt;/li&gt;      &lt;li&gt;&lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357693"&gt;ADO Synchronization Services&lt;/a&gt; presented by Steve Lasker &lt;/li&gt;   &lt;/ul&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The Channel9 videos are especially good, these are all various Microsoft folks from the product teams presenting about their individual area of expertise.&amp;#160; I especially recommend the &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357687"&gt;What's new in VB9&lt;/a&gt; and &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=357683"&gt;intro to LINQ&lt;/a&gt; talk.&amp;#160; There are some pretty cool things in VB9, and I think the XML support is something really cool.&amp;#160; For those of you from the WF world, inside the training kit is a presentation on the WF-WCF integration, as well as a set of labs and demos that walk through simple to complex use cases.&lt;/p&gt;  &lt;p&gt;That should be enough to get you through a few hours of downloading :-)&lt;/p&gt;  &lt;p&gt;Congrats to all the product teams involved in shipping, it's always incredible to me to see how we actually ship software out of this place (and to get to take part in bits and pieces of it).&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6406914" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category></item><item><title>Regarding Re-use of Context-aware Proxies</title><link>http://blogs.msdn.com/mwinkle/archive/2007/11/08/regarding-re-use-of-context-aware-proxies.aspx</link><pubDate>Thu, 08 Nov 2007 10:56:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5980530</guid><dc:creator>mwinkle</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/5980530.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=5980530</wfw:commentRss><description>&lt;p&gt;Yesterday, following my &amp;quot;What's the context for this conversation&amp;quot; presentation, I was approached with the following question:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;I am sharing a singleton client that I want to use to interact with multiple workflow instances, how do I change the context for each of them.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Completely unbeknownst to me, Wenlong, one of the product team's more prolific bloggers, addressed this very topic in his post &lt;a href="http://blogs.msdn.com/wenlong/archive/2007/11/08/how-to-use-a-singleton-wcf-proxy-to-call-different-workflow-service-instances-in-net-3-5.aspx"&gt;here&lt;/a&gt;, conveniently posted yesterday :-) &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5980530" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category></item><item><title>VS 2008 Beta 2 Shipped : 0 to Workflow Service in 60 seconds</title><link>http://blogs.msdn.com/mwinkle/archive/2007/07/30/vs-2008-beta-2-shipped-0-to-workflow-service-in-60-seconds.aspx</link><pubDate>Mon, 30 Jul 2007 23:03:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4135568</guid><dc:creator>mwinkle</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/4135568.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=4135568</wfw:commentRss><description>&lt;p&gt;So, per &lt;a href="http://blogs.msdn.com/somasegar/archive/2007/07/26/announcing-the-release-of-visual-studio-2008-beta-2-net-fx-3-5-beta-2-and-silverlight-1-0-rc.aspx"&gt;Soma's blog&lt;/a&gt;, this &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=329443"&gt;great Channel9 video&lt;/a&gt;, and a bunch of other places, VS 2008 Beta 2 is available for download (&lt;a href="http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx"&gt;go here&lt;/a&gt;).&lt;/p&gt; &lt;p&gt;Others are covering their favorite feature in depth, I want to cover one of mine: the WCF test client, which I will show by way of creating a Workflow Service application.&lt;/p&gt; &lt;p&gt;Real quick, for those of you who didn't read the readme file, I know sometimes you just forget, there is an important note regarding how to get&amp;nbsp; this to work (out of the box you will probably get an exception in svcutil.exe).&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;b&gt;&lt;em&gt;Running a WCF Service Library results in svcutil.exe crashing and the test form not working&lt;/em&gt;&lt;/b&gt; &lt;p&gt;&lt;em&gt;Running a WCF Service Library starts the service in WcfSvcHost and opens a test form to debug operations on the service.&amp;nbsp; On the Beta2 build this results in crash of svcutil.exe and the test form doesn’t work due to a signing problem.&lt;/em&gt; &lt;p&gt;&lt;b&gt;&lt;em&gt;To resolve this issue &lt;/em&gt;&lt;/b&gt; &lt;p&gt;&lt;em&gt;Disable strong name signing for svcutil.exe by opening a Visual Studio 2008 Beta2 Command Prompt. At the command prompt run: &lt;strong&gt;sn –Vr “&amp;lt;program files&amp;gt;\Microsoft SDKs\Windows\v6.0A\Bin\SvcUtil.exe”&lt;/strong&gt;&amp;nbsp; (replace &amp;lt;program files&amp;gt; with your program files path – ex: c:\Program Files)&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Fire up VS 2008, create a new Sequential Workflow Service Library project:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="383" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb.png" width="541" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;This creates a basic Sequential workflow with a Receive activity&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_2.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="240" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_2.png" width="215" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;It also creates an app.config and IWorkflow1.cs&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_3.png" atomicselection="true"&gt;&lt;img height="128" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_3.png" width="240" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;IWorkflow1.cs contains the contract our service is going to implement:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&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.ServiceModel;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; WFServiceLibrary1
{
    &lt;span class="rem"&gt;// NOTE: If you change the interface name "IWorkflow1" here, &lt;/span&gt;
    &lt;span class="rem"&gt;// you must also update the reference to "IWorkflow1" in App.config.&lt;/span&gt;
    [ServiceContract]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IWorkflow1
    {
        [OperationContract]
        &lt;span class="kwrd"&gt;string&lt;/span&gt; Hello(&lt;span class="kwrd"&gt;string&lt;/span&gt; message);
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now, we can modify this as needed, or we can delete it and create the contract as part of the Receive activity, see my previous post &lt;a href="http://blogs.msdn.com/mwinkle/archive/2007/04/27/dynamically-generating-an-operation-contract-in-orcas.aspx"&gt;here&lt;/a&gt; on the topic.&lt;/p&gt;
&lt;p&gt;Return to the workflow and take a quick look at the properties of the Receive activity, and note that the parameters for the method (message and (returnValue)) have already been promoted and bound as properties on the workflow, that saves us a quick step or two:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_4.png" atomicselection="true"&gt;&lt;img height="282" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_4.png" width="355" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Drop a code activity in the Receive shape, and double click to enter some code:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_5.png" atomicselection="true"&gt;&lt;img height="166" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_5.png" width="214" border="0"&gt;&lt;/a&gt; &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; codeActivity1_ExecuteCode(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    returnValue = String.Format(&lt;span class="str"&gt;"You entered '{0}'."&lt;/span&gt;, inputMessage);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now, we're pretty much there, but let's take a quick look at the app.config&lt;/p&gt;&lt;pre class="csharpcode"&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;="WFServiceLibrary1.Workflow1"&lt;/span&gt; &lt;span class="attr"&gt;behaviorConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;="WFServiceLibrary1.Workflow1Behavior"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;host&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;baseAddresses&lt;/span&gt;&lt;span class="kwrd"&gt;&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;baseAddress&lt;/span&gt;&lt;span class="kwrd"&gt;="http://localhost:8080/Workflow1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;baseAddresses&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;host&lt;/span&gt;&lt;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;=""&lt;/span&gt;
            &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;="wsHttpContextBinding"&lt;/span&gt;
            &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;="WFServiceLibrary1.IWorkflow1"&lt;/span&gt; &lt;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;="mex"&lt;/span&gt; 
            &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;="mexHttpBinding"&lt;/span&gt; 
            &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;="IMetadataExchange"&lt;/span&gt; &lt;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;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;We're going to use the wsHttpContextBinding, which you can think of as the standard wsHttpBinding with the addition of the Context channel to the channel stack.&amp;nbsp; Also note, we can right click the config and open it in the WCF config editor, slick!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_6.png" atomicselection="true"&gt;&lt;img height="248" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_6.png" width="308" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Let's hit F5.&amp;nbsp; We build, do a little bit of processing and up pops the WCF test client.&amp;nbsp; You may also note this little pop up from your task tray:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_7.png" atomicselection="true"&gt;&lt;img height="103" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_7.png" width="240" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;What's this, the "autohosting" of your service, just like you get with ASP.NET on a machine.&amp;nbsp; This saves me the trouble of having to write a host as well as my service when I just want to play around a bit.&amp;nbsp; The test client looks like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_8.png" atomicselection="true"&gt;&lt;img height="388" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_8.png" width="590" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Double click on the hello operation and fill in a message to send to the service:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_9.png" atomicselection="true"&gt;&lt;img height="231" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_9.png" width="460" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Clicking "Invoke" will invoke the service, which will soon return with the value we hope to see.&amp;nbsp; Sure enough, after a bit of chugging along, this returns:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_10.png" atomicselection="true"&gt;&lt;img height="227" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/VS2008Beta2Shipped0toWorkflowServicein60_B73F/image_thumb_10.png" width="475" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Finally, let's hit the XML tab to see what's in there, and we see it is the full XML of the request and the response.&amp;nbsp; There's an interesting little tidbit in the header of the response:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;s:Envelope&lt;/span&gt; &lt;span class="attr"&gt;xmlns:s&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/2003/05/soap-envelope"&lt;/span&gt; 
&lt;span class="attr"&gt;xmlns:a&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/2005/08/addressing"&lt;/span&gt; 
&lt;span class="attr"&gt;xmlns:u&lt;/span&gt;&lt;span class="kwrd"&gt;="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;s:Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a:Action&lt;/span&gt; &lt;span class="attr"&gt;s:mustUnderstand&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;u:Id&lt;/span&gt;&lt;span class="kwrd"&gt;="_2"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
       http://tempuri.org/IWorkflow1/HelloResponse
     &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a:Action&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a:RelatesTo&lt;/span&gt; &lt;span class="attr"&gt;u:Id&lt;/span&gt;&lt;span class="kwrd"&gt;="_3"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;urn:uuid:3f5b7eb5-cc35-4b01-b345-92f6edf728d7&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a:RelatesTo&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Context&lt;/span&gt; &lt;span class="attr"&gt;u:Id&lt;/span&gt;&lt;span class="kwrd"&gt;="_4"&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/ws/2006/05/context"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;InstanceId&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;fc0f47fd-dd7b-4030-9883-acbf358583c3&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;InstanceId&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Context&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This is the context token that lets me know how to continue conversing with this workflow.&amp;nbsp; In the test client, I can't find a way to attach it to a subsequent request, meaning we can't use the test client for testing multiple steps through a workflow, but this new feature lets me get up and running, verify connectivity, and be able to set breakpoints and debug my workflow service, which is pretty cool.&lt;/p&gt;
&lt;p&gt;I've posted the following video on &lt;a href="http://channel9.msdn.com/ShowPost.aspx?PostID=330489"&gt;c9 as a screencast&lt;/a&gt;, which I will try to do with my subsequent blog postings.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4135568" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category></item><item><title>Paste XML as Serializable Type</title><link>http://blogs.msdn.com/mwinkle/archive/2007/05/14/paste-xml-as-serializable-type.aspx</link><pubDate>Tue, 15 May 2007 00:45:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2634073</guid><dc:creator>mwinkle</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/2634073.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=2634073</wfw:commentRss><description>&lt;p&gt;Every now and then, there's a really cool feature that's buried somewhere that just hits you and makes you say "Wow, that's insanely helpful, why didn't somebody think of this sooner."&amp;nbsp; &lt;/p&gt; &lt;p&gt;I was playing around with the &lt;a href="http://labs.biztalk.net/"&gt;BizTalk Services SDK&lt;/a&gt;, specifically the different web programming bits and pieces and stumbled up on the Paste As Serializable visual studio add in (navigate to BizTalk Services SDK\Samples\Web\Tooling).&amp;nbsp; &lt;/p&gt; &lt;p&gt;Let's say you're interested in programming against some services that return normal, plain XML. Well, nobody likes writing code to query XML, Linq to XML is fun, but I'd just really like to mess around with some objects and not really deal with how it looks over the wire or under the hood.&lt;/p&gt; &lt;p&gt;This great little utility lets you select some snippet of XML (say I get it from &lt;a href="http://twitter.com/statuses/user_timeline/mwinkle.xml"&gt;here&lt;/a&gt;, because I am working on a Twitter mashup).&amp;nbsp; Copy the XML to the clipboard (here's a snippet of what the XML looks like).&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;statuses&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;status&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;created_at&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Wed May 02 16:54:45 +0000 2007&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;created_at&lt;/span&gt;&lt;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;47434042&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;text&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;has advil &lt;span class="attr"&gt;&amp;amp;amp;&lt;/span&gt; beineigts in the back of Steve and Don's talk in 4101B.  Anybody needing either is welcome to some, the pastries will go fast.&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;text&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;user&lt;/span&gt;&lt;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;5440022&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;name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Matt Winkler&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;screen_name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;mwinkle&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;screen_name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;location&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Seattle&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;location&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;workflow technical evangelist&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;profile_image_url&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;http://assets2.twitter.com/system/user/profile_image/5440022/normal/Matt_Winkler-72dpi.jpg?1177350091&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;profile_image_url&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;url&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;http://blogs.msdn.com/mwinkle&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;url&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;protected&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;false&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;protected&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;user&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;status&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Go into Visual Studio into a code file and open up the edit menu.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/PasteXMLasSerializableType_CF68/image.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="440" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/PasteXMLasSerializableType_CF68/image_thumb.png" width="250" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;There, clearly indicated by the "this is just an alpha icon," is the option to "Paste XML as Serializable Type".&amp;nbsp; Here's what it outputs:&lt;/p&gt;&lt;pre class="csharpcode"&gt;   [System.Xml.Serialization.XmlRootAttribute(Namespace = &lt;span class="str"&gt;""&lt;/span&gt;, ElementName = &lt;span class="str"&gt;"statuses"&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; StatusesClass
    {

        &lt;span class="kwrd"&gt;private&lt;/span&gt; System.Collections.Generic.List&amp;lt;StatusClass&amp;gt; statusField;

        [System.Xml.Serialization.XmlElementAttribute(Namespace = &lt;span class="str"&gt;""&lt;/span&gt;, ElementName = &lt;span class="str"&gt;"status"&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; System.Collections.Generic.List&amp;lt;StatusClass&amp;gt; Status
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.statusField;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.statusField = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [System.Xml.Serialization.XmlRootAttribute(Namespace = &lt;span class="str"&gt;""&lt;/span&gt;, ElementName = &lt;span class="str"&gt;"status"&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; StatusClass
        {

            &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; created_atField;
            &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; idField;
            &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; textField;
            &lt;span class="kwrd"&gt;private&lt;/span&gt; UserClass userField;
            [System.Xml.Serialization.XmlElementAttribute(Namespace = &lt;span class="str"&gt;""&lt;/span&gt;, ElementName = &lt;span class="str"&gt;"created_at"&lt;/span&gt;)]
            &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Created_at
            {
                get
                {
                    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.created_atField;
                }
                set
                {
                    &lt;span class="kwrd"&gt;this&lt;/span&gt;.created_atField = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
                }
            }
&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Remainder of code truncated for the sake of the readers.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;This lets me do some cool stuff like this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
{
    WebHttpClient twc = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebHttpClient();
    twc.UriTemplate = &lt;span class="str"&gt;"http://twitter.com/statuses/user_timeline/mwinkle.xml"&lt;/span&gt;;
    StatusesClass sc = twc.Get().GetBody&amp;lt;StatusesClass&amp;gt;();
    Console.WriteLine(&lt;span class="str"&gt;"Got {0}"&lt;/span&gt;, sc.Status.Count);
    
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;And get my result back in a nice typed object that I can then use elsewhere in my code (or at least debug)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/PasteXMLasSerializableType_CF68/image_1.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="372" alt="image" src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/PasteXMLasSerializableType_CF68/image_thumb_1.png" width="804" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://hyperthink.net/blog/"&gt;Steve&lt;/a&gt;, thanks, this thing rocks!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2634073" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category></item><item><title>Orcas Beta 1 Samples (WF, WCF)</title><link>http://blogs.msdn.com/mwinkle/archive/2007/04/27/orcas-beta-1-samples-wf-wcf.aspx</link><pubDate>Fri, 27 Apr 2007 22:17:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2302344</guid><dc:creator>mwinkle</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/2302344.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=2302344</wfw:commentRss><description>&lt;p&gt;Beta 1 samples have been posted.&amp;nbsp; In this release there are separate installs for WF and WCF (and the workflow services are in the WCF one, go figure!)&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms752239(VS.90).aspx"&gt;WCF (and WF Services) Samples&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms742187(VS.90).aspx"&gt;WF Samples&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;From Laurence's &lt;a href="http://blogs.msdn.com/melloula/archive/2007/04/24/wcf-and-wf-samples-for-orcas-beta1-are-available-on-msdn.aspx"&gt;blog&lt;/a&gt;:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;This is the only version of the new samples that works at this time.&amp;nbsp;The version that comes&amp;nbsp;with the VS Orcas Beta1 offline Help does not work.&lt;/em&gt;  &lt;p&gt;&lt;em&gt;New samples in this release:&lt;/em&gt;  &lt;p&gt;&lt;em&gt;WF Samples\Technologies\Rules And Conditions\Order Processing Policy&lt;/em&gt;  &lt;p&gt;&lt;em&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;WCF Technology Samples\Basic\Ajax&lt;/em&gt;  &lt;p&gt;&lt;em&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;WCF Technology Samples\Basic\Syndication&lt;/em&gt;  &lt;p&gt;&lt;em&gt;WCF Technology Samples\Basic\WorkflowServices&lt;/em&gt;  &lt;p&gt;&lt;em&gt;You can download the zip files through any of the samples. &lt;/em&gt; &lt;p&gt;&lt;em&gt;To setup and run the Orcas Beta1 samples:&lt;/em&gt;  &lt;p&gt;&lt;em&gt;1. Setup:&lt;/em&gt;  &lt;p&gt;&lt;em&gt;a. Check out the &lt;/em&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb410779(VS.90).aspx"&gt;&lt;em&gt;Setup Instructions for the Ajax, Syndication, and Workflow Services samples&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;  &lt;p&gt;&lt;em&gt;i. Use the Setup scripts under the “OrcasSetup” dir in the downloaded WCF zip file. In contrast, the “Setup” dir includes the scripts necessary for the samples already released with WCF 3.0&lt;/em&gt;  &lt;p&gt;&lt;em&gt;b. On Win2K3, if you see a plain text page when connecting to &lt;/em&gt;&lt;a href="http://localhost/NetFx35Samples/service.svc"&gt;&lt;em&gt;http://localhost/NetFx35Samples/service.svc&lt;/em&gt;&lt;/a&gt;&lt;em&gt;, you need to run:&lt;/em&gt;  &lt;p&gt;&lt;em&gt;“%SystemDrive%\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe” -i –enable&lt;/em&gt;  &lt;p&gt;&lt;em&gt;"%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -i&lt;/em&gt;  &lt;p&gt;&lt;em&gt;c. The WCF Samples setup script Setupvroot.bat will not run unless MSMQ is installed or the NetMsmqActivator service is disabled&lt;/em&gt;  &lt;p&gt;&lt;em&gt;2. Ajax samples:&lt;/em&gt;  &lt;p&gt;&lt;em&gt;a. For the Simple and Post Ajax service samples, you will need to completely refresh your session to be able to reload ClientPage.htm from one service to another as there is an issue with IE. Or simply rename ClientPage.htm in one of the samples&lt;/em&gt;  &lt;p&gt;&lt;em&gt;3. &amp;nbsp;Workflow Services:&lt;/em&gt;  &lt;p&gt;&lt;em&gt;a. WorkflowServiceUtility is a&amp;nbsp;reference necessary to the CalculatorClient and DuplexWorkflowServices samples&lt;/em&gt;  &lt;p&gt;&lt;em&gt;b. CalculatorClient is the client for both DurableService and StateMachineWorkflowService. Click on “C” to stop the session (it becomes red) before switching services&lt;/em&gt;  &lt;p&gt;&lt;em&gt;c. The Conversations client is the window that has “Press enter to submit order”&lt;/em&gt;  &lt;p&gt;&lt;em&gt;d. In DuplexWorkflowServices, only the ServiceHost and ClientHost projects need to be started&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:8acbbcef-f9f9-4a51-86a1-250b99a7368c" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/orcas" rel="tag"&gt;orcas&lt;/a&gt;, &lt;a href="http://technorati.com/tags/wf" rel="tag"&gt;wf&lt;/a&gt;, &lt;a href="http://technorati.com/tags/wcf" rel="tag"&gt;wcf&lt;/a&gt;, &lt;a href="http://technorati.com/tags/samples" rel="tag"&gt;samples&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2302344" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category></item><item><title>Dynamically Generating an Operation Contract in Orcas using WF</title><link>http://blogs.msdn.com/mwinkle/archive/2007/04/27/dynamically-generating-an-operation-contract-in-orcas.aspx</link><pubDate>Fri, 27 Apr 2007 19:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2300995</guid><dc:creator>mwinkle</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/2300995.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=2300995</wfw:commentRss><description>&lt;p&gt;This kicks off a set of posts where I'll be discussing some of the interesting features coming out in Orcas.&lt;/p&gt; &lt;p&gt;I want to focus on this post on the Receive Activity, and a nice little feature in the designer that lets you create a contract on the fly, without having to drop into code and write a decorated interface.&amp;nbsp; This allows us to divide the world into two approaches:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;One where I design my contract first, and then start creating a workflow to implement the operations on the contract.&lt;/li&gt; &lt;li&gt;Design my workflow first, and have&amp;nbsp;it figure out the contract for me (this is what I will focus on in more detail)&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Designing a Contract First&lt;/h2&gt; &lt;p&gt;This is what most WCF folks will be familiar with:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[ServiceContract]&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IOrderProcessing&lt;br&gt;{&lt;br&gt;&lt;br&gt;    [OperationContract]&lt;br&gt;    &lt;span class="kwrd"&gt;bool&lt;/span&gt; SubmitOrder(Order order);&lt;br&gt;&lt;br&gt;    [OperationContract]&lt;br&gt;    Order[] GetOrders(&lt;span class="kwrd"&gt;int&lt;/span&gt; customerId);&lt;br&gt;}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;When I drop a receive activity onto a workflow, I can now import this contract:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog1%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog1%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog1_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog1_thumb%5B1%5D.jpg" height="351" width="347"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;This will bring up a type chooser that lets me pick my service contract:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog2%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog2%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog2_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog2_thumb%5B1%5D.jpg" height="390" width="513"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;This imports all of the details and we can see the the operation picker&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog3%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog3%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog3_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog3_thumb%5B1%5D.jpg" height="392" width="397"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;If we look at the activity properties we now see the parameters to the method.&amp;nbsp; The (ReturnValue) is the object that we need to return in the operation.&amp;nbsp; The order parameter is the message that is going to be passed when the method is called.&amp;nbsp; I can take that and bind that to values in my workflow or whatever I want to do with it.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog4%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog4%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog4_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog4_thumb%5B1%5D.jpg" height="270" width="425"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Designing a Workflow First&lt;/h2&gt;
&lt;p&gt;The other approach we can take is to create the contract as we create the workflow.&amp;nbsp; That's right, we don't need to create the contract explicitly in code.&amp;nbsp; To do that, drop a receive activity onto the designer and double click.&amp;nbsp; Instead of selecting "Import Contract" select "Add Contract".&amp;nbsp; This will create a new contract with a basic operation.&amp;nbsp; By selecting the contract or the operation we can name it something a little nicer.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog5%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog5%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog5_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog5_thumb%5B1%5D.jpg" height="435" width="424"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;By selecting the operation, I can customize all of its behavior.&amp;nbsp; I can create parameters to be passed in, I can set the types of those parameters (as well as the return type of the operation).&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog6%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog6%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog6_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog6_thumb%5B1%5D.jpg" height="405" width="505"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;It's relevent to point out that I can select any type that would be valid in a WCF contract.&amp;nbsp; The drop down list displays the basic types, but by selecting "Browse Type" I am brought into a type picker where I can select custom types.&amp;nbsp; As you can see below I have created a "CancelOrder" operation that takes in an order, the reason and who authorized the cancellation.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog7%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog7%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog7_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog7_thumb%5B1%5D.jpg" height="260" width="512"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;When I click ok, my activity has had new dependency properties added to it, as can be seen in the property grid for the activity.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog8%5B3%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog8%5B3%5D.jpg" atomicselection="true"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog8_thumb%5B1%5D.jpg" mce_src="http://blogs.msdn.com/blogfiles/mwinkle/WindowsLiveWriter/DynamicallyGeneratinganOperationContract_88F3/blog8_thumb%5B1%5D.jpg" height="324" width="445"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;So what's happening here?&lt;/h2&gt;
&lt;p&gt;In the workflow I created, I used a code separation workflow, so I have an&amp;nbsp;.xoml file which contains the workflow definition.&amp;nbsp; Let's take a quick peek at how the receive activity is defined (note, some of the xml is truncated, if you view in an rss reader or copy and past you can see all the details, I'll work on updating the blog layout):&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:ReceiveActivity&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="receiveActivity2"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:ReceiveActivity.ServiceOperationInfo&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationInfo&lt;/span&gt; &lt;span class="attr"&gt;PrincipalPermissionRole&lt;/span&gt;&lt;span class="kwrd"&gt;="administrators"&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CancelOrder"&lt;/span&gt; &lt;span class="attr"&gt;ContractName&lt;/span&gt;&lt;span class="kwrd"&gt;="MyContract"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationInfo.Parameters&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationParameterInfo&lt;/span&gt; &lt;span class="attr"&gt;Attributes&lt;/span&gt;&lt;span class="kwrd"&gt;="Out, Retval"&lt;/span&gt; &lt;span class="attr"&gt;ParameterType&lt;/span&gt;&lt;span class="kwrd"&gt;="{x:Type p9:Boolean}"&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="(ReturnValue)"&lt;/span&gt; &lt;span class="attr"&gt;Position&lt;/span&gt;&lt;span class="kwrd"&gt;="-1"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:p9&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationParameterInfo&lt;/span&gt; &lt;span class="attr"&gt;Attributes&lt;/span&gt;&lt;span class="kwrd"&gt;="In"&lt;/span&gt; &lt;span class="attr"&gt;ParameterType&lt;/span&gt;&lt;span class="kwrd"&gt;="{x:Type p9:Order}"&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="order"&lt;/span&gt; &lt;span class="attr"&gt;Position&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:p9&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:WcfServiceLibrary1;Assembly=WcfServiceLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationParameterInfo&lt;/span&gt; &lt;span class="attr"&gt;Attributes&lt;/span&gt;&lt;span class="kwrd"&gt;="In"&lt;/span&gt; &lt;span class="attr"&gt;ParameterType&lt;/span&gt;&lt;span class="kwrd"&gt;="{x:Type p9:String}"&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="reason"&lt;/span&gt; &lt;span class="attr"&gt;Position&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:p9&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationParameterInfo&lt;/span&gt; &lt;span class="attr"&gt;Attributes&lt;/span&gt;&lt;span class="kwrd"&gt;="In"&lt;/span&gt; &lt;span class="attr"&gt;ParameterType&lt;/span&gt;&lt;span class="kwrd"&gt;="{x:Type p9:String}"&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="authorizedBy"&lt;/span&gt; &lt;span class="attr"&gt;Position&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:p9&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationInfo.Parameters&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ns0:OperationInfo&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ns0:ReceiveActivity.ServiceOperationInfo&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ns0:ReceiveActivity&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Here you can see that within the metadata of the activity, we have the definition for the contract and the operation that I defined.&amp;nbsp; When we spin up a WorkflowServiceHost to host this workflow as a service, the host will inspect the metadata for the workflow, looking for all of the endpoints and will create them.&amp;nbsp; You can also see within the OperationInfo element that I am able to define the PrincipalPermissionRole defining the role of allowed callers, taking advantage of the static security checks which I will talk about in another post.&amp;nbsp; So, defined declaratively in the XAML is the contract for the operations.&amp;nbsp; I didn't need to write the interface or the contract explicitly, I was able to write a workflow, specifiy in the workflow how it will communicate and then let the WorkflowServiceHost figure out the nitty gritty details of how create the endpoints.&amp;nbsp; The other part here that is important to mention is that the config will play a part determining what the transport channel and other such details will be.&amp;nbsp; Within the config, when we set up an endpoint we need to specify the contract is "MyContract", or the name that we assigned when we created it.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;We talked about the way that we can implement contracts that already exist in a receive activity, as well as how we can use the designer to actually create our contract while we are designing the workflow.&amp;nbsp; The WorkflowServiceHost does the heavy lifting here in order to enable this little bit of nifty-ness. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2300995" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/activities/default.aspx">activities</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category></item><item><title>WCF and WF in "Orcas"</title><link>http://blogs.msdn.com/mwinkle/archive/2007/02/28/wcf-and-wf-in-quot-orcas-quot.aspx</link><pubDate>Thu, 01 Mar 2007 01:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1776107</guid><dc:creator>mwinkle</dc:creator><slash:comments>15</slash:comments><comments>http://blogs.msdn.com/mwinkle/comments/1776107.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwinkle/commentrss.aspx?PostID=1776107</wfw:commentRss><description>&lt;P&gt;The wheels of evangelism never stop rolling.&amp;nbsp; Just a few months ago I was blogging that .NET 3.0 was released.&amp;nbsp; I've been busy since then, and now I can talk about some of that.&amp;nbsp; Today, the March CTP of Visual Studio "Orcas" was released to the web.&amp;nbsp; You can get your fresh hot bits &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=B533619A-0008-4DD6-9ED1-47D482683C78&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=B533619A-0008-4DD6-9ED1-47D482683C78&amp;amp;displaylang=en"&gt;here&lt;/A&gt;.&amp;nbsp; Samples will be coming shortly. Thom has a high level summary &lt;A href="http://blogs.msdn.com/trobbins/archive/2007/02/28/microsoft-pre-release-software-visual-studio-code-name-orcas-march-2007-community-technology-preview-ctp.aspx" mce_href="http://blogs.msdn.com/trobbins/archive/2007/02/28/microsoft-pre-release-software-visual-studio-code-name-orcas-march-2007-community-technology-preview-ctp.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;UPDATE: Wendesday, 2/28/2007 @ 11pm.&amp;nbsp; The readme file is posted &lt;A href="http://download.microsoft.com/download/2/0/d/20d107fd-4719-4236-8e5b-ef6bfdb69c81/OrcasMarchCTP_ReadMe.htm" mce_href="http://download.microsoft.com/download/2/0/d/20d107fd-4719-4236-8e5b-ef6bfdb69c81/OrcasMarchCTP_ReadMe.htm"&gt;here&lt;/A&gt;, a few minor corrections have been made to the caveats below.&lt;/P&gt;
&lt;P&gt;More updates... corrections to another caveat (a post-build event is required to get the config to be read).&lt;/P&gt;
&lt;H3&gt;A Couple of Minor Caveats&lt;/H3&gt;
&lt;P&gt;Since this is a CTP, it's&amp;nbsp;possible that sometimes the wrong bits end up in the right place at the wrong time.&amp;nbsp;Here are a few things to be aware of (not intended to be a comprehensive list):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Declarative Rules in Workflows:&amp;nbsp; There is an issue right now where the .rules file does not get hooked into the build process correctly. 
&lt;UL&gt;
&lt;LI&gt;Solution: Use code conditions, or load declarative rules for policy activiites using the &lt;A href="http://wf.netfx3.com/files/folders/rules_samples/entry8850.aspx" mce_href="http://wf.netfx3.com/files/folders/rules_samples/entry8850.aspx"&gt;RulesFromFile activity&lt;/A&gt;&amp;nbsp;available at the community site&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;WF Project templates are set to target the wrong version: As a result, trying to add assemblies that are 3.0.0.0 or greater will not be allowed. 
&lt;UL&gt;
&lt;LI&gt;Solution: Right click the project, select properties, and change the targeted version of the framework to 3.0.0.0 or 3.5.0.0&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;A ServiceHost may not read config settings because the app config does not get copied to the bin (update: only on server 2003):&amp;nbsp; You will get an exception that "no application endpoints can be found" &lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Add the following Post Build Event "copy “$(ProjectDir)\app.config” $(TargetName).config " 
&lt;LI&gt;&lt;STRIKE&gt;Solution: For the time being, configure the WorkflowServiceHost in code (using AddServiceEndpoint() and referencing the WorkflowRuntime property to configure any services on the workflow runtime &lt;/STRIKE&gt;
&lt;LI&gt;&lt;STRIKE&gt;This also means that a number of the workflow enabled services samples will not work out of the box.&amp;nbsp; Replace the config based approach with the code based approach and you will be fine.&amp;nbsp; I will try to post modified versions of these to the community site shortly.&lt;/STRIKE&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;STRIKE&gt;Workflow&lt;/STRIKE&gt;ServiceHost exception on closing: You will get an exception that "&lt;STRIKE&gt;Application image file could not be loaded... &lt;/STRIKE&gt;System.BadImageFormatException: &amp;nbsp;An attempt was made to load the program with an incorrect format" 
&lt;UL&gt;
&lt;LI&gt;Solution: Use the typical "These are not the exceptions you are looking for" jedi mind trick.&amp;nbsp; Catch the exception and move along in your application, as if there is nothing to see here.&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Tools from the Windows SDK that you've come to know and love, like SvcConfigEditor and SvcTraceViewer are not available on the VPC.&amp;nbsp; 
&lt;UL&gt;
&lt;LI&gt;Solution: Copy these in from somewhere else and they will work fine. The SvcConfigEditor will even pick up the new bindings and behaviors to configure the services for some of the new functionality.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The CTP is not something that is designed for you to go into production with, it's designed to let you explore the technology.&amp;nbsp;There is no go-live license associated with this, it's for you to learn more about the technology.&amp;nbsp;Since most of these issues have some work around, this shouldn't prevent you from checking these things out (because they are some kind of neat).&lt;/P&gt;
&lt;H3&gt;New Features In WF and WCF in "Orcas"&lt;/H3&gt;
&lt;H4&gt;Workflow Enabled Services&lt;/H4&gt;
&lt;P&gt;We've been talking about this since we launched at PDC 2005.&amp;nbsp; There was a session at TechEd 2006 in the US and Beijing that mentioned bits and pieces of this.&amp;nbsp; One of the key focus areas is the unification of WCF and WF.&amp;nbsp; Not only have the product teams joined internally, the two technologies are very&amp;nbsp;complementary.&amp;nbsp; So complementary that everyone usually asks "so how do I use WCF services here?" when I show a workflow demo.&amp;nbsp; That's fixed now!&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Workflow enabled services allow two key things:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Easily consume WCF services inside of a workflow 
&lt;LI&gt;Expose a workflow as a WCF service&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;This is accomplished by the following additions built on top of v1:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Messaging Activities (Send and Receive) 
&lt;UL&gt;
&lt;LI&gt;With designer support to import or create contracts&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;WorkflowServiceHost, a derivation of ServiceHost 
&lt;LI&gt;Behavior extensions that handles message routing and instantiation of workflows exposed via services. 
&lt;LI&gt;Channel extensions for managing conversation context.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;The Send and Receive activites live inside of the workflow that we define.&amp;nbsp; The cool part of the Receive activity is that we have a contract designer, so you don't have to dive in and create an interface for the contract, you can just specifiy it right on the Receive activity, allowing you a "workflow-first" approach to building services.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Once we've built a workflow, we need a place to expose it as a service.&amp;nbsp; We use the WorkflowServiceHost which is a subclass of ServiceHost in order to host these workflow enabled services.&amp;nbsp; The WorkflowServiceHost takes care of the nitty-gritty details of managine workflow instances, routing incoming messages to the appropriate workflow and performing security checks as well.&amp;nbsp; This means that the code required to host a workflow as a WCF service is now reduced to four lines of code or so.&amp;nbsp; In the sample below, we are not setting the endpoint info in code due to the issue mentioned above.&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;WorkflowServiceHost wsh = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; WorkflowServiceHost(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(MyWorkflow));&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;wsh.Open();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;Console.WriteLine(&lt;SPAN class=str&gt;"Press &amp;lt;Enter&amp;gt; to Exit"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;Console.ReadLine();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;wsh.Close();&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;To support some of the more sophisticated behavior, such as routing messages to a running workflow, we introduce a new channel extension responsible for managing context.&amp;nbsp; In the simple case, this context just contains the workflowId, but in a more complicated case, it can contain information similar to the correlation token in v1 that allows the message to be delivered to the right activity (think three receives in parallel, all listing on the same operation).&amp;nbsp; Out of the box there is the wsHttpContextBinding and the netTcpContextBinding which implicitly support the idea of maintaining this context token.&amp;nbsp; You can also roll your own binding and attach a Context element into the binding definition.&lt;/P&gt;
&lt;P&gt;The Send activity allows the consumption of a service, and relies on configuraiton to detemrine exactly how we will call that service.&amp;nbsp; If the service we are calling is another workflow, the Send activity and the Receive activity are aware of the context extensions and will take advantage of them.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;With the Send and Receive actiivty, it gets a lot easier to do workflow to workflow communicaiton, as well as more complicated messaging patterns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another nice feature of the work that was done to enable this is that we know have the ability to easily support durable services.&amp;nbsp; These are "normal" WCF services written in code that utilize an infrastructure similar to the workflow persistence store in order to provide a durable storing of state between method calls.&lt;/P&gt;
&lt;P&gt;As you can imagine, I'll be blogging about this a lot more in the future.&lt;/P&gt;
&lt;H4&gt;JSON / AJAX Support&lt;/H4&gt;
&lt;P&gt;While there has been a lot of focus on the UI side of AJAX, there still remains the task of creating the sources for the UI to consume.&amp;nbsp; One can return POX (Plain Old Xml) and then manipulate it in the javascript, but that can get messy.&amp;nbsp; JavaScript Object Notation (JSON) is a compact, text-based serialization of a JavaScript object.&amp;nbsp; This lets me do something like:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; stuff = {&lt;SPAN class=str&gt;"foo"&lt;/SPAN&gt; : 78, &lt;SPAN class=str&gt;"bar"&lt;/SPAN&gt; : &lt;SPAN class=str&gt;"Forty-two"&lt;/SPAN&gt;};
document.write(&lt;SPAN class=str&gt;"The meaning of life is "&lt;/SPAN&gt; + stuff.bar);&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;In WCF, we can now return JSON with a few switches of config.&amp;nbsp; The following config:&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="CustomerService"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ICustomers"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;      &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;      &lt;SPAN class=attr&gt;bindingConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="jsonBinding"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;      &lt;SPAN class=attr&gt;address&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt; &lt;SPAN class=attr&gt;behaviorConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="jsonBehavior"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;webHttpBinding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;binding&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="jsonBinding"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;messageEncoding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Json"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;webHttpBinding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  11:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  12:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  13:  &lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  14:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;="jsonBehavior"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  15:  &lt;/SPAN&gt;          &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;webScriptEnable&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  16:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  17:  &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;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  18:  &lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;will allow a function like this:&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; Customer[] GetCustomers(SearchCriteria criteria)&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;   &lt;SPAN class=rem&gt;// do some work here&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; customerListing;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;to return JSON when called.&amp;nbsp; In JavaScript, I would then have an instance of a CustomerOrder object to manipulate.&amp;nbsp; We can also serialize from JavaScript to JSON so this provides a nice way to send parameters to a method.&amp;nbsp;&amp;nbsp; So, in the above method, we can send in the complex object SearchCriteria from our JavaScript. &amp;nbsp;There is an extension to the behavior that creates a JavaScript proxy.&amp;nbsp; So, by referencing /js as the source of the script, you can get IntelliSense in the IDE, and we can call our services directly from our AJAX UI.&lt;/P&gt;
&lt;P&gt;We can also use the JSON support in other languages like Ruby to quickly call our service and manipulate the object that is returned.&lt;/P&gt;
&lt;P&gt;I think that's pretty cool.&lt;/P&gt;
&lt;H4&gt;Syndication Support&lt;/H4&gt;
&lt;P&gt;While we have the &lt;A href="http://wcf.netfx3.com/files/folders/encoders/entry3262.aspx" mce_href="http://wcf.netfx3.com/files/folders/encoders/entry3262.aspx"&gt;RSS Toolkit in V1&lt;/A&gt;, we wanted to make syndication part of the toolset out of the box.&amp;nbsp; This allows a developer to quickly return a feed from a service.&amp;nbsp; Think of using this as another way to expose your data for consumption.&amp;nbsp; We have introduced a SyndicationFeed object that is an abstraction of the idea of a feed that you program against.&amp;nbsp; We then leave it up to config to determine if that is an ATOM or RSS feed (and, would it be WCF if we didn't give you a way to implement a custom encoding as well?)&amp;nbsp; So this is cool if you just want to create a simple feed, but it also allows you to create a more complicated feed that has content that is not just plain text.&amp;nbsp; For instance, the &lt;A href="http://www.digg.com/" mce_href="http://www.digg.com/"&gt;digg&lt;/A&gt; feed has information about the submission, the &lt;A href="http://www.flickr.com/" mce_href="http://www.flickr.com/"&gt;flickr&lt;/A&gt; feed has info about the photos.&amp;nbsp; Your customer feed may want to have an extension that contains the customer info that you will allow your consumers to have access to.&amp;nbsp; The SyndicationFeed object allows you to create these extensions and then the work of encoding it to the specific format is taken care of for you.&amp;nbsp; So, let's seem some of that code (note, this is from the samples above):&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; SyndicationFeed GetProcesses()&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;    Process[] processes = Process.GetProcesses();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;    &lt;SPAN class=rem&gt;//SyndicationFeed also has convenience constructors&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;    &lt;SPAN class=rem&gt;//that take in common elements like Title and Content.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;    SyndicationFeed f = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SyndicationFeed();            &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;    &lt;SPAN class=rem&gt;//Create a title for the feed&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;    f.Title = SyndicationContent.CreatePlaintextTextSyndicationContent(&lt;SPAN class=str&gt;"Currently running processes"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  11:  &lt;/SPAN&gt;    f.Links.Add(SyndicationLink.CreateSelfLink(OperationContext.Current.IncomingMessageHeaders.To));&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  12:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  13:  &lt;/SPAN&gt;    &lt;SPAN class=rem&gt;//Create a new RSS/Atom item for each running process&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  14:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;foreach&lt;/SPAN&gt; (Process p &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; processes)&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  15:  &lt;/SPAN&gt;    {&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  16:  &lt;/SPAN&gt;        &lt;SPAN class=rem&gt;//SyndicationItem also has convenience constructors&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  17:  &lt;/SPAN&gt;        &lt;SPAN class=rem&gt;//that take in common elements such as Title and Content&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  18:  &lt;/SPAN&gt;        SyndicationItem i = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SyndicationItem();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  19:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  20:  &lt;/SPAN&gt;        &lt;SPAN class=rem&gt;//Add an item title.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  21:  &lt;/SPAN&gt;        i.Title = SyndicationContent.CreatePlaintextTextSyndicationContent(p.ProcessName);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  22:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  23:  &lt;/SPAN&gt;        &lt;SPAN class=rem&gt;//Add some HTML content in the summary&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  24:  &lt;/SPAN&gt;        i.Summary = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; TextSyndicationContent(String.Format(&lt;SPAN class=str&gt;"&amp;lt;b&amp;gt;{0}&amp;lt;/b&amp;gt;"&lt;/SPAN&gt;, p.MainWindowTitle), TextSyndicationContentKind.Html);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  25:  &lt;/SPAN&gt;        &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  26:  &lt;/SPAN&gt;        &lt;SPAN class=rem&gt;//Add some machine-readable XML in the item content.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  27:  &lt;/SPAN&gt;        i.Content = SyndicationContent.CreateXmlSyndicationContent(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ProcessData(p));&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  28:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  29:  &lt;/SPAN&gt;        f.Items.Add(i);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  30:  &lt;/SPAN&gt;    }&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  31:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  32:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; f;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  33:  &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;And the config associated with this would be:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &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;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ProcessInfo"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;       &lt;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;="rss"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;           &lt;SPAN class=attr&gt;behaviorConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="rssBehavior"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;           &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="HelloSyndication.IDiagnosticsService"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;address&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="atom"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;           &lt;SPAN class=attr&gt;behaviorConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="atomBehavior"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;           &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="HelloSyndication.IDiagnosticsService"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;    &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  11:  &lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  12:  &lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  13:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  14:  &lt;/SPAN&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="rssBehavior"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  15:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;syndication&lt;/SPAN&gt; &lt;SPAN class=attr&gt;version&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Rss20"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  16:  &lt;/SPAN&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  17:  &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;="atomBehavior"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  18:  &lt;/SPAN&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;syndication&lt;/SPAN&gt; &lt;SPAN class=attr&gt;version&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Atom10"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  19:  &lt;/SPAN&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  20:  &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;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  21:  &lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;  &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  22:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;This config will actually create an RSS and an ATOM endpoint.&amp;nbsp; The feed returned would have the process information embedded as: (in this case in ATOM)&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;entry&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;fe1f1d2e-d676-417d-85bf-b7969dd07661&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;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;devenv&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;summary&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="html"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=attr&gt;&amp;amp;lt;&lt;/SPAN&gt;b&lt;SPAN class=attr&gt;&amp;amp;gt;&lt;/SPAN&gt;Conversations - Microsoft Visual Studio&lt;SPAN class=attr&gt;&amp;amp;lt;&lt;/SPAN&gt;/b&lt;SPAN class=attr&gt;&amp;amp;gt;&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;summary&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;content&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/xml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;ProcessData&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.datacontract.org/2004/07/HelloSyndication"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;            &lt;SPAN class=attr&gt;xmlns:i&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www.w3.org/2001/XMLSchema-instance"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;PeakVirtualMemorySize&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;552157184&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;PeakVirtualMemorySize&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;PeakWorkingSetSize&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;146124800&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;PeakWorkingSetSize&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;VirtualMemorySize&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;456237056&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;VirtualMemorySize&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  11:  &lt;/SPAN&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;ProcessData&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  12:  &lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;content&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;  13:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;entry&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;We can also use the Syndication support to consume feeds!&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;SyndicationFeed feed = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SyndicationFeed();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;feed.Load(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Uri(&lt;SPAN class=str&gt;"http://blogs.msdn.com/mwinkle/atom.xml"&lt;/SPAN&gt;));&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;foreach&lt;/SPAN&gt; (SyndicationItem item &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; feed.Items)&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;   &lt;SPAN class=rem&gt;// process the feed here&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;In the case where there have been extensions to the feed, we can access those as the raw XML or we can attempt to deserialize into an object.&amp;nbsp; This is accomplished in the reverse of the above:&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;foreach&lt;/SPAN&gt; (SyndicationItem i &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; feed.Items)&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;    XmlSyndicationContent content = i.Content &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; XmlSyndicationContent;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;    ProcessData pd = content.ReadContent&amp;lt;ProcessData&amp;gt;();&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;    Console.WriteLine(i.Title.Text);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;    Console.WriteLine(pd.ToString());&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;H4&gt;HTTP Programming Support&lt;/H4&gt;
&lt;P&gt;In order to enable both of the above scenarios (Syndication and JSON), there has been work done to create the webHttpBinding to make it easier to do POX and HTTP programming.&lt;/P&gt;
&lt;P&gt;Here's an example of how we can influence this behavior and return POX.&amp;nbsp; First the config:&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="GetCustomers"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;address&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="pox"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;            &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;            &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Sample.IGetCustomers"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;Now the code for the interface:&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;interface&lt;/SPAN&gt; IRestaurantOrdersService&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;   [OperationContract(Name=&lt;SPAN class=str&gt;"GetOrdersByRestaurant"&lt;/SPAN&gt;)]&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;   [HttpTransferContract(Method = &lt;SPAN class=str&gt;"GET"&lt;/SPAN&gt;)]  &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;   CustomerOrder[] GetOrdersByRestaurant();  &lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;The implementation of this interface does the work to get the CustomerOrder objects (a datacontract defined elsewhere).&amp;nbsp; And the returned XML is the datacontract serialization of CustomerOrder (omitted here for some brevity).&amp;nbsp; With parameters this gets more interesting as these are things we can pass in via the query string or via a POST, allowing arbitrary clients that can form URL's and receive XML to consume our services.&lt;/P&gt;
&lt;H4&gt;Partial Trust for WCF&lt;/H4&gt;
&lt;P&gt;I'm not fully up to date on all of the details here, but there has been some work done to enable some of the WCF functionality to operate in a partial trust environment.&amp;nbsp; This is especially important for situations where you want to use WCF to expose a service in a hosted situation (like creating a service that generates an rss feed off of some of your data).&amp;nbsp; I'll follow up with more details on this one later.&lt;/P&gt;
&lt;H4&gt;WCF Tooling&lt;/H4&gt;
&lt;P&gt;You now get a WCF project template that also includes a self hosting option (similar to the magic Visual Studion ASP.NET hosting).&amp;nbsp; This means that you can create a WCF project, hit F5 and have your service available.&amp;nbsp; This is another are where I will follow up later on.&lt;/P&gt;
&lt;H3&gt;Wrap Up&lt;/H3&gt;
&lt;P&gt;So, what now?&amp;nbsp; &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=B533619A-0008-4DD6-9ED1-47D482683C78&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=B533619A-0008-4DD6-9ED1-47D482683C78&amp;amp;displaylang=en"&gt;Grab the bits&lt;/A&gt; 
&lt;LI&gt;Explore the new features 
&lt;LI&gt;Give&amp;nbsp; us feedback (through &lt;A href="http://blogs.msdn.com/mwinkle/contact.aspx" mce_href="http://blogs.msdn.com/mwinkle/contact.aspx"&gt;my blog&lt;/A&gt; or a channel9 wiki I am putting together now)! What works, doesn't work, what do you like, not like, etc. 
&lt;LI&gt;Look forward to more posts, c9 videos and screencasts on the features in Orcas.&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1776107" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwinkle/archive/tags/wf/default.aspx">wf</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://blogs.msdn.com/mwinkle/archive/tags/WCF/default.aspx">WCF</category></item></channel></rss>