<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Ron Jacobs</title><subtitle type="html">The New WCF / WF Evangelist</subtitle><id>http://blogs.msdn.com/rjacobs/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/rjacobs/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-03-23T11:33:24Z</updated><entry><title>WF4: How To Access Out Arguments</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/09/24/wf4-how-to-access-out-arguments.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/09/24/wf4-how-to-access-out-arguments.aspx</id><published>2009-09-25T01:12:30Z</published><updated>2009-09-25T01:12:30Z</updated><content type="html">&lt;p&gt;To get a value from your workflow you must access the dictionary of output arguments returned from the workflow.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: This example is based on Visual Studio 2010 Beta 2&lt;/p&gt;  &lt;p&gt;Consider a workflow that accepts two arguments&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="400"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="133"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="133"&gt;&lt;strong&gt;Direction&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="133"&gt;&lt;strong&gt;Argument Type&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;UserName&lt;/td&gt;        &lt;td valign="top" width="133"&gt;In&lt;/td&gt;        &lt;td valign="top" width="133"&gt;String&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;Greeting&lt;/td&gt;        &lt;td valign="top" width="133"&gt;Out&lt;/td&gt;        &lt;td valign="top" width="133"&gt;String&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The workflow uses an assign activity to set the result of the expression &lt;b&gt;&lt;i&gt;&amp;quot;Hello &amp;quot; &amp;amp; UserName &amp;amp; &amp;quot; from Workflow 4&amp;quot;&lt;/i&gt;&lt;/b&gt; to the Greeting out argument.&amp;#160; The hosting program can access the Greeting out argument from the dictionary of output values returned from the &lt;b&gt;WorkflowInvoker&lt;/b&gt; or &lt;b&gt;WorkflowApplication&lt;/b&gt;.&lt;/p&gt;  &lt;p&gt;Because the values in the output dictionary are stored as objects with a string as the key, there are three possible outcomes when you try to access an argument value.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The key does not exist in the dictionary &lt;/li&gt;    &lt;li&gt;The key exists but the type of the value is not what you expected &lt;/li&gt;    &lt;li&gt;The key exists and the type is compatible with what you expected &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Whenever you access an out argument you must consider these outcomes. In the event that the key does not exist or the type of the value is not what is expected you may encounter a &lt;b&gt;KeyNotFoundException&lt;/b&gt; or &lt;b&gt;InvalidCastException&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can choose to &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Let these exceptions propagate possibly terminating the host with an unhandled exception &lt;/li&gt;    &lt;li&gt;Catch the exceptions &lt;/li&gt;    &lt;li&gt;Code defensively using &lt;strong&gt;TryGetValue&lt;/strong&gt; to access the key from the collection or the C# keyword “&lt;strong&gt;as&lt;/strong&gt;” or VB function &lt;strong&gt;TryCast&lt;/strong&gt; to avoid the invalid cast       &lt;p&gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Accessing Out Arguments with WorkflowInvoker&lt;/h1&gt;  &lt;p&gt;The following example shows a method that Invokes the SayHello workflow passing in the UserName and accessing the out argument named “Greeting” after the workflow completes.&amp;#160; &lt;/p&gt;  &lt;div&gt;   &lt;p class="noteStyle"&gt;&lt;strong&gt;Watch Out&lt;/strong&gt;      &lt;br /&gt;This example is not coding defensively or catching exceptions so if the key did not exist or the type of the value was not compatible the exception would propagate to the caller. &lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;C#&lt;/h2&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetArgumentsFromWorkflowInvoker()&lt;br /&gt;{&lt;br /&gt;    IDictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt; output = WorkflowInvoker.Invoke(&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SayHello() { UserName = &lt;span style="color: #006080"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt; });&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; greeting = (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)output[&lt;span style="color: #006080"&gt;&amp;quot;Greeting&amp;quot;&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;    Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowInvoker said {0}&amp;quot;&lt;/span&gt;, greeting);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h2&gt;Visual Basic&lt;/h2&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Shared&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; GetArgumentsFromWorkflowInvoker()&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; output &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; IDictionary(Of &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;) =&lt;br /&gt;        WorkflowInvoker.Invoke(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SayHello() &lt;span style="color: #0000ff"&gt;With&lt;/span&gt; {.UserName = &lt;span style="color: #006080"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt;})&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; greeting &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = output(&lt;span style="color: #006080"&gt;&amp;quot;Greeting&amp;quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;    Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowInvoker said {0}&amp;quot;&lt;/span&gt;, greeting)&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h1&gt;Accessing Out Arguments with WorkflowApplication&lt;/h1&gt;

&lt;p&gt;WorkflowApplication invokes the workflow on a thread from the CLR threadpool. To capture the outputs you must assign a delegate to the WorkflowApplication.Completed property. Keep in mind that your delegate is called whenever the workflow completes successfully or not. You can check the CompletionState property to find out if the activity closed or faulted. Because accessing the Outputs dictionary may result in an exception you should wrap the access with a try/catch/finally block as shown.&lt;/p&gt;

&lt;h2&gt;C#&lt;/h2&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetArgumentsFromWorkflowApplication()&lt;br /&gt;{&lt;br /&gt;    AutoResetEvent sync = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AutoResetEvent(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; greeting = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;    Exception argException = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    WorkflowApplication wfApp = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WorkflowApplication(&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SayHello()&lt;br /&gt;        {&lt;br /&gt;            UserName = &lt;span style="color: #006080"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt;&lt;br /&gt;        });&lt;br /&gt;&lt;br /&gt;    wfApp.Completed = (e) =&amp;gt;&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #008000"&gt;// Did the workflow complete without error?&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.CompletionState == ActivityInstanceState.Closed)&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style="color: #008000"&gt;// Accessing the output arguments dictionary&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #008000"&gt;// might throw a KeyNotFoundException or&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #008000"&gt;// InvalidCastException                            &lt;/span&gt;&lt;br /&gt;                    greeting = (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)e.Outputs[&lt;span style="color: #006080"&gt;&amp;quot;Greeting&amp;quot;&lt;/span&gt;];&lt;br /&gt;                }&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;                {&lt;br /&gt;                    argException = ex;&lt;br /&gt;                }&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style="color: #008000"&gt;// Must be sure to unblock the main thread&lt;/span&gt;&lt;br /&gt;                    sync.Set();&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        };&lt;br /&gt;&lt;br /&gt;    wfApp.Run();&lt;br /&gt;    sync.WaitOne();&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;// Show the exception from the background thread&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (argException != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowApplication error {0}&amp;quot;&lt;/span&gt;, argException.Message);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowApplication said {0}&amp;quot;&lt;/span&gt;, greeting);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h2&gt;Visual Basic&lt;/h2&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Shared&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; GetArgumentsFromWorkflowApplication()&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; sync &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; AutoResetEvent = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; AutoResetEvent(&lt;span style="color: #0000ff"&gt;False&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; greeting &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; argException &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Exception = &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; wfApp &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; WorkflowApplication =&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; WorkflowApplication(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SayHello() &lt;span style="color: #0000ff"&gt;With&lt;/span&gt; {.UserName = &lt;span style="color: #006080"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt;})&lt;br /&gt;&lt;br /&gt;    wfApp.Completed = &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;(args)&lt;br /&gt;                          &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (args.CompletionState = &lt;br /&gt;                                         ActivityInstanceState.Closed) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;                              &lt;span style="color: #0000ff"&gt;Try&lt;/span&gt;&lt;br /&gt;                                  &lt;span style="color: #008000"&gt;' Accessing the output arguments dictionary&lt;/span&gt;&lt;br /&gt;                                  &lt;span style="color: #008000"&gt;' might throw a KeyNotFoundException or&lt;/span&gt;&lt;br /&gt;                                  &lt;span style="color: #008000"&gt;' InvalidCastException                            &lt;/span&gt;&lt;br /&gt;                                  greeting = args.Outputs(&lt;span style="color: #006080"&gt;&amp;quot;Greeting&amp;quot;&lt;/span&gt;)&lt;br /&gt;                              &lt;span style="color: #0000ff"&gt;Catch&lt;/span&gt; ex &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Exception&lt;br /&gt;                                  argException = ex&lt;br /&gt;                              &lt;span style="color: #0000ff"&gt;Finally&lt;/span&gt;&lt;br /&gt;                                  &lt;span style="color: #008000"&gt;' Must be sure to unblock the main thread&lt;/span&gt;&lt;br /&gt;                                  sync.&lt;span style="color: #0000ff"&gt;Set&lt;/span&gt;()&lt;br /&gt;                              &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Try&lt;/span&gt;&lt;br /&gt;                          &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                          &lt;span style="color: #008000"&gt;' VB requires lambda expressions to return a value&lt;/span&gt;&lt;br /&gt;                          &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;&lt;br /&gt;                      &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    wfApp.Run()&lt;br /&gt;    sync.WaitOne()&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;' Show the exception from the background thread&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (argException &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowApplication said {0}&amp;quot;&lt;/span&gt;, greeting)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowApplication error {0}&amp;quot;&lt;/span&gt;, argException.Message)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h1&gt;Accessing Out Arguments with Defensive Coding Style&lt;/h1&gt;

&lt;p&gt;In this example, we are accessing the Out Argument with a defensive coding style that will insure no exceptions are thrown.&lt;/p&gt;

&lt;div&gt;
  &lt;p class="noteStyle"&gt;&lt;b&gt;ContainsKey()&lt;/b&gt; vs. &lt;b&gt;TryGet()&lt;/b&gt;

    &lt;br /&gt;You should use TryGet instead of ContainsKey() to first check for the key and then Get() to access the key. The reason for this is that you will iterate over the collection twice, once to determine if the key is present and again to access the value.&lt;/p&gt;
&lt;/div&gt;

&lt;h2&gt;C#&lt;/h2&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetArgumentsFromWorkflowInvokerDefensive()&lt;br /&gt;{&lt;br /&gt;    IDictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt; output = WorkflowInvoker.Invoke(&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SayHello() { UserName = &lt;span style="color: #006080"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt; });&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; greeting = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!output.TryGetValue(&lt;span style="color: #006080"&gt;&amp;quot;Greeting&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; obj))&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Greeting not found&amp;quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        greeting = obj &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (greeting == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Greeting could not be converted to a string&amp;quot;&lt;/span&gt;);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowInvoker said {0}&amp;quot;&lt;/span&gt;, greeting);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h2&gt;Visual Basic&lt;/h2&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Shared&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; GetArgumentsFromWorkflowInvokerDefensive()&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; output &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; IDictionary(Of &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;) =&lt;br /&gt;        WorkflowInvoker.Invoke(&lt;span style="color: #0000ff"&gt;New&lt;/span&gt; SayHello() &lt;span style="color: #0000ff"&gt;With&lt;/span&gt; {.UserName = &lt;span style="color: #006080"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt;})&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; obj &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt; = &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; greeting &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;' TryGetValue will not throw an exception&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; output.TryGetValue(&lt;span style="color: #006080"&gt;&amp;quot;Greeting&amp;quot;&lt;/span&gt;, obj)) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Greeting not found&amp;quot;&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #008000"&gt;' Not sure what type it is, try to convert it&lt;/span&gt;&lt;br /&gt;        greeting = &lt;span style="color: #0000ff"&gt;TryCast&lt;/span&gt;(obj, &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;)&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (greeting &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Greeting could not be converted to a string&amp;quot;&lt;/span&gt;)&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;WorkflowInvoker said {0}&amp;quot;&lt;/span&gt;, greeting)&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899184" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>WF4: Passing Arguments to Activities</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/09/14/wf4-passing-arguments-to-activities.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/09/14/wf4-passing-arguments-to-activities.aspx</id><published>2009-09-15T03:49:18Z</published><updated>2009-09-15T03:49:18Z</updated><content type="html">&lt;p&gt;In Windows Workflow Foundation .NET 4 (WF4) everything is an &lt;em&gt;Activity&lt;/em&gt;.&amp;#160; That is a class that inherits from System.Activities.Activity.&amp;#160; Activities can have in, out or in/out arguments and do their work then the &lt;strong&gt;Activity.Execute&lt;/strong&gt;() method is called.&amp;#160; You could think of them as being similar to a static method except for the fact that a static method can have only 1 return argument where an Activity can have more than one.&amp;#160; &lt;/p&gt;  &lt;p&gt;Passing arguments to an activity can be done one of two ways.&amp;#160; You can use Initialization syntax when creating the activity to set the input arguments (which are just public properties of type InArgument&amp;lt;T&amp;gt;) or you can pass a Dictionary&amp;lt;string, object&amp;gt; which will be used to initialize the arguments.&lt;/p&gt;  &lt;h2&gt;Passing Arguments with Initialization syntax&lt;/h2&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; [TestMethod]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldReturnGreetingWithName()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     var output = WorkflowInvoker.Invoke(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SayHello()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;             UserName = &lt;span style="color: #006080"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;         });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     Assert.AreEqual(&lt;span style="color: #006080"&gt;&amp;quot;Hello Test from Workflow 4&amp;quot;&lt;/span&gt;, output[&lt;span style="color: #006080"&gt;&amp;quot;Greeting&amp;quot;&lt;/span&gt;]);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This works well except that out arguments (OutArgument&amp;lt;T&amp;gt;) will also show up in the Intellisense window as well as other public properties such as the DisplayName.&amp;#160; In this example from the beta 2 release of the “Introduction to Workflow 4” hands on lab (look for it at the PDC) you will see three properties from Intellisense but only one of them is an in argument suitable for initialization.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WF4TestingActivityInterfaces_F605/OutArg_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="OutArg" border="0" alt="OutArg" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WF4TestingActivityInterfaces_F605/OutArg_thumb.png" width="470" height="216" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As you can see initializing an OutArgument looks possible, but if you try it… &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WF4TestingActivityInterfaces_F605/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WF4TestingActivityInterfaces_F605/image_thumb_1.png" width="728" height="266" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;What’s going on here?&amp;#160; InArgument&amp;lt;T&amp;gt; will implicitly construct from an argument of type &lt;em&gt;T&lt;/em&gt; but OutArgument&amp;lt;T&amp;gt; won’t do this so even though it appears like you can do this, you can’t because it won’t compile.&amp;#160; But this is a good thing because you shouldn’t initialize an OutArgument anyway.&lt;/p&gt;

&lt;p&gt;In practice, I think most people will wrap activity initialization and (possibly) invocation inside of other methods so that developers who are unfamiliar with workflow can just call those methods to do the work.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9895202" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>WCF Essentials – Great Stuff now online</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/09/10/wcf-essentials-great-stuff-now-online.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/09/10/wcf-essentials-great-stuff-now-online.aspx</id><published>2009-09-10T21:47:36Z</published><updated>2009-09-10T21:47:36Z</updated><content type="html">&lt;p&gt;&lt;a href="http://www.dasblonde.net/"&gt;Michelle Leroux Bustamante&lt;/a&gt; has written some great new papers for MSDN that you really should check out.&amp;#160; They are in the &lt;a href="http://msdn.microsoft.com/en-us/library/ee354181.aspx"&gt;WCF Essentials&lt;/a&gt; series.&lt;/p&gt;  &lt;p&gt;What I like the most about these articles is that she gives really great practical advice.&amp;#160; For example check out this sentence from &lt;a href="http://msdn.microsoft.com/en-us/library/ee354180.aspx"&gt;Getting Started with WCF&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“The default is &lt;strong&gt;PerSession&lt;/strong&gt; which is typically not the desired setting.”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Wow – you won’t read that in the MSDN documentation about the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontextmode.aspx"&gt;InstanceContextMode Enumeration&lt;/a&gt; but it is probably something that you should know.&amp;#160; It is the kind of advice you can expect from a seasoned WCF developer.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Are you doing WCF Services or SOA in your organization?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If so, I’d like to talk with you about your solution as a part of some research we are doing for future releases.&amp;#160; Please contact me through my blog if you would be willing to have a short phone discussion with me about your solution and needs. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9893804" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>Testing a SendMail activity with WF4</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/09/01/testing-a-sendmail-activity-with-wf4.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/09/01/testing-a-sendmail-activity-with-wf4.aspx</id><published>2009-09-01T21:00:31Z</published><updated>2009-09-01T21:00:31Z</updated><content type="html">&lt;p&gt;Many applications send email.&amp;#160; After all it is the preferred binding for async app to human communication.&amp;#160; I noticed that many of my colleagues were creating samples that simulate email by dropping a text file into a directory.&amp;#160; Then they would open the file and copy and paste a GUID into a form.&amp;#160; There is a much better way of course.&amp;#160; In the real world people would send an HTML mail with a link that brings you back to the website with the GUID in place.&lt;/p&gt;  &lt;p&gt;Nearly everyone has done this with a web site where you register with the site, they send you an email to confirm and then you click a link in the email to complete the registration process.&amp;#160; I decided to build out this scenario using a workflow to manage the registration process but then I ran into the issue of how to test the email.&lt;/p&gt;  &lt;p&gt;At first I thought I would just use Hotmail.&amp;#160; This would work for a demonstration but you have to have network connectivity and verifying that the message arrived would require coding to open the mailbox with POP3 and look for a particular message.&amp;#160; Then I found an easier way.&amp;#160; You can configure the SmtpClient to drop mail messages into a folder rather than send them.&lt;/p&gt;  &lt;p&gt;Of course, many of you will say “Duh! I can’t believe Ron didn’t know about this…”.&amp;#160; Well it was news to me so I’m sure that some people didn’t know about it either so here is how it works.&lt;/p&gt;  &lt;p&gt;First off, here is the very simple SendMail activity (using .NET 4 Beta 1)&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SendMail : CodeActivity&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; InArgument&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; From { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; InArgument&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; Recipients { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; InArgument&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; Subject { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; InArgument&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; Body { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; InArgument&amp;lt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt; IsBodyHtml { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Execute(CodeActivityContext context)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;         SmtpClient client = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SmtpClient();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;         MailMessage message = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MailMessage(From.Get(context),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;             Recipients.Get(context), Subject.Get(context), Body.Get(context));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;         message.IsBodyHtml = IsBodyHtml.Get(context);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;         client.Send(message);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now I want to test my SendMail class.&amp;#160; So I created a Unit Test project and added an app.config file with the necessary configuration magic.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;system.net&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;mailSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;smtp&lt;/span&gt; &lt;span style="color: #ff0000"&gt;deliveryMethod&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SpecifiedPickupDirectory&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;specifiedPickupDirectory&lt;/span&gt; &lt;span style="color: #ff0000"&gt;pickupDirectoryLocation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;c:\maildrop&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;smtp&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;mailSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;system.net&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now all that I need to do is write the test.&amp;#160; I want to be sure that when I send a mail that a file ends up in the c:\maildrop directory.&amp;#160; The file will have a random GUID as the name.&amp;#160; I’m not worried about reading the file to be sure that it contains the correct text.&amp;#160; That would be testing the SmtpClient class which I assume works properly.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; [TestMethod]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; [DeploymentItem(&lt;span style="color: #006080"&gt;&amp;quot;MyActivities.dll&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldSendMail()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Remove all files from the drop location&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Directory.Exists(mailDrop))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;         Directory.Delete(mailDrop, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     Directory.CreateDirectory(mailDrop);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Create and send the message&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;     WorkflowInvoker.Invoke(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MyActivities.SendMail()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;         From = &lt;span style="color: #006080"&gt;&amp;quot;test@tempuri.org&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;         Recipients = &lt;span style="color: #006080"&gt;&amp;quot;foo@bar.org, baz@foo.com&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;         Subject = &lt;span style="color: #006080"&gt;&amp;quot;Test HTML message&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;         IsBodyHtml = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt;         Body = messageBody&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;     });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Find the message in the drop location&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&lt;/span&gt;     var messages = Directory.EnumerateFiles(mailDrop);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt;     Assert.AreEqual(1, messages.Count());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum24"&gt;  24:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And the really cool thing is that you can open this file with Windows Live Mail and click the link if you want to demonstrate how it works.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/TestingaSendMailactivitywithWF4_9AC6/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/TestingaSendMailactivitywithWF4_9AC6/image_thumb.png" width="244" height="126" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I decided to screencast this code check it out 
  &lt;br /&gt;&lt;a href="http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Spike-on-Workflow-Managed-Email-Verification/"&gt;endpoint.tv Screencast - Spike on Workflow Managed Email Verification&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889990" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>Windows Workflow in .NET 4 and Web Services</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/07/29/windows-workflow-in-net-4-and-web-services.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/07/29/windows-workflow-in-net-4-and-web-services.aspx</id><published>2009-07-29T23:33:59Z</published><updated>2009-07-29T23:33:59Z</updated><content type="html">&lt;p&gt;Today I published &lt;a href="http://channel9.msdn.com/shows/10-4/10-4-episode-29-Workflow-Web-Services/"&gt;10-4 episode 29: Workflow Web Services&lt;/a&gt; on our &lt;a href="http://channel9.msdn.com/shows/10-4/"&gt;Channel 9 10-4 Show&lt;/a&gt; about Workflow Services in .NET 4 beta 1.&amp;#160; &lt;/p&gt;  &lt;p&gt;People have asked me why they would want to implement a web service with a workflow rather than with code using WCF.&amp;#160; It is a valid question.&amp;#160; Over the next few blog posts I’ll describe some of the reasons why I find workflows a very interesting solution for implementing web services.&lt;/p&gt;  &lt;h2&gt;Workflows are a simple way to implement web services&lt;/h2&gt;  &lt;p&gt;Remember the ABC’s of web services with WCF?&amp;#160; Every service has an Address, Binding and Contract right?&amp;#160; Well it turns out that this isn’t as simple as it sounds.&amp;#160; With Workflow services I don’t have to bother so much with the ABC’s.&amp;#160; Instead I can focus on a declarative model where I simply create a variable of some type that I want to receive and put it into a receive shape.&lt;/p&gt;  &lt;p&gt;Here is a screenshot of a Declarative Sequential Workflow Service in Visual Studio 2010 Beta 1.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WindowsWorkflowin.NET4andWebServices_AF85/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WindowsWorkflowin.NET4andWebServices_AF85/image_thumb.png" width="602" height="638" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This picture is a visualization of XAML that describes a contract.&amp;#160; And what is the contract?&amp;#160; You can see it from the WCF Test Client&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WindowsWorkflowin.NET4andWebServices_AF85/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WindowsWorkflowin.NET4andWebServices_AF85/image_thumb_1.png" width="312" height="173" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Ok – so the name is a bit ugly but it is just a property of the receive activity easy to change.&amp;#160; I have a contract with a method named GetData.&amp;#160; And what does the GetData method use as an argument?&amp;#160; The value is an Int32, of course because this is a web service message the value might not be included so the WCF Test Client now allows me to use a Nullable&amp;lt;Int32&amp;gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WindowsWorkflowin.NET4andWebServices_AF85/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/WindowsWorkflowin.NET4andWebServices_AF85/image_thumb_2.png" width="522" height="148" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And the workflow definition is just a XAMLX file that I can drop on the web server (along with any assemblies it uses) and have a complete working service.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Service&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/netfx/2009/xaml/servicemodel&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:d&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:DeclarativeSequentialServiceLibrary1;assembly=DeclarativeSequentialServiceLibrary1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/netfx/2009/xaml/activities&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:sad&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:System.Activities.Debugger;assembly=System.Activities&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns:x&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;WorkflowServiceImplementation&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ConfigurationName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Service1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Service1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:Sequence&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sequential Service&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;sad:XamlDebuggerXmlReader&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;FileName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;c:\scratch\DeclarativeSequentialServiceLibrary1\DeclarativeSequentialServiceLibrary1\Service1.xamlx&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:Sequence.Variables&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:Variable&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:TypeArguments&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CorrelationHandle&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;handle&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:Variable&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:TypeArguments&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;x:Int32&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;data&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p:Sequence.Variables&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Receive&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;__ReferenceID0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CanCreateInstance&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ReceiveRequest&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;OperationName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GetData&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ServiceContractName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Contract1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ValueType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;x:Int32&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Receive.AdditionalCorrelations&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:InArgument&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:TypeArguments&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CorrelationHandle&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ChannelBasedCorrelation&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;[handle]&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p:InArgument&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Receive.AdditionalCorrelations&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Receive.KnownTypes&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;x:Type&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;x:Int32&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Receive.KnownTypes&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:OutArgument&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:TypeArguments&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;x:Int32&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;[data]&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p:OutArgument&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Receive&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;d:TraceActivity&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Message&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[String.Format(&amp;amp;quot;Received data {0}&amp;amp;quot;, data)]&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SendReply&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Request&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{x:Reference __ReferenceID0}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SendResponse&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ValueType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;x:String&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:InArgument&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:TypeArguments&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;x:String&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;[data.ToString()]&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p:InArgument&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SendReply&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p:Sequence&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;WorkflowServiceImplementation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This is a pretty cool way to declare a service.&amp;#160; If I want to get a little more complex, I can create a type that is received with multiple properties and such.&amp;#160; This is exactly what we are doing in the Introduction to Workflow Services lab from the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;amp;displaylang=en"&gt;Visual Studio 2010 Training Kit&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9852512" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author><category term="WF4" scheme="http://blogs.msdn.com/rjacobs/archive/tags/WF4/default.aspx" /><category term="WCF4" scheme="http://blogs.msdn.com/rjacobs/archive/tags/WCF4/default.aspx" /></entry><entry><title>Another reason I love Windows 7 - The Network Troubleshooter</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/07/28/another-reason-i-love-windows-7-the-network-troubleshooter.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/07/28/another-reason-i-love-windows-7-the-network-troubleshooter.aspx</id><published>2009-07-28T19:46:43Z</published><updated>2009-07-28T19:46:43Z</updated><content type="html">&lt;p&gt;After installing the RTM release of Windows 7 I dropped by the office this morning and when I put the laptop on the docking station I fired up the web browser and got… nothing.&amp;#160; My PC was acting like it had no network connection even though it was connected both to a wired and wireless connection on the corporate network.&lt;/p&gt;  &lt;p&gt;I’ve been through this enough times to know that the issue was probably something to do with the corporate firewall and proxy settings on IE but I decided to test out the Windows 7 Network Troubleshooter.&amp;#160; &lt;/p&gt;  &lt;p&gt;When people say that Windows 7 is just a minor update to Windows Vista they underestimate the great work the Windows team did on this release.&amp;#160; Somebody who doesn’t know the first thing about networking or proxies would have to call the helpdesk to fix this problem but Windows 7 includes troubleshooter “packs” that help you to solve common problems without becoming a networking guru.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/TroubleShoot%20problems_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TroubleShoot problems" border="0" alt="TroubleShoot problems" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/TroubleShoot%20problems_thumb.png" width="854" height="452" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;First I select the Troubleshoot Internet connections &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/Wiz1_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Wiz1" border="0" alt="Wiz1" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/Wiz1_thumb.png" width="589" height="450" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Notice that this dialog shows a publisher – I assume this means that others can publish troubleshooting packs though I’m not sure what the process is for this.&amp;#160;&amp;#160;&amp;#160; I click next.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/Wiz2_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Wiz2" border="0" alt="Wiz2" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/Wiz2_thumb.png" width="589" height="450" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Since I’m having trouble connecting to any website I’ll use the first option which will test microsoft.com&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/image_thumb_1.png" width="589" height="450" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After short time I got the problem fixed automatically&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/TroubleshootingCompleted_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TroubleshootingCompleted" border="0" alt="TroubleshootingCompleted" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/AnotherreasonIloveWindows7TheNetworkTrou_8974/TroubleshootingCompleted_thumb.png" width="589" height="450" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The problem was that I forgot to install the ISA firewall client that automatically sets up the proxy settings when I’m on corpnet.&amp;#160; I used to do product support many years ago.&amp;#160; How I would have loved a tool like this.&amp;#160; Way to go Windows 7!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9851148" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>Mocking the Console</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/06/09/mocking-the-console.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/06/09/mocking-the-console.aspx</id><published>2009-06-10T04:21:15Z</published><updated>2009-06-10T04:21:15Z</updated><content type="html">&lt;p&gt;I’ve posted an update to the &lt;a href="http://code.msdn.microsoft.com/wf4Simulation"&gt;Microsoft.Activities.Simulation&lt;/a&gt; library.&amp;#160; Today at the team meeting I showed the library to the Windows Workflow team and &lt;a href="http://blogs.msdn.com/edpinto/"&gt;Ed Pinto&lt;/a&gt; said “That is cool!” so I must be doing something right.&lt;/p&gt;  &lt;p&gt;Today’s update is a better TestConsole.&amp;#160; This time I’ve had the TestConsole redirect the Console output stream by calling Console.SetOut.&amp;#160; Now the stream will go into a StringWriter backed by a StringBuilder as the buffer.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; StringBuilder _buffer;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; TestConsole()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     StringWriter outWriter = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringWriter(_buffer);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     Console.SetOut(outWriter);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This way anything that writes to the console will now be captured and therefore it will become testable.&lt;/p&gt;

&lt;p&gt;When I want to verify that something was written to the console there are two ways I can do it.&amp;#160; I can access the StringBuilder by calling TestConsole.Buffer.ToString() and then look for something in the string.&lt;/p&gt;

&lt;p&gt;Or if I prefer a line oriented approach I can do something like this test.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; Assert.AreEqual(&lt;span style="color: #006080"&gt;&amp;quot;Scope 1 Number is 1&amp;quot;&lt;/span&gt;, results.Console.Lines[0]);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Here I have a SimulationResults type with a TestConsole member named Console.&amp;#160; I can access a string[] named Lines that will return each line from the TestConsole buffer by calling Regex.Split&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] Lines&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     get&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: #008000"&gt;// Split it only if we need to&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Buffer.Length != _lastBufferSplit)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;             _lastBufferSplit = Buffer.Length;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;             _lines = Regex.Split(Buffer.ToString(), Environment.NewLine);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _lines;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Since splitting the buffer is a little work, I only split it if the length of the buffer has changed since the last time I split it.&amp;#160; One side effect of using Regex.Split is that you always get an empty last line.&amp;#160; Since the &lt;a href="http://code.msdn.microsoft.com/wf4CancellationScope"&gt;CancellationScope Activity Sample&lt;/a&gt; also uses this library I put the library in place and found that I had to update all the unit tests that relied on a line count.&amp;#160; If they asserted the count should be 2 I had to change it to 3.&amp;#160; &lt;/p&gt;

&lt;p&gt;I’ m not enough of a Regex guru to know how to work around this.&amp;#160; For now I think it is ok to just say that you will always get one empty line at the end of the array and that is just the way it is.&lt;/p&gt;

&lt;p&gt;If you are interested in the &lt;a href="http://code.msdn.microsoft.com/wf4Simulation"&gt;Microsoft.Activities.Simulation library&lt;/a&gt;, let me know by posting some &lt;a href="http://code.msdn.microsoft.com/wf4Simulation/Thread/List.aspx"&gt;discussion threads&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9720298" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>How to test WF4 Workflows with Microsoft.Activities.Simulation</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/06/05/how-to-test-wf4-workflows-with-microsoft-activities-simulation.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/06/05/how-to-test-wf4-workflows-with-microsoft-activities-simulation.aspx</id><published>2009-06-05T19:10:54Z</published><updated>2009-06-05T19:10:54Z</updated><content type="html">&lt;p&gt;Recently I posted a &lt;a href="http://code.msdn.microsoft.com/wf4CancellationScope"&gt;new sample&lt;/a&gt; for the CancellationScope activity.&amp;#160; Of course, I’m building these samples on .NET 4 Beta 1.&amp;#160; But the team is already making rapid progress towards the next major milestone.&amp;#160; They are checking in changes that may or may not break my sample applications and hands on labs.&amp;#160; How will I know if things are broken?&lt;/p&gt;  &lt;p&gt;Most people rely on manual testing to detect broken code.&amp;#160; The problem is that manual testing is time consuming and expensive.&amp;#160; I wanted to find a way to unit and acceptance test the sample applications and labs.&amp;#160; There are significant challenges to this but I’ve got some ideas that I think will work and I’m going to describe them to you on my blog as I get them in place.&lt;/p&gt;  &lt;h2&gt;Unit Testing A Workflow&lt;/h2&gt;  &lt;p&gt;I’ve covered this on my blog in the past.&amp;#160; In fact, the WF4 Hands On Labs (Lab 1) from the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;amp;displaylang=en"&gt;Visual Studio 2010 training kit&lt;/a&gt; includes unit testing.&amp;#160; One issue I did not cover was how to use a &lt;a href="http://xunitpatterns.com/Test%20Double.html"&gt;Test Double&lt;/a&gt; with workflow.&amp;#160; Why would you do this?&amp;#160; Because some activities do things that are not testable or desirable in a unit test.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The WriteLine activity writes text to the console&lt;/li&gt;    &lt;li&gt;A Send activity sends a message to an endpoint that might not be available when testing&lt;/li&gt;    &lt;li&gt;A Receive activity requires a message to cause the workflow to continue.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;One response to things like this is to use &lt;a href="http://martinfowler.com/articles/injection.html"&gt;Dependency Injection&lt;/a&gt; with &lt;a href="http://martinfowler.com/articles/injection.html"&gt;Inversion of Control&lt;/a&gt; containers to replace these troublesome components with something more testable.&amp;#160; The Microsoft patterns &amp;amp; practices group has produced the &lt;a href="http://www.codeplex.com/unity"&gt;Unity container&lt;/a&gt; for this very purpose.&lt;/p&gt;  &lt;p&gt;These solutions do not work with workflow activities because they rely on having some measure of control over the creation of dependencies so they can resolve them at runtime.&amp;#160; &lt;/p&gt;  &lt;h2&gt;Microsoft.Activities.Simulation&lt;/h2&gt;  &lt;p&gt;I found a way to get around this specifically for workflow.&amp;#160; I’m using the term “Simulation” to describe it because in the long run I believe we can build something that would be useful to technical business users for testing workflows.&amp;#160; To understand how it works consider the CancellationScope activity sample.&amp;#160; If I want to test this sample, how would I do it?&lt;/p&gt;  &lt;p&gt;The sample writes data to a console window to show how the cancellation scope allows you to execute activities that will be triggered when a workflow element is cancelled.&amp;#160; It uses the &lt;strong&gt;System.Activities.Statements.WriteLine&lt;/strong&gt; activity to do this.&amp;#160; So what I need is a way to verify that the correct messages are output by WriteLine in the correct order.&amp;#160; What I really wanted to do was to replace &lt;strong&gt;WriteLine&lt;/strong&gt; with another activity I call &lt;strong&gt;MockWriteLine&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;The strategy I use is to modify the XAML for testing.&amp;#160; Consider the following XAML snippet.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:CancellationScope&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Cancellation Scope 1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:CancellationScope.CancelHandler&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p:WriteLine&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WriteLine Cancel Scope 1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;[&amp;quot;Cancelling scope 1...&amp;quot;]&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p:WriteLine&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p:CancellationScope.CancelHandler&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Here&amp;#160; you can see the solution staring you in the face.&amp;#160; If you could just change &lt;strong&gt;&amp;lt;p:WriteLine&lt;/strong&gt; to &lt;strong&gt;&amp;lt;p:MockWriteLine&lt;/strong&gt; and made the MockWriteLine activity have the same properties as WriteLine then you can do whatever you want from MockWriteLine to make the workflow testable.&lt;/p&gt;

&lt;p&gt;Great, but what should MockWriteLine do?&amp;#160; I want to capture what it would have written to the console.&amp;#160; I need to get data from this activity without modifying the workflow more than I already have.&amp;#160; The solution is to use the &lt;a href="http://xunitpatterns.com/Test%20Spy.html"&gt;Test Spy pattern&lt;/a&gt; with a workflow extension.&lt;/p&gt;

&lt;p&gt;I created a class called &lt;strong&gt;TestConsole&lt;/strong&gt; that will store up the WriteLine output in a buffer that I can verify later.&amp;#160; I can then add this extension to the workflow instance.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; WorkflowInstance workflowInstance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WorkflowInstance(wfElement, inputs);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; TestConsole testConsole = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TestConsole();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: #008000"&gt;// Add the testConsole to the extensions collection&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; workflowInstance.Extensions.Add(testConsole);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; &lt;span style="color: #008000"&gt;// Run the test...&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt; RunTheTest();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt; &lt;span style="color: #008000"&gt;// Check the first line of the buffer&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt; Assert.AreEqual(&lt;span style="color: #006080"&gt;&amp;quot;Some text to verify&amp;quot;&lt;/span&gt;, testConsole.Buffer.ElementAt(0));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
There is much more to say about this but I’m running out of time.&amp;#160; To see it in action, check out the updated version of the &lt;a href="http://code.msdn.microsoft.com/wf4CancellationScope"&gt;CancellationScope Activity Sample&lt;/a&gt;.

&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9701549" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>WF / WCF 4 and “Dublin” Resources</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/06/02/wf-wcf-4-and-dublin-resources.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/06/02/wf-wcf-4-and-dublin-resources.aspx</id><published>2009-06-03T01:12:27Z</published><updated>2009-06-03T01:12:27Z</updated><content type="html">&lt;p&gt;Every now and then somebody will ask me about resources for WF/WCF 4.&amp;#160; I usually copy a bunch of links into an email for them.&amp;#160; Today I decided I ought to share these resources with all of you.&amp;#160; I’ll try to remember and come back to this page and add more as we make more.&lt;/p&gt;  &lt;h2&gt;Videos&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://channel9.msdn.com/shows/Endpoint/endpointtv-Windows-Workflow-4/"&gt;endpoint.tv - Windows Workflow 4&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/shows/Endpoint/endpointtv-Service-Discovery-with-WCF/"&gt;endpoint.tv - Service Discovery with WCF&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/shows/Endpoint/endpointtv-Dublin-Architecture/"&gt;endpoint.tv - Dublin Architecture&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/shows/Endpoint/endpointtv-Dublin-what-is-it-and-why-should-I-care/"&gt;endpoint.tv - &amp;quot;Dublin&amp;quot; what is it and why should I care?&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Code / Samples&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/wcfwf4"&gt;WF/WCF 4 Hands On Labs&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/rjacobs/archive/2009/06/01/cancellationscope-activity.aspx"&gt;CancellationScope Activity sample&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;amp;displaylang=en"&gt;Visual Studio 2010 Training Kit (includes WF/WCF 4 Labs)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=5aca0622-d87d-4cc9-a22c-0d58205a56b4#tm"&gt;Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4.0 Beta 1&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/netframework/cc896557.aspx"&gt;MSDN – WCF / WF4 Changes&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Questions&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/threads"&gt;WF4 Pre Release Forum&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcfprerelease/threads"&gt;WCF4 Pre Release Forum&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9687444" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>CancellationScope Activity</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/06/01/cancellationscope-activity.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/06/01/cancellationscope-activity.aspx</id><published>2009-06-01T22:00:46Z</published><updated>2009-06-01T22:00:46Z</updated><content type="html">&lt;p&gt;Last Edit: 2-Jun-2009&lt;/p&gt;  &lt;p&gt;How do you cancel work in your application?&amp;#160; Many middle tier components and services rely on transactions to handle cancellation for them.&amp;#160; This makes a great deal of sense because transactional programming is well understood.&amp;#160; However there are many times when you must cancel work that cannot be done under a transaction.&amp;#160; Cancellation can be very difficult because you have to track work that has been done to know how to cancel it.&amp;#160; WF4 also includes compensation activities that can be used to do clean up work as well.&lt;/p&gt;  &lt;p&gt;Windows Workflow Foundation 4 helps you with this by providing a CancellationScope activity.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/CancellationScopeActivity_DEDB/Cancellation%20Scope%201_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Cancellation Scope 1" border="0" alt="Cancellation Scope 1" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/CancellationScopeActivity_DEDB/Cancellation%20Scope%201_thumb.jpg" width="309" height="340" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In today’s example I’m going to show you how you can use a cancellation scope to manage cleanup work.&lt;/p&gt;  &lt;h2&gt;How does cancellation happen?&lt;/h2&gt;  &lt;p&gt;Before we consider how the CancellationScope, let’s think about how cancellation happens in a workflow.&amp;#160; There are 2 ways it can happen, from &lt;strong&gt;inside&lt;/strong&gt; of a workflow or from the &lt;strong&gt;outside&lt;/strong&gt;.&amp;#160; Child workflow activities are scheduled by their parent activity (such as a &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.sequence(VS.100).aspx"&gt;Sequence&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.parallel(VS.100).aspx"&gt;Parallel&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.flowchart(VS.100).aspx"&gt;Flowchart&lt;/a&gt; or some custom activity).&amp;#160; The parent activity can decide to cancel child activities for any reason.&amp;#160; For example, a Parallel activity with three child branches will cancel the remaining child branches whenever it completes a branch and the&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.parallel.completioncondition(VS.100).aspx"&gt;CompletionCondition&lt;/a&gt; expression evaluates to true.&lt;/p&gt;  &lt;p&gt;The workflow can also be cancelled from the outside by the host application by calling the &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.workflowinstance.cancel(VS.100).aspx"&gt;Cancel&lt;/a&gt; method on the &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.workflowinstance(VS.100).aspx"&gt;WorkflowInstance.&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;How does the cancellation scope work?&lt;/h2&gt;  &lt;p&gt;It’s very simple really, the cancellation scope has a &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.cancellationscope.body(VS.100).aspx"&gt;Body&lt;/a&gt;.&amp;#160; This is where you do the work that you might have to cancel later.&amp;#160; The &lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.statements.cancellationscope.cancelhandler(VS.100).aspx"&gt;CancelHandler&lt;/a&gt; contains the activities you want to run if the activity is canceled.&amp;#160; &lt;/p&gt;  &lt;h2&gt;Does an unhandled exception cause the cancellation handler to be invoked?&lt;/h2&gt;  &lt;p&gt;No it does not.&amp;#160; Unhandled exceptions cause the workflow to abort, cancellation handlers are not invoked.&lt;/p&gt;  &lt;h2&gt;What if my cancellation handler throws an unhandled exception?&lt;/h2&gt;  &lt;p&gt;If you have an unhandled exception in the cancellation handler the workflow will immediately terminate with the exception.&amp;#160; This is similar to throwing an exception from within a catch block.&lt;/p&gt;  &lt;h2&gt;Show me a sample&lt;/h2&gt;  &lt;p&gt;I created some sample code for this blog post that cancels the workflow from the outside.&amp;#160; In this example you can observe the behavior of nested cancellation.&lt;/p&gt;  &lt;p&gt;When it starts you enter a number between 1 and 3 to determine the number of nested levels you want to call.&amp;#160; When you get to the limit of that level the workflow will call a custom activity I created call GoIdle that simply sets a bookmark.&amp;#160; This will cause the workflow to become idle and the WorkflowInstance.&lt;a href="http://msdn.microsoft.com/en-us/library/system.activities.workflowinstance.onidle(VS.100).aspx"&gt;OnIdle&lt;/a&gt; handler will be invoked handing control back to the host.&lt;/p&gt;  &lt;p&gt;In &lt;strong&gt;program.cs&lt;/strong&gt; I’ve created two AutoResetEvents, one that will be signaled when the workflow goes idle and another that will be signaled when the workflow completes or terminates with an exception.&amp;#160; This is a little unusual but I know that my workflow will go idle when it matches one of the nesting levels 1,2 or 3.&lt;/p&gt;  &lt;h2&gt;Try It Out&lt;/h2&gt;  &lt;p&gt;Download the sample code from &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wf4CancellationScope&amp;amp;DownloadId=5980"&gt;here&lt;/a&gt;.&amp;#160; (This sample requires &lt;a href="http://go.microsoft.com/?linkid=9666892"&gt;Visual Studio 2010 / .NET 4 Beta 1&lt;/a&gt;)&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Explore the sample, check out program.cs and Sequence1.xaml &lt;/li&gt;    &lt;li&gt;Press Ctrl+F5 to compile and run the sample &lt;/li&gt;    &lt;li&gt;When it prompts you for a level try level 1 or 2.&amp;#160; You will see that cancellation happens in reverse order of invocation (level 2 cancels before level 1). &lt;/li&gt;    &lt;li&gt;To see what happens when you have an unhandled exception thrown in the cancel handler, try level 3. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/CancellationScopeActivity_DEDB/CancelCmd_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CancelCmd" border="0" alt="CancelCmd" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/CancellationScopeActivity_DEDB/CancelCmd_thumb_1.png" width="396" height="250" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9680317" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>Ready to learn WF/WCF 4?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/05/19/ready-to-learn-wf-wcf-4.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/05/19/ready-to-learn-wf-wcf-4.aspx</id><published>2009-05-19T21:02:02Z</published><updated>2009-05-19T21:02:02Z</updated><content type="html">&lt;p&gt;Tomorrow Visual Studio 2010 and .NET 4 beta 1 will be available for everyone to download.&amp;#160; I’ve been keeping quiet about the work I’ve been up to for the last month and a half while we got some great resources ready for you.&lt;/p&gt;  &lt;p&gt;Ok – I let some of this out on &lt;a href="http://endpoint.tv"&gt;endpoint.tv&lt;/a&gt; already but now you can get hands on with the technology and learn it yourself.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/wcfwf4"&gt;Download the WF / WCF 4 Hands On Labs&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;Introduction to Workflow 4 &lt;/h4&gt; In this lab you will get to know the basics of creating, hosting and running a workflow. This lab is also intended to be an introduction to the new workflow authoring constructs in the .NET Framework 4 and Visual Studio 2010, including the new Workflow Designer, expressions, variables and arguments. Additionally, you will explore the use of some basic built-in activities.   &lt;h4&gt;Introduction to Workflow Services using .NET Framework 4 &lt;/h4&gt; This hands-on lab is intended to introduce developers to writing workflow services using .NET Framework 4. You will examine the different messaging activities of Windows Workflow, and learn how to configure them to create a distributed application. This lab is built around a specific HR business scenario where candidates submit their applications and are hired or rejected based on an evaluation process.   &lt;h4&gt;Workflow Designer Programming Model &lt;/h4&gt; This hands-on lab introduces you to the designer programming model of Windows Workflow 4. You will learn how to rehost the workflow designer in a WPF desktop application and how to create composite custom designers for your workflow activities.   &lt;h4&gt;Creating Flowchart Workflows &lt;/h4&gt; This lab is intended to be an introduction to the Flowchart paradigm used in Workflow development. In this lab you will learn how to create Flowchart Workflows using the designer, and you will also learn the usage of several of the provided activities and how to create custom activities easily.   &lt;h4&gt;Monitoring Workflow Services using .NET Framework 4 &lt;/h4&gt; During the life cycle of an application, developers and system administrators often need to monitor running services in order to perform health checks or troubleshoot issues. The Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) runtimes already come with a built-in tracking infrastructure, making it easy to enable monitoring within your WCF and WF applications. In this hands-on lab you will learn how you can leverage some of the main WF and WCF monitoring features to track application execution and troubleshoot problems with services when necessary.   &lt;h4&gt;WCF Service Discovery using .NET Framework 4 &lt;/h4&gt; Windows Communication Foundation 4 includes a new feature that enables service discovery. Service discovery allows you to locate services on the same subnet using ad hoc discovery, or using a proxy to establish connections with servers regardless of where they are. In this lab you will create a simple chat application that will use both methods to learn about available services.   &lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9628901" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>Configuring a VPC for the REST Starter Kit Hands On Labs</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/04/03/configuring-a-vpc-for-the-rest-starter-kit-hands-on-labs.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/04/03/configuring-a-vpc-for-the-rest-starter-kit-hands-on-labs.aspx</id><published>2009-04-04T01:24:47Z</published><updated>2009-04-04T01:24:47Z</updated><content type="html">&lt;p&gt;Today I was given a VPC image that someone had started and asked to put the &lt;a href="http://code.msdn.microsoft.com/wcfrestlabs"&gt;WCF REST Starter Kit Hands On Labs&lt;/a&gt; on the image so we can use it at Tech-Ed.&lt;/p&gt;  &lt;p&gt;I ran into some interesting problems and I thought I would share the solutions with you in case you run into the same thing.&lt;/p&gt;  &lt;h2&gt;Problem #1 SQL Server Name&lt;/h2&gt;  &lt;p&gt;The REST Starter Kit labs assume that the SQL Server is “.\SQLExpress”.&amp;#160; Normally this works pretty well since Visual Studio installs this instance.&amp;#160; However the image I was working with did not have this server present.&amp;#160; They had uninstalled it (since it was SQL Server 2005) and replaced it with a SQL Server 2008 install at (local).&lt;/p&gt;  &lt;p&gt;I had two choices now.&amp;#160; I could go through all the labs and docs and change the connection strings or… I could use a SQL Alias.&amp;#160; If you have never used these, they are way cool.&amp;#160; SQL Server allows you to create an alias for a server and that is just what I did.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/ConfiguringaVPCfortheRESTStarterKitHands_D8BB/sqlalias_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="sqlalias" border="0" alt="sqlalias" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/ConfiguringaVPCfortheRESTStarterKitHands_D8BB/sqlalias_thumb.png" width="227" height="254" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; Now I can refer to the server as (local) or as “.\SQLExpress” which means I don’t have to change any scripts, docs or connection strings.&lt;/p&gt;  &lt;h2&gt;Problem #2 Default.htm is blank&lt;/h2&gt;  &lt;p&gt;Every now and then I run into something I had never seen before.&amp;#160; When I opened Lab 2, I right clicked on default.htm and selected “View in browser” which promptly launched IE and displayed an empty page.&amp;#160; I thought that perhaps I had accidentally deleted the content of the page so I opened it in Visual Studio and the HTML was there and displaying properly in the VS Design Mode editor.&lt;/p&gt;  &lt;p&gt;I launched the site in the debugger and refreshed IE several times… no luck.&amp;#160; I did View Source and saw that an empty HTML was being returned.&amp;#160; Now I was really confused.&amp;#160; Then I realized that the IIS7 installation allows you to pick and choose features.&amp;#160; Once of those features is “Static Content”.&amp;#160; I’ve always selected this option and didn’t know what would happen if I didn’t.&amp;#160; Sure enough, this option was not enabled.&amp;#160; I had to go into Server Manager (on Windows Server 2008) and enable the feature.&amp;#160; No big deal but this sure threw me for a minute.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/ConfiguringaVPCfortheRESTStarterKitHands_D8BB/IISStatic.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IISStatic" border="0" alt="IISStatic" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/ConfiguringaVPCfortheRESTStarterKitHands_D8BB/IISStatic_thumb.png" width="244" height="141" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;Problem #3 Network Service login to SQL Server&lt;/h2&gt;  &lt;p&gt;Now that I have the web page showing, I test and get a security exception.&amp;#160; The Network Service account doesn’t have permission to open the database.&amp;#160; I’m sure that everybody has run into this a dozen times, I know that every now and then I have to fix up a server like this but it seems like I can never remember the exact way to do it.&amp;#160; Fortunately my friends in the patterns &amp;amp; practices team have published a great “How to” document on this called &lt;a href="http://msdn.microsoft.com/en-us/library/ms998320.aspx"&gt;How To: Use the Network Service Account to Access Resources in ASP.NET&lt;/a&gt;.&amp;#160; This document tells me exactly how to grant access.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;And now everything is working great for the people who are going to be at Tech-Ed North America 2009.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9531021" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>Installing Microsoft URL Rewrite Module on Windows 7 Beta</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/03/27/installing-microsoft-url-rewrite-module-on-windows-7-beta.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/03/27/installing-microsoft-url-rewrite-module-on-windows-7-beta.aspx</id><published>2009-03-27T17:29:06Z</published><updated>2009-03-27T17:29:06Z</updated><content type="html">&lt;p&gt;Recently I said that the IIS 7 URL rewrite module will not work on Windows 7.&amp;#160; Someone commented on my blog post that there is a &lt;a href="http://forums.iis.net/t/1155759.aspx"&gt;workaround&lt;/a&gt; posted on the iis.net site.&amp;#160; I know the IIS team says this works but I’ve tried it on multiple machines and it never works for me.&amp;#160; I have not tried it on Windows Server&amp;#160; 2008 R2 so perhaps it works there.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9514276" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>Today on endpoint.tv – The REST Collection Template</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/03/26/today-on-endpoint-tv-the-rest-collection-template.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/03/26/today-on-endpoint-tv-the-rest-collection-template.aspx</id><published>2009-03-26T20:42:45Z</published><updated>2009-03-26T20:42:45Z</updated><content type="html">&lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Endpoint/endpointtv-WCF-REST-Starter-Kit-Lab-3-REST-Collection-Service/"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="20090325endpointLab3_large_ch9[1]" border="0" alt="20090325endpointLab3_large_ch9[1]" src="http://blogs.msdn.com/blogfiles/rjacobs/WindowsLiveWriter/Todayonendpo.tvTheRESTCollectionTemplate_96A3/20090325endpointLab3_large_ch9%5B1%5D_3.png" width="244" height="184" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;One of the more interesting (challenging?) things we did with the WCF REST Starter Kit is the REST Collection Service Template.&amp;#160; The idea behind this template was to produce a service that allows you read/write access to a service using a simple REST style interface.&amp;#160; The idea is to provide both a contract and base class that takes care of most of the REST-“isms” and you simply override the methods to support your business logic.&lt;/p&gt;  &lt;p&gt;And how does this template help?&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Provides the URI templates for your service based on a very simple model of a resource per service with an ID parameter&lt;/li&gt;    &lt;li&gt;Supports content negotiation with a query string parameter i.e. “?format=json”&lt;/li&gt;    &lt;li&gt;Supports HTTP status codes such as 201 – “Created” when you add a new item or 404 – Not Found when you try to update or delete an item that does not exist&lt;/li&gt;    &lt;li&gt;Supports append to the collection via POST&lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;What do you think?&lt;/h2&gt;  &lt;p&gt;One of the reasons we are putting this out to the community in a Codeplex release is that we want to get your constructive feedback.&amp;#160;&amp;#160; Here is a good starting point.&amp;#160; Answer this question&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;&lt;em&gt;What is wrong with this template?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I’m not tying to sound defensive, I just want to know what you really think.&lt;/p&gt;  &lt;p&gt;We know that it isn’t perfect, but if you don’t like it, what do you not like about it?&amp;#160; How can we improve it?&lt;/p&gt;  &lt;p&gt;The best way to answer these questions is to give it a test drive by running through Lab 3 from the &lt;a href="http://code.msdn.microsoft.com/wcfrestlabs"&gt;WCF REST Starter Kit Hands On Labs&lt;/a&gt; so download and give it a go.&amp;#160; You can help us make it better.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9511441" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry><entry><title>RESTful Services and Business Exceptions</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rjacobs/archive/2009/03/23/restful-services-and-business-exceptions.aspx" /><id>http://blogs.msdn.com/rjacobs/archive/2009/03/23/restful-services-and-business-exceptions.aspx</id><published>2009-03-23T21:33:24Z</published><updated>2009-03-23T21:33:24Z</updated><content type="html">&lt;p&gt;Last week I had the privilege of speaking at MIX09.&amp;#160; My session &lt;a href="http://videos.visitmix.com/MIX09/T10F"&gt;RESTful Services for the Programmable Web with Windows Communication Foundation&lt;/a&gt; is already available for online viewing (pretty cool how fast they turned that around).&amp;#160; This morning I got an email from Francois who saw the session on the web and he had an excellent question.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“I just wanted to know how you deal with business exceptions (concurrency, invalid state transitions, ...) when an update or delete is performed. Do you simply return HTTP error codes? How do you do the equivalent of returning a Soap Fault?”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Great question, to answer it let me first lay some foundation then consider the second part of your question with regard to SOAP faults and finally use some examples to hopefully make this more clear.&lt;/p&gt;  &lt;h2&gt;REST and HTTP Status Codes&lt;/h2&gt;  &lt;p&gt;One of the key values of REST is that you are using a universal API known as HTTP.&amp;#160; Because of this you must try to understand the way that HTTP wants you to deal with this.&amp;#160; And how does HTTP want me to deal with this issue?&amp;#160; By using an HTTP Status code.&lt;/p&gt;  &lt;p&gt;The first line of an HTTP response is the status line – HTTP clients look to this line to understand the outcome of their request.&amp;#160; It isn’t just a matter of errors, there are many different response codes you could return or encounter when invoking RESTful services.&amp;#160;&amp;#160;&amp;#160; (For more information on the Status-Line see the &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1"&gt;HTTP spec, section 6.1&lt;/a&gt;)&lt;/p&gt;  &lt;pre&gt;       Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF&lt;/pre&gt;

&lt;p&gt;The status code comes from a long list of codes, according to the spec, the list of codes is extensible but you should follow the model based on the categories of errors&lt;/p&gt;

&lt;pre&gt;      - 1xx: Informational - Request received, continuing process
      - 2xx: Success - The action was successfully received,
        understood, and accepted
      - 3xx: Redirection - Further action must be taken in order to
        complete the request
      - 4xx: Client Error - The request contains bad syntax or cannot
        be fulfilled
      - 5xx: Server Error - The server failed to fulfill an apparently
        valid request&lt;/pre&gt;

&lt;p&gt;Even so, I would not go about creating custom HTTP status codes.&amp;#160; Instead I would try to use the commonly used status codes listed in &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"&gt;section 10 of the HTTP spec&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;REST equivalent of SOAP faults&lt;/h2&gt;

&lt;p&gt;The designers of SOAP had exceptions in mind when they created SOAP faults.&amp;#160; Previous distributed computing environments (DCOM, CORBA etc.) did not have a model for propagating exceptions across boundaries.&amp;#160; SOAP came along 10+ years after these technologies a time during which exceptions became accepted as a better way of dealing with errors.&amp;#160; Many SOAP stacks (WCF being the prime example) will catch an exception, turn it into a SOAP fault and pass it along to the client side which will unpack the message and throw an exception on the client side.&lt;/p&gt;

&lt;p&gt;SOAP faults are different than HTTP status codes because they are always errors and there is no taxonomy of errors, just whatever you want them to be.&amp;#160; In other words, the “error protocol” is application specific.&lt;/p&gt;

&lt;p&gt;In REST HTTP status codes are common and they are not always errors.&amp;#160; However the errors do fall into 2 categories 4XX (Client) and 5XX server errors.&amp;#160;&amp;#160; Now let’s consider some common scenarios where you must deal with errors and status codes.&lt;/p&gt;

&lt;h2&gt;Error Scenarios&lt;/h2&gt;

&lt;p&gt;The first class of errors you must consider are (4XX) client request errors.&amp;#160; Generally it means that the server rejected the request for some reason.&lt;/p&gt;

&lt;h3&gt;Get or Update record that does not exist&lt;/h3&gt;

&lt;p&gt;Client does an HTTP GET for a resource ID that does not exist in the database.&amp;#160; On the server you might call into the data layer to update a record an get a KeyNotFoundException (like I did in the video).&amp;#160; What happens if you do nothing?&amp;#160; Well WCF will catch all unhandled exceptions and return a status code of 500 - “Internal Server Error”.&amp;#160; This is not what you want, because it implies that the problem is a server problem.&amp;#160; &lt;/p&gt;

&lt;p&gt;In this case you should return a HTTP status code of &lt;strike&gt;400&lt;/strike&gt; 404 “Not Found”&amp;#160; (edit – 3/25 – thanks Clemens!)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;h5&gt;&lt;a&gt;10.4.1&lt;/a&gt; 400 Bad Request&lt;/h5&gt;

  &lt;p&gt;The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here is some code that processes a GET request by looking it up in a dictionary.&amp;#160; This is the fixed version of what I showed in the video.&amp;#160; As you can see I’m converting an exception into a status code by throwing a WebProtocolException.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;[OperationContract]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;[WebGet(UriTemplate = &amp;quot;&lt;span style="color: #8b0000"&gt;/{id}&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;SessionData GetSession(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; id)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _sessions[id];
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (KeyNotFoundException)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WebProtocolException(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            HttpStatusCode.NotFound);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;Add a resource with missing or invalid data&lt;/h2&gt;

&lt;p&gt;Client does an HTTP POST with missing or invalid data in the request body.&amp;#160; The server attempts to validate the request and rejects it because of the invalid or missing data.&amp;#160; The HTTP status code should be 400 – Bad request&lt;/p&gt;

&lt;h2&gt;Server Processing Errors&lt;/h2&gt;

&lt;p&gt;Suppose that the request is valid, the resource exists and for whatever reason (concurrency or some other processing error) the server cannot complete the request.&amp;#160; Then what?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;h5&gt;&lt;a&gt;10.5&lt;/a&gt; Server Error 5xx&lt;/h5&gt;

  &lt;p&gt;Response status codes beginning with the digit &amp;quot;5&amp;quot; indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You should return a HTTP status code of 500 along with some text to let the user know what is happening (if you want to).&amp;#160; Here is an example of code that would do this kind of processing.&amp;#160; &lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;[OperationContract]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;[WebInvoke(Method = &amp;quot;&lt;span style="color: #8b0000"&gt;PUT&lt;/span&gt;&amp;quot;, UriTemplate = &amp;quot;&lt;span style="color: #8b0000"&gt;/{id}&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;SessionData UpdateSession(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; id, SessionData updatedSession)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!_sessions.Contains(updatedSession.ID))
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WebProtocolException(HttpStatusCode.BadRequest);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!_sessions.IsValidSession(updatedSession))
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WebProtocolException(HttpStatusCode.BadRequest);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _sessions.Update(updatedSession);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (TimeoutException)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WebProtocolException(HttpStatusCode.InternalServerError,&amp;quot;&lt;span style="color: #8b0000"&gt;Update session timeout&lt;/span&gt;&amp;quot;,&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;WebProtocolException does provide mechanisms for passing more detail in a SOAP Fault like way as a part of the HTTP response body.&amp;#160; Sounds like a good topic for my next post.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9502166" width="1" height="1"&gt;</content><author><name>ronjacobs</name><uri>http://blogs.msdn.com/members/ronjacobs.aspx</uri></author></entry></feed>