<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The Problem Solver</title><link>http://msmvps.com/blogs/theproblemsolver/default.aspx</link><description>Tell me and I will forget&lt;br /&gt;
Show me and I will remember&lt;br /&gt;
Involve me and I will understand&lt;br /&gt;
- Confucius -</description><dc:language>en</dc:language><generator>CommunityServer 2008 SP1 (Build: 30619.63)</generator><item><title>Changing a Declarative Rule Condition at runtime</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/09/04/changing-a-declarative-rule-condition-at-runtime.aspx</link><pubDate>Thu, 04 Sep 2008 19:27:39 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1646799</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1646799</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/09/04/changing-a-declarative-rule-condition-at-runtime.aspx#comments</comments><description>&lt;p&gt;One powerful feature of a workflow is that a workflow can be changed at runtime. Like other powerful features this is something that should be done with care but it can be a real life saver at times.&lt;/p&gt; &lt;p&gt;One of the things that you can change are Declarative Rule Conditions. However as these rules are really CodeDom objects it can be a bit tricky to find the right property to change. However once you know a little tick life is much easier. &lt;/p&gt; &lt;p&gt;The trick is in the .rules file created when you add a Declarative Rule Condition to the workflow and is best demonstrated using a small example. Take the following workflow:&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.ChangingaDeclarativeRuleConditionatrunti_5F00_F69E/image_5F00_2.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="273" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.ChangingaDeclarativeRuleConditionatrunti_5F00_F69E/image_5F00_thumb.png" width="317" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The IfElseActivity has a Declarative Rule Condition which looks like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.ChangingaDeclarativeRuleConditionatrunti_5F00_F69E/image_5F00_4.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="187" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.ChangingaDeclarativeRuleConditionatrunti_5F00_F69E/image_5F00_thumb_5F00_1.png" width="377" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;So I consider every amount larger that 100 large. Hmm not much, lets change that to 1000 instead of 100 &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt; &lt;p&gt;The first step is we need to change the workflow instance so we need a WorkflowChanges object passing in the workflow root as the activity. No big deal but what now. Well lets open the Workflow1.Rules file and take a look at what is inside.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleDefinitions &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/winfx/2006/xaml/workflow&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleDefinitions.Conditions&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleExpressionCondition &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;LargeAmountRule&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleExpressionCondition.Expression&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodeBinaryOperatorExpression &lt;/span&gt;&lt;span style="color:red;"&gt;Operator&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;GreaterThan&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;xmlns:ns0&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodeBinaryOperatorExpression.Left&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePropertyReferenceExpression &lt;/span&gt;&lt;span style="color:red;"&gt;PropertyName&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Amount&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePropertyReferenceExpression.TargetObject&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodeThisReferenceExpression &lt;/span&gt;&lt;span style="color:blue;"&gt;/&amp;gt;
                            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePropertyReferenceExpression.TargetObject&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePropertyReferenceExpression&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodeBinaryOperatorExpression.Left&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodeBinaryOperatorExpression.Right&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePrimitiveExpression&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePrimitiveExpression.Value&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns1:Int32 &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns:ns1&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;100&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns1:Int32&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePrimitiveExpression.Value&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodePrimitiveExpression&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodeBinaryOperatorExpression.Right&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ns0:CodeBinaryOperatorExpression&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleExpressionCondition.Expression&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleExpressionCondition&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleDefinitions.Conditions&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RuleDefinitions&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It turns out that the XML is a very literal representation of the objects that make up our rule and what we need to change. So we need to start with a RuleDefinitions.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;RuleDefinitions &lt;/span&gt;rules =
    (&lt;span style="color:#2b91af;"&gt;RuleDefinitions&lt;/span&gt;)changes.TransientWorkflow.GetValue(&lt;span style="color:#2b91af;"&gt;RuleDefinitions&lt;/span&gt;.RuleDefinitionsProperty);
&lt;/pre&gt;
&lt;p&gt;So getting our hand on it is easy, just use the GetValue function passing in the RuleDefinitionsProperty dependency property.&lt;/p&gt;
&lt;p&gt;Once we have this things are even easier as it is just following the XML &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;. It shows the RuleDefinitions object has a Conditions property and our rule is in there with a name LargeAmountRule and is of type RuleExpressionCondition. This rule in turn contains a left and right part with the right part pointing at the value of 100 we want to change. Again this value is of a type CodePrimitiveExpression, another easy cast. The code below is the complete code required to change the value from 100 to1000.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;WorkflowChanges &lt;/span&gt;changes = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WorkflowChanges&lt;/span&gt;(&lt;span style="color:blue;"&gt;this&lt;/span&gt;);

&lt;span style="color:#2b91af;"&gt;RuleDefinitions &lt;/span&gt;rules =
    (&lt;span style="color:#2b91af;"&gt;RuleDefinitions&lt;/span&gt;)changes.TransientWorkflow.GetValue(&lt;span style="color:#2b91af;"&gt;RuleDefinitions&lt;/span&gt;.RuleDefinitionsProperty);

&lt;span style="color:#2b91af;"&gt;RuleExpressionCondition &lt;/span&gt;rule = (&lt;span style="color:#2b91af;"&gt;RuleExpressionCondition&lt;/span&gt;)rules.Conditions
    .First(rc =&amp;gt; rc.Name == &lt;span style="color:#a31515;"&gt;&amp;quot;LargeAmountRule&amp;quot;&lt;/span&gt;);
&lt;span style="color:#2b91af;"&gt;CodeBinaryOperatorExpression &lt;/span&gt;expression = (&lt;span style="color:#2b91af;"&gt;CodeBinaryOperatorExpression&lt;/span&gt;)rule.Expression;
&lt;span style="color:#2b91af;"&gt;CodePrimitiveExpression &lt;/span&gt;primitive = (&lt;span style="color:#2b91af;"&gt;CodePrimitiveExpression&lt;/span&gt;)expression.Right;
primitive.Value = 1000;

ApplyWorkflowChanges(changes);
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Easy once you know where to look &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.theproblemsolver.nl/"&gt;www.TheProblemSolver.nl &lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.windowsworkflowfoundation.eu/"&gt;Wiki.WindowsWorkflowFoundation.eu&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1646799" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category></item><item><title>Calling WCF services from a Silverlight 2 app.</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/26/calling-wcf-services-from-a-silverlight-2-app.aspx</link><pubDate>Mon, 25 Aug 2008 22:11:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1645795</guid><dc:creator>Maurice</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1645795</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/26/calling-wcf-services-from-a-silverlight-2-app.aspx#comments</comments><description>&lt;p&gt;As far as I am concerned Silverlight 2 is pretty cool and should have been developed years ago &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;. Well guess that isn&amp;#39;t the case but it is here now.&lt;/p&gt;
&lt;p&gt;One thing I like about Silverlight is how easy it is to call a web service. I guess that is a must be because when developing a LOB application in Silverlight you are going to be calling your server to get and store data. So calling the back end is as easy as adding a new Silverlight-enabled WCF Service, implementing the ServiceContract and setting a service reference from your Silverlight project. Things will work immediately and you are all good to go.&lt;/p&gt;
&lt;h2&gt;Or maybe not &lt;img src="http://msmvps.com/emoticons/emotion-6.gif" alt="Sad" /&gt;&lt;/h2&gt;
&lt;p&gt;Well your service will work just fine in your development machine, no problems there. But when you move your project to another machine thing might just stop working and you will see a ProtocolException with message &amp;quot;The remote server returned an unexpected response: (404) Not Found.&amp;quot;. &lt;/p&gt;
&lt;p&gt;So what gives?&lt;/p&gt;
&lt;p&gt;Well the problem is that the WCF stores the absolute Uri for the WCF service in its configuration file, the ServiceReferences.ClientConfig. In this case the configuration looks like this:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configuration&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bindings&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;binding &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;BasicHttpBinding_Service&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;maxBufferSize&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;65536&lt;/span&gt;&amp;quot;
                    &lt;span style="color:red;"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;65536&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;security &lt;/span&gt;&lt;span style="color:red;"&gt;mode&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;None&lt;/span&gt;&amp;quot; &lt;span style="color:blue;"&gt;/&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;binding&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bindings&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;client&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;endpoint &lt;/span&gt;&lt;span style="color:red;"&gt;address&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://localhost:4370/SilverlightApplication3Web/Service.svc&lt;/span&gt;&amp;quot;
                &lt;span style="color:red;"&gt;binding&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;basicHttpBinding&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;BasicHttpBinding_Service&lt;/span&gt;&amp;quot;
                &lt;span style="color:red;"&gt;contract&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;SilverlightApplication3.ServiceReference1.Service&lt;/span&gt;&amp;quot;
                &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;BasicHttpBinding_Service.&lt;/span&gt;&amp;quot; &lt;span style="color:blue;"&gt;/&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;client&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configuration&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The problem here is the endpoint address that points to localhost port 4370. So as this service is part of the same website using a relative Uri sounds like the reasonable thing to do. Unfortunately this doesn&amp;#39;t work and results in an UriFormatException with message: &amp;quot;Invalid URI: The format of the URI could not be determined.&amp;quot;. Not good. So this means we have to change the address for every local endpoint when we move the Silverlight application, and its WCF services, to a different location. Not good, specially when we could have a long list of services used &lt;img src="http://msmvps.com/emoticons/emotion-6.gif" alt="Sad" /&gt;.&lt;/p&gt;
&lt;h2&gt;A partial solution&lt;/h2&gt;
&lt;p&gt;So fortunately there is a way around this as we can specify the service address when creating the WCF service proxy, all we need to do is insert the correct Uri based upon the location of the Silverlight application.&lt;/p&gt;
&lt;p&gt;Normally the code I write looks something like this:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;ServiceClient &lt;/span&gt;proxy = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ServiceClient&lt;/span&gt;();
proxy.DoWorkCompleted += proxy_DoWorkCompleted;
proxy.DoWorkAsync();
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What I need to do is change this somewhat so that the ServiceClient is created through a factory method like this:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;ServiceClient &lt;/span&gt;proxy = GetServiceClient();
proxy.DoWorkCompleted += proxy_DoWorkCompleted;
proxy.DoWorkAsync();
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The interesting work occurs in the GetServiceClient() function:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ServiceClient &lt;/span&gt;GetServiceClient()
{
    &lt;span style="color:#2b91af;"&gt;Uri &lt;/span&gt;uri = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Uri&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;HtmlPage&lt;/span&gt;.Document.DocumentUri, &lt;span style="color:#a31515;"&gt;&amp;quot;Service.svc&amp;quot;&lt;/span&gt;);
    &lt;span style="color:#2b91af;"&gt;EndpointAddress &lt;/span&gt;address = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EndpointAddress&lt;/span&gt;(uri);

    &lt;span style="color:blue;"&gt;return new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ServiceClient&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, address);
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;First I determine where the Silverlight application was loaded from in the first place through the HtmlPage.Document.DocumentUri. Next I create a new Uri with the relative address where the service should be located. And finally I create and return the WCF proxy object. The first parameter, the&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;*&amp;quot; &lt;/span&gt;indicated that the WCF runtime should use a wildcard match and the first endpoint found with the same contract, which is the same as when no parameters are passed in.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;A better solution&lt;/h2&gt;
&lt;p&gt;Of course the solution above works but requires extra coding and care with every service we create. And being easy to forget, specially when you just get started with Silverlight, is not exactly an ideal solution. So the proper solution is that the WCF stack inside of Silverlight should accept relative Uri and understand that this Uri is relative to the current page. Now this is not exactly rocket science and exactly what browsers have been doing for years. So lets hope the Silverlight team adds this feature before the RTM (which I hope is real soon).&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.theproblemsolver.nl/"&gt;www.TheProblemSolver.nl &lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.windowsworkflowfoundation.eu/"&gt;Wiki.WindowsWorkflowFoundation.eu&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1645795" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WCF/default.aspx">WCF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Using an IronPython runtime service from Windows Workflow Foundation</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/25/using-an-ironpython-runtime-service-from-windows-workflow-foundation.aspx</link><pubDate>Mon, 25 Aug 2008 10:15:18 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1645704</guid><dc:creator>Maurice</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1645704</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/25/using-an-ironpython-runtime-service-from-windows-workflow-foundation.aspx#comments</comments><description>&lt;p&gt;In &lt;a href="http://msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx"&gt;this post&lt;/a&gt; I demonstrated how to create &lt;a href="http://www.codeplex.com/IronPython"&gt;IronPython&lt;/a&gt; objects and call them from strongly typed .NET code. So suppose we want to do so with &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/Workflow%20Foundation.html"&gt;Windows Workflow Foundation&lt;/a&gt; where could we use this?&lt;/p&gt; &lt;p&gt;Well the most obvious place would be a &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/WorkflowRuntimeService.html"&gt;runtime service&lt;/a&gt;. The example below uses a very simple message that needs to be displayed but it is easy to see how to same concept could be applied in other places.&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.UsinganIronPythonruntimeservicefromWindo_5F00_A4C6/image_5F00_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="337" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.UsinganIronPythonruntimeservicefromWindo_5F00_A4C6/image_5F00_thumb.png" width="541" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;But first the basics. I have created a very simple custom DisplayMessageActivity like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DisplayMessageActivity &lt;/span&gt;: System.Workflow.ComponentModel.&lt;span style="color:#2b91af;"&gt;Activity
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;DisplayMessageActivity()
    {
    }

    &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Message { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color:blue;"&gt;protected override &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus &lt;/span&gt;Execute(
        &lt;span style="color:#2b91af;"&gt;ActivityExecutionContext &lt;/span&gt;executionContext)
    {
        &lt;span style="color:#2b91af;"&gt;IDisplayMessageService &lt;/span&gt;service = executionContext.GetService&amp;lt;&lt;span style="color:#2b91af;"&gt;IDisplayMessageService&lt;/span&gt;&amp;gt;();
        service.Display(Message);

        &lt;span style="color:blue;"&gt;return base&lt;/span&gt;.Execute(executionContext);
    }
}
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Next I have created a very simple workflow with only the DisplayMessageActivity and set the Message property to: &amp;quot;This is the message to show.&amp;quot;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You might have noticed in the code above that I am looking for a service of type &lt;span style="color:#2b91af;"&gt;IDisplayMessageService&lt;/span&gt;. This is pretty simple as well and looks like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public interface &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IDisplayMessageService
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;void &lt;/span&gt;Display(&lt;span style="color:blue;"&gt;string &lt;/span&gt;message);
}
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;In this case I am using an interface but you could just as well use a concrete baseclass with virtual methods.&lt;/p&gt;
&lt;p&gt;For the actual implementation I created two classes in IronPython, the first displays the message on the console while the second uses a MessageBox to display the same message. The IronPython source looks like this:&lt;/p&gt;&lt;pre class="code"&gt;import clr

clr.AddReference(&amp;#39;PythonWorkflowConsoleApplication1&amp;#39;)
from PythonWorkflowConsoleApplication1 import IDisplayMessageService

clr.AddReference(&amp;quot;System.Windows.Forms&amp;quot;)
from System.Windows.Forms import MessageBox

# Display all messages in the console window
class ConsoleDisplayMessageService(IDisplayMessageService):
    def Display(self, message):
        print message

# Display all messages using a Windows.Forms.MessageBox
class MessageBoxDisplayMessageService(IDisplayMessageService):
    def Display(self, message):
        MessageBox.Show(message, &amp;#39;IronPython&amp;#39;)
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Like in the previous example I first import the clr so I can set references to additional assemblies. Next add a reference to the PythonWorkflowConsoleApplication1 assembly. This is my sample application that contains the runtime service interface definition. With this reference set I can import the IDisplayMessageService interface so I can derive from it. &lt;/p&gt;
&lt;p&gt;I included two implementations, lets first look at the ConsoleDisplayMessageService as this is the simpler of the two. All this does is use the Python print function to display the message on the console. The first parameter, self, is the current object, so this in C# or me in VB. We make sure this class derives from IDisplayMessageService by specifying this after the class name. BTW the lines starting with # are comments in Python.&lt;/p&gt;
&lt;p&gt;The second class is MessageBoxDisplayMessageService and this actually uses a MessageBox to display the message from the workflow. First we need to add a reference to the System.Windows.Forms assembly and once that is done we need to import the MessageBox type. Once this is done we can use it like this: &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(message, &amp;#39;IronPython&amp;#39;)&lt;/p&gt;
&lt;p&gt;Simple enough right.&lt;/p&gt;
&lt;p&gt;So now for the trick part, adding the IronPython runtime service to the workflow runtime.&lt;/p&gt;
&lt;p&gt;The console main function is as follows:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;static void &lt;/span&gt;Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)
{
    &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;WorkflowRuntime &lt;/span&gt;workflowRuntime = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WorkflowRuntime&lt;/span&gt;())
    {
        AddMessageService(workflowRuntime, &lt;span style="color:#2b91af;"&gt;DisplayMode&lt;/span&gt;.Windows);

        &lt;span style="color:#2b91af;"&gt;WorkflowInstance &lt;/span&gt;instance = workflowRuntime.CreateWorkflow(
            &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(PythonWorkflowConsoleApplication1.&lt;span style="color:#2b91af;"&gt;Workflow1&lt;/span&gt;));
        instance.Start();

        &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.ReadLine();
    }
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;With the AddMessageService() doing the actual work. Note the second parameter specifies which IronPython class to load.&lt;/p&gt;
&lt;p&gt;So the AddMessageService looks like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;static void &lt;/span&gt;AddMessageService(&lt;span style="color:#2b91af;"&gt;WorkflowRuntime &lt;/span&gt;workflowRuntime, &lt;span style="color:#2b91af;"&gt;DisplayMode &lt;/span&gt;mode)
{
    &lt;span style="color:blue;"&gt;string &lt;/span&gt;className;
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(mode == &lt;span style="color:#2b91af;"&gt;DisplayMode&lt;/span&gt;.Console)
        className = &lt;span style="color:#a31515;"&gt;&amp;quot;ConsoleDisplayMessageService&amp;quot;&lt;/span&gt;;
    &lt;span style="color:blue;"&gt;else
        &lt;/span&gt;className = &lt;span style="color:#a31515;"&gt;&amp;quot;MessageBoxDisplayMessageService&amp;quot;&lt;/span&gt;;

    &lt;span style="color:#2b91af;"&gt;ScriptRuntime &lt;/span&gt;runtime = &lt;span style="color:#2b91af;"&gt;PythonEngine&lt;/span&gt;.CurrentEngine.Runtime;
    &lt;span style="color:#2b91af;"&gt;ScriptScope &lt;/span&gt;scope = runtime.ExecuteFile(&lt;span style="color:#a31515;"&gt;&amp;quot;DisplayMessageService.py&amp;quot;&lt;/span&gt;);

    &lt;span style="color:#2b91af;"&gt;PythonType &lt;/span&gt;pythonType = scope.GetVariable&amp;lt;&lt;span style="color:#2b91af;"&gt;PythonType&lt;/span&gt;&amp;gt;(className);
    &lt;span style="color:blue;"&gt;object &lt;/span&gt;service = runtime.Operations.Call(pythonType);

    workflowRuntime.AddService(service);
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;The basics are the same as in my &lt;a href="http://msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx"&gt;previous&lt;/a&gt; IronPython post. Depending on the display mode I make a choice of class to load and I use the same code as previous time to create the object. Finally I add it to the &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/WorkflowRuntime.html"&gt;WorkflowRuntime&lt;/a&gt; as a &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/WorkflowRuntimeService.html"&gt;runtime service&lt;/a&gt;. This last bit is easy as this accepts every object type as a valid service and only when we call the GetService do we check the actual type.&lt;/p&gt;
&lt;p&gt;I used IronPython 2.0 Beta 4 for this example. More info about IronPython can be found &lt;a href="http://www.codeplex.com/IronPython"&gt;here&lt;/a&gt;, the download of version 2 &lt;a href="http://www.codeplex.com/IronPython/Release/ProjectReleases.aspx?ReleaseId=14353"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.theproblemsolver.nl/"&gt;www.TheProblemSolver.nl &lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.windowsworkflowfoundation.eu/"&gt;Wiki.WindowsWorkflowFoundation.eu&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1645704" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/IronPython/default.aspx">IronPython</category></item><item><title>Red Gate to continue development of .NET Reflector</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/20/red-gate-to-continue-development-of-net-reflector.aspx</link><pubDate>Wed, 20 Aug 2008 07:04:54 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1645153</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1645153</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/20/red-gate-to-continue-development-of-net-reflector.aspx#comments</comments><description>&lt;p&gt;.NET Reflector, by Lutz Roeder, must be one of the most useful tools I have when developing .NET code. Usually it is the first thing I install right after Visual Studio not even waiting until I need it because I know I will.&lt;/p&gt; &lt;p&gt;So the big news is that Red Gate, makers of the Ants profiler and lots of other tools, are taking over from Lutz Roeder and will continue developing .NET Reflector. Interesting move and I hope this means a bright future for the .NET Reflector.&lt;/p&gt; &lt;p&gt;Read more about this &lt;a href="http://www.simple-talk.com/reflector/interview.htm"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.theproblemsolver.nl/"&gt;www.TheProblemSolver.nl &lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.windowsworkflowfoundation.eu/"&gt;Wiki.WindowsWorkflowFoundation.eu&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1645153" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WCF/default.aspx">WCF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WPF/default.aspx">WPF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>Two useful batch files when testing with Windows Workflow Foundation</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/19/two-useful-batch-files-when-testing-with-windows-workflow-foundation.aspx</link><pubDate>Tue, 19 Aug 2008 14:21:48 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1645075</guid><dc:creator>Maurice</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1645075</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/19/two-useful-batch-files-when-testing-with-windows-workflow-foundation.aspx#comments</comments><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;The following are two batch files I use a lot when working with WF persistence and or tracking as I find it desirable to clear the out often. Just drop them in the &amp;quot;C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN&amp;quot; directory with the four SQL scripts and recreating the required databases is just a few clicks away.&lt;/p&gt; &lt;h2&gt;CreatePersistence.bat&lt;/h2&gt; &lt;p&gt;osql -E -S .\sqlexpress -Q &amp;quot;Drop Database WorkflowPersistence&amp;quot;&lt;br /&gt;osql -E -S .\sqlexpress -Q &amp;quot;Create Database WorkflowPersistence&amp;quot; &lt;br /&gt;osql -E -S .\sqlexpress -d WorkflowPersistence -i SqlPersistenceService_Schema.sql&lt;br /&gt;osql -E -S .\sqlexpress -d WorkflowPersistence -i SqlPersistenceService_Logic.sql &lt;p&gt;&amp;nbsp; &lt;h2&gt;CreateTracking.bat&lt;/h2&gt; &lt;p&gt;osql -E -S .\sqlexpress -Q &amp;quot;Drop Database WorkflowTracking&amp;quot;&lt;br /&gt;osql -E -S .\sqlexpress -Q &amp;quot;Create Database WorkflowTracking&amp;quot; &lt;br /&gt;osql -E -S .\sqlexpress -d WorkflowTracking -i Tracking_Schema.sql&lt;br /&gt;osql -E -S .\sqlexpress -d WorkflowTracking -i Tracking_Logic.sql &lt;p&gt;&amp;nbsp; &lt;p&gt;Of course you could also use my SqlCeWFPersistence as the persistence service, download it from &lt;a href="http://code.msdn.microsoft.com/SqlCeWFPersistence"&gt;here&lt;/a&gt;. I never did create a TrackingService based upon SQL Compact but if enough people are interested I might just do so &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt; &lt;p&gt;Enjoy! &lt;p&gt;&lt;a href="http://www.theproblemsolver.nl/"&gt;www.TheProblemSolver.nl &lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.windowsworkflowfoundation.eu/"&gt;Wiki.windowsworkflowfoundation.eu&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1645075" width="1" height="1"&gt;</description></item><item><title>.NET Framework 3.5 Enhancements Training Kit</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/19/net-framework-3-5-enhancements-training-kit.aspx</link><pubDate>Tue, 19 Aug 2008 10:32:52 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1645044</guid><dc:creator>Maurice</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1645044</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/19/net-framework-3-5-enhancements-training-kit.aspx#comments</comments><description>&lt;p&gt;Want to know what is new in the .NET 3.5 SP1 framework or Visual Studio 2008 SP1? Then check out the presentations and labs here: &lt;a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=355C80E9-FDE0-4812-98B5-8A03F5874E96&amp;amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=355C80E9-FDE0-4812-98B5-8A03F5874E96&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=355C80E9-FDE0-4812-98B5-8A03F5874E96&amp;amp;displaylang=en&lt;/a&gt;&lt;/p&gt; &lt;h2&gt;&amp;nbsp;&lt;/h2&gt; &lt;h2&gt;Overview&lt;/h2&gt; &lt;p&gt;The .NET Framework 3.5 Enhancements Training Kit includes presentations, hands-on labs, demos, and event materials. This content is designed to help you learn how to utilize the .NET 3.5 Enhancement features including: ASP.NET MVC, ASP.NET Dynamic Data, ASP.NET AJAX History, ASP.NET Routing, ADO.NET Data Services, ADO.NET Entity Framework, WCF 3.5 SP1, and the .NET Framework Client Profile.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now this is nowhere near complete but a good place to start.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1645044" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>Calling IronPython functions from .NET</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx</link><pubDate>Thu, 14 Aug 2008 18:17:19 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1644675</guid><dc:creator>Maurice</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1644675</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx#comments</comments><description>&lt;p&gt;Having worked with Python in the past I find IronPython an interesting language to work with. However the story becomes really interesting if you can combine IronPython with regular strong typed code into one.&lt;/p&gt; &lt;p&gt;So I decided to take a look at what it would take to do so with the current IronPython version. I used IronPython 2 Beta 3, based upon the current version of the Dynamic Language Runtime, which is still evolving so the classes might have changed, take care! You can download the latest IronPython release &lt;a href="http://www.codeplex.com/IronPython"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;Lets take a look at what it takes to use an IronPython class from a Visual Basic Project.&lt;/h3&gt; &lt;p&gt; The first thing we need is a base class we are actually going to derive from. This is because IronPython doesn&amp;#39;t compile its code into a static type but VB requires its variables to be typed. This is the base class I am using:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;Public Class &lt;/span&gt;HelloWorldVB
    &lt;span style="color:blue;"&gt;Public Overridable Function &lt;/span&gt;HelloWorld(&lt;span style="color:blue;"&gt;ByVal &lt;/span&gt;name &lt;span style="color:blue;"&gt;As String&lt;/span&gt;) &lt;span style="color:blue;"&gt;As String
        Return String&lt;/span&gt;.Format(&lt;span style="color:#a31515;"&gt;&amp;quot;Hello &amp;#39;{0}&amp;#39; from Visual Basic&amp;quot;&lt;/span&gt;, name)
    &lt;span style="color:blue;"&gt;End Function
End Class
&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;And a main module to start thing off:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;Sub &lt;/span&gt;Main()

    &lt;span style="color:blue;"&gt;Dim &lt;/span&gt;helloWorld &lt;span style="color:blue;"&gt;As New &lt;/span&gt;HelloWorldVB()
    Console.WriteLine(helloWorld.HelloWorld(&lt;span style="color:#a31515;"&gt;&amp;quot;Maurice&amp;quot;&lt;/span&gt;))

    Console.ReadLine()
&lt;span style="color:blue;"&gt;End Sub
&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;No big surprise here &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;So how do we derive an IronPython class from our VB type?&lt;/h3&gt;
&lt;p&gt;The following code is the IronPython code I added to the file HelloWorld.py.&lt;/p&gt;&lt;pre class="code"&gt;import clr
clr.AddReference(&amp;#39;IronPythonTest2&amp;#39;)
from IronPythonTest2 import HelloWorldVB

class HelloWorldIronPython(HelloWorldVB):
    def HelloWorld(self, name):
        return &amp;quot;Hello &amp;#39;&amp;quot; + name + &amp;quot;&amp;#39; from IronPython&amp;quot;
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Basically this code adds a reference to the IronPythonTest2 assembly, this is my console application containing the previous VB code. Next it imports the HelloWorldVB type from the assembly. Now it know about the type we can go ahead and derive from that type and create a new one. This exactly what the line class HelloWorldIronPython(HelloWorldVB) does, it creates a new type called HelloWorldIronPython. Next we override the HelloWorld function and return a different welcome string. A few things to note here: Python uses indentation to specify blocks, so the function being indented from the class is a part of that and the line of code with the return is indented from the def that defines the function so it is part of the function body. Another interesting thing is the self parameter. Every function in Python is passed a reference to itself as the first parameter. Sort of like the implicit Me in VB except a bit more obvious.&lt;/p&gt;
&lt;p&gt;If you want to know more about IronPython I suggest you get the book &lt;a href="http://www.manning.com/foord/"&gt;IronPython in Action&lt;/a&gt; from &lt;a href="http://www.voidspace.org.uk/python/weblog/index.shtml"&gt;Michael Foord&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.manning.com/foord/foord_cover150.jpg" alt="" /&gt; &lt;/p&gt;
&lt;p&gt;To make sure the HelloWorld.py file is available to the console application I have set the&amp;nbsp; Copy to Output Directory to Copy always.&lt;/p&gt;
&lt;p&gt;OK so far so good. We have an IronPython class with the code we need. Now we still need to create an object from it. This isn&amp;#39;t hard it just takes a bit more doing than just using the New operator.&lt;/p&gt;
&lt;h3&gt;Instantiating the IronPython object&lt;/h3&gt;
&lt;p&gt;The first step is adding the required references. We need to add the following assemblies:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;IronPython.dll&lt;/li&gt;
&lt;li&gt;IronPython.Modules.dll&lt;/li&gt;
&lt;li&gt;Microsoft.Scripting.dll&lt;/li&gt;
&lt;li&gt;Microsoft.Scripting.Core.dll&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;We will only be using the 1st and 3rd ourselves but the others are needed as well.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Once we have the references set we can add the required Imports:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;Imports &lt;/span&gt;Microsoft.Scripting.Hosting
&lt;span style="color:blue;"&gt;Imports &lt;/span&gt;IronPython.Hosting
&lt;span style="color:blue;"&gt;Imports &lt;/span&gt;IronPython.Runtime.Types
&lt;/pre&gt;
&lt;p&gt;And now we can get really going with the code &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt;
&lt;p&gt;We need to load the file with the Python source code using an IronPython ScriptRuntime. Once done we can get a reference to the IronPython type object using the GetVariable() function by passing in the class name. Once we have that we call the ScriptRuntime again to actually create the object. See the code below:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;Dim &lt;/span&gt;runtime &lt;span style="color:blue;"&gt;As &lt;/span&gt;ScriptRuntime = PythonEngine.CurrentEngine.Runtime
&lt;span style="color:blue;"&gt;Dim &lt;/span&gt;scope &lt;span style="color:blue;"&gt;As &lt;/span&gt;ScriptScope = runtime.ExecuteFile(&lt;span style="color:#a31515;"&gt;&amp;quot;HelloWorld.py&amp;quot;&lt;/span&gt;)
&lt;span style="color:blue;"&gt;Dim &lt;/span&gt;pythonType &lt;span style="color:blue;"&gt;As &lt;/span&gt;PythonType = scope.GetVariable(&lt;span style="color:blue;"&gt;Of &lt;/span&gt;PythonType)(&lt;span style="color:#a31515;"&gt;&amp;quot;HelloWorldIronPython&amp;quot;&lt;/span&gt;)
helloWorld = &lt;span style="color:blue;"&gt;CType&lt;/span&gt;(runtime.Operations.Call(pythonType), HelloWorldVB)
Console.WriteLine(helloWorld.HelloWorld(&lt;span style="color:#a31515;"&gt;&amp;quot;Maurice&amp;quot;&lt;/span&gt;))
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And with this code we are good to go. Running the complete code will show the output below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.CallingIronPythonfunctionsfrom.NET_5F00_113A8/image_5F00_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="146" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.CallingIronPythonfunctionsfrom.NET_5F00_113A8/image_5F00_thumb.png" width="335" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The complete code in the main module:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;Option Explicit On
Option Strict On

Imports &lt;/span&gt;Microsoft.Scripting.Hosting
&lt;span style="color:blue;"&gt;Imports &lt;/span&gt;IronPython.Hosting
&lt;span style="color:blue;"&gt;Imports &lt;/span&gt;IronPython.Runtime.Types

&lt;span style="color:blue;"&gt;Module &lt;/span&gt;Module1
    &lt;span style="color:blue;"&gt;Sub &lt;/span&gt;Main()
        &lt;span style="color:blue;"&gt;Dim &lt;/span&gt;helloWorld &lt;span style="color:blue;"&gt;As New &lt;/span&gt;HelloWorldVB()
        Console.WriteLine(helloWorld.HelloWorld(&lt;span style="color:#a31515;"&gt;&amp;quot;Maurice&amp;quot;&lt;/span&gt;))

        &lt;span style="color:blue;"&gt;Dim &lt;/span&gt;runtime &lt;span style="color:blue;"&gt;As &lt;/span&gt;ScriptRuntime = PythonEngine.CurrentEngine.Runtime
        &lt;span style="color:blue;"&gt;Dim &lt;/span&gt;scope &lt;span style="color:blue;"&gt;As &lt;/span&gt;ScriptScope = runtime.ExecuteFile(&lt;span style="color:#a31515;"&gt;&amp;quot;HelloWorld.py&amp;quot;&lt;/span&gt;)
        &lt;span style="color:blue;"&gt;Dim &lt;/span&gt;pythonType &lt;span style="color:blue;"&gt;As &lt;/span&gt;PythonType = scope.GetVariable(&lt;span style="color:blue;"&gt;Of &lt;/span&gt;PythonType)(&lt;span style="color:#a31515;"&gt;&amp;quot;HelloWorldIronPython&amp;quot;&lt;/span&gt;)
        helloWorld = &lt;span style="color:blue;"&gt;CType&lt;/span&gt;(runtime.Operations.Call(pythonType), HelloWorldVB)
        Console.WriteLine(helloWorld.HelloWorld(&lt;span style="color:#a31515;"&gt;&amp;quot;Maurice&amp;quot;&lt;/span&gt;))

        Console.ReadLine()
    &lt;span style="color:blue;"&gt;End Sub
End Module
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1644675" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/IronPython/default.aspx">IronPython</category></item><item><title>Book review: Pro WF by Bruce Bukovics</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/13/book-review-pro-wf-by-bruce-bukovics.aspx</link><pubDate>Wed, 13 Aug 2008 19:16:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1644558</guid><dc:creator>Maurice</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1644558</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/13/book-review-pro-wf-by-bruce-bukovics.aspx#comments</comments><description>&lt;p&gt;Windows Workflow Foundation, WF for short, is one of the technologies I work a lot with and as a consequence I own several books about WF. Comparing this book with the others I can only say it is one of the best books you can get on the subject. It has a good coverage of almost all the subject you are going to need to know. Not only is there a good coverage but the explanation and examples are very clear. Now there are a few thing missing from the book. As it was written with the .NET framework 3.0 there is no coverage of the WCF integration that comes in the form of the SendActivity and the ReceiveActivity. While this is unfortunate it is also understandable and I can only hope that the author has the time to update the book with one more chapter.  &lt;p&gt;&lt;a href="http://books.google.nl/books?id=s5eVXpNmQxgC&amp;amp;dq=pro+wf"&gt;&lt;img src="http://bks0.books.google.nl/books?id=s5eVXpNmQxgC&amp;amp;printsec=frontcover&amp;amp;img=1&amp;amp;zoom=1&amp;amp;sig=ACfU3U1FW26DezRy5hL6Uyfx1a0Ma0prAg" alt="" /&gt;&lt;/a&gt;  &lt;p&gt;For a book this size, about 700 pages, I was amazed at how little I could find that I didn&amp;#39;t like. In fact one of few errors I could find is the statement that only a single instance of the WorkflowRuntime can be created per AppDomain. This is a myth that stems back to the first beta&amp;#39;s where it was briefly the case but the restriction has been lifted long ago and has never been part of the released product. But given the size of the book and how few people ever need to create multiple WorkflowRuntime objects it is hardly a big objection.  &lt;p&gt;So my advise: If you are getting into Windows Workflow Foundation make sure you buy this book!  &lt;p&gt;&amp;nbsp; &lt;p&gt;Enjoy.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1644558" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category></item><item><title>Using a TransactionScopeActivity within a ReceiveActivity in a state machine workflow</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/13/using-a-transactionscopeactivity-within-a-receiveactivity-in-a-state-machine-workflow.aspx</link><pubDate>Wed, 13 Aug 2008 10:31:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1644506</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1644506</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/13/using-a-transactionscopeactivity-within-a-receiveactivity-in-a-state-machine-workflow.aspx#comments</comments><description>&lt;p&gt;In two previous blog posts, &lt;a href="http://msmvps.com/blogs/theproblemsolver/archive/2008/08/06/using-a-transactionscopeactivity-with-a-wcf-receiveactivity.aspx"&gt;part one&lt;/a&gt; and &lt;a href="http://msmvps.com/blogs/theproblemsolver/archive/2008/08/08/more-on-using-a-transactionscopeactivity-within-a-receiveactivity.aspx"&gt;part two&lt;/a&gt;, I covered the fact that the ReceiveActivity and the TransactionScopeActivity don&amp;#39;t work together very well. I demonstrated this using a sequential workflow and did show a, clumsy and hacky, workaround to get at least the initial request working. So while the request that starts the sequential workflow could work the same is not true for any subsequent calls.&lt;/p&gt; &lt;h2&gt;But what about a state workflow?&lt;/h2&gt; &lt;p&gt;State workflow&amp;#39;s are very different then sequential workflow&amp;#39;s because they are completely event driven. With every state you need to add an EventDrivenActivity and the first child should implement the IEventActivity interface. Well the ReceiveActivity does just that so we can use it to initiate a state machine workflow and triggers its events. However as you might expect a TransactionScopeActivity is not an IEventActivity so it cannot be the first child of the EventDrivenActivity. And that means you cannot wrap the ReceiveActivity inside of an TransactionScopeActivity, something that sort of solved the problem with a sequential workflow. Of course nesting the TransactionScopeActivity inside of the ReceiveActivity won&amp;#39;t work either for the reasons described in the first two post. So far so bad &lt;img src="http://msmvps.com/emoticons/emotion-6.gif" alt="Sad" /&gt;&lt;/p&gt; &lt;h2&gt;So we need another workaround&lt;/h2&gt; &lt;p&gt;Again there is no real good workaround &lt;img src="http://msmvps.com/emoticons/emotion-6.gif" alt="Sad" /&gt;. In fact the only one I can come up with is stop using the TransactionScopeActivity all together. So how to do transactions without using the TransactionScopeActivity?&lt;/p&gt; &lt;p&gt;Well the solution, ahem workaround, is to use the WorkflowEnvironment.WorkBatch object and add all pending work to it. The first parameter is an object of type IPendingWork and this is the one that is actually going to be called to do the work. The second parameter, the workItem, contains the data. Now when a workflow per persistence point is reached the IPendingWork object is called to do its work. &lt;/p&gt;&lt;span style="color:blue;"&gt;&lt;pre class="code"&gt;[&lt;span style="color:#2b91af;"&gt;Serializable()]
&lt;/span&gt;&lt;span style="color:blue;"&gt;class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Workflow1PendingWork : IPendingWork
{
    &lt;/span&gt;&lt;span style="color:blue;"&gt;#region IPendingWork Members

    public void Commit(&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Transaction transaction, ICollection items)
    {
        &lt;/span&gt;&lt;span style="color:blue;"&gt;foreach (var Workflow1PendingWork in items)
        {
            using (&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TransactionScope tx = &lt;/span&gt;&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TransactionScope(transaction))
            {
                &lt;/span&gt;&lt;span style="color:green;"&gt;// Do my own transaction work
                tx.Complete();
            }
        }
    }

    &lt;/span&gt;&lt;span style="color:blue;"&gt;public void Complete(bool succeeded, &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ICollection items)
    {
    }

    &lt;/span&gt;&lt;span style="color:blue;"&gt;public bool MustCommit(&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ICollection items)
    {
        &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &lt;/span&gt;&lt;span style="color:green;"&gt;We want to commit!
        &lt;/span&gt;&lt;span style="color:blue;"&gt;return true;
    }

    #endregion
}

&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;p&gt;The MustCommit function is called to check if the Commit needs to be called. The Commit itself is called as part of the workflow persistence point. Now you can use something like a CodeActivity and add your workItem to the batch like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;WorkflowEnvironment.WorkBatch.Add(_pendingWork, myTransactionData);
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;When do we reach a persistence point?&lt;/h2&gt;
&lt;p&gt;This leaves us with the question of when these persistence point occur. The best way to think if these is when a workflow reaches a state that is final, no matter what happens. This includes the point where a workflow is done and when it is persisted to the persistence store. Using the SqlWorkflowPersistenceService with the PersistOnIdle option set to true will mean this will happen as soon as the event handler is done executing and the workflow is idle. However sometimes that just isn&amp;#39;t good enough and you need to do so sooner. Well the easiest way is to create a custom activity, I call it the PersistStateActivity, and decorate it with the PersistOnClose attribute. No need to add any code, all we are interested in is the attribute. &lt;/p&gt;&lt;pre class="code"&gt;[&lt;span style="color:#2b91af;"&gt;PersistOnClose()]
&lt;/span&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PersistStateActivity : Activity
{
    &lt;/span&gt;&lt;span style="color:blue;"&gt;public PersistStateActivity()
    {
    }
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;
&lt;p&gt;Now drop the activity at any point where you want your transactional data to be committed and the workflow runtime will take care of things for you &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Although these workarounds are possible they are all but intuitive and it took quite a bit of digging around and brainstorming with some people to get this to work. So be very careful when using the TransactionScopeActivity, or any form of transactions for that matter, and the WCF ReceiveActivity!&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;span style="color:blue;"&gt;&lt;/p&gt;&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1644506" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WCF/default.aspx">WCF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Visual Studio 2008 Service Pack 1 available</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/11/visual-studio-2008-service-pack-1-available.aspx</link><pubDate>Mon, 11 Aug 2008 15:33:33 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1644248</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1644248</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/11/visual-studio-2008-service-pack-1-available.aspx#comments</comments><description>&lt;p&gt;It is available from the subscriptions download at &lt;a title="http://msdn.microsoft.com/en-us/subscriptions/default.aspx" href="http://msdn.microsoft.com/en-us/subscriptions/default.aspx"&gt;http://msdn.microsoft.com/en-us/subscriptions/default.aspx&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Get it while it is hot &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1644248" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WCF/default.aspx">WCF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WPF/default.aspx">WPF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>More on using a TransactionScopeActivity within a ReceiveActivity</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/08/more-on-using-a-transactionscopeactivity-within-a-receiveactivity.aspx</link><pubDate>Fri, 08 Aug 2008 12:01:09 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1643919</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1643919</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/08/more-on-using-a-transactionscopeactivity-within-a-receiveactivity.aspx#comments</comments><description>&lt;p&gt;In a &lt;a href="http://msmvps.com/blogs/theproblemsolver/archive/2008/08/06/using-a-transactionscopeactivity-with-a-wcf-receiveactivity.aspx"&gt;previous blog post&lt;/a&gt; I write about what happens when you place a TransactionScopeActivity within a ReceiveActivity and an exception occurs that is supposed to roll back the transaction. In short the story was very bad and we could come up with only a partial workaround, not a pretty sight.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;But there is more to it than just that little horror story. Suppose you do the obvious and place the a TransactionScopeActivity within a ReceiveActivity and no exception occurs. Say like the workflow below, please note that the codeActivity1 only sets the return value and causes no error.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.MoreonusingaTransactionScopeActivitywith_5F00_14133/image_5F00_2.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="311" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.MoreonusingaTransactionScopeActivitywith_5F00_14133/image_5F00_thumb.png" width="382" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now the transaction is committed and the WCF call returns perfectly normally so everything is good right. Well not quite &lt;img src="http://msmvps.com/emoticons/emotion-6.gif" alt="Sad" /&gt; &lt;/p&gt; &lt;p&gt;The obvious first point is that the TransactionScopeActivity serves no real purpose. After all if it isn&amp;#39;t allowed to fail under any circumstances why bother with it in the first place. Well ok there is the point of doing several updates as a single transaction so other users cannot see a partially committed order but that is about it.&lt;/p&gt; &lt;p&gt;But that is actually the least of my worries as there is a far bigger issue to worry about and that is called workflow persistence.&lt;/p&gt; &lt;p&gt;Yes that is right. After all when we are using a TransactionScopeActivity workflow persistence is mandatory. The TransactionScopeActivity is decorated with the PersistOnClose attribute so the state of the workflow will be persisted as soon as the transaction is complete. And normally that is a good thing but in this case it is the cause of the second problem because this is still inside the ReceiveActivity. So basically we are storing the workflow state as it is just before returning an answer to the client. Now if everything is running fine that won&amp;#39;t matter because the workflow will continue until it is finished and everyone is happy. But suppose the workflow host terminates before the workflow is finished? In this test I added the DelayActivity, and set UnloadOnIdle to false so it doesn&amp;#39;t persist the state, giving me the opportunity to kill the workflow runtime. Now if I restart the runtime It is going to reload the last state of the workflow and continue from there. And guess what it&amp;#39;s going to do first? You guessed it: it is going to send the response to the client for a second time. Of course the client is no longer around and that action fails with an InvalidOperationException with message &amp;quot;Workflow unloaded between request &amp;amp; response.&amp;quot;&lt;/p&gt; &lt;p&gt;I guess the message is not entirely correct as it should say &amp;quot;Workflow &lt;strong&gt;reloaded&lt;/strong&gt; between request &amp;amp; response.&amp;quot; but it&amp;#39;s close enough.&lt;/p&gt; &lt;p&gt;The bottom line is the workflow terminates unless you specifically allow for this to happen and catch the error.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;So basically we have a choice between putting the TransactionScopeActivity inside a ReceiveActivity, not being able to throw an error and having a restore problem, or putting the TransactionScopeActivity around the ReceiveActivity, something that only works with a sequential workflow and an initiating ReceiveActivity as I described in the &lt;a href="http://msmvps.com/blogs/theproblemsolver/archive/2008/08/06/using-a-transactionscopeactivity-with-a-wcf-receiveactivity.aspx"&gt;previous post&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I guess these options make me pretty unhappy &lt;img src="http://msmvps.com/emoticons/emotion-6.gif" alt="Sad" /&gt;.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy your workflow transactions!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1643919" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WCF/default.aspx">WCF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category></item><item><title>SQL Server Compact 3.5 SP1 released</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/07/sql-server-compact-3-5-sp1-released.aspx</link><pubDate>Thu, 07 Aug 2008 07:47:58 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1643674</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1643674</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/07/sql-server-compact-3-5-sp1-released.aspx#comments</comments><description>&lt;p&gt;Steve Lasker just announced that SQL Server Compact 3.5 service pack 1 is released, read his announcement &lt;a href="http://blogs.msdn.com/stevelasker/archive/2008/08/07/sql-server-compact-3-5-sp1-released.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;They added support for the entity framework, great stuff. And another neat feature is native 64 bits support. No longer do you need to target X86 and use WoW [:0]. Great if you are using my &lt;a href="http://code.msdn.microsoft.com/SqlCeWFPersistence"&gt;SQL Server Compact Workflow Persistence Service&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1643674" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>Using a TransactionScopeActivity with a WCF ReceiveActivity</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/06/using-a-transactionscopeactivity-with-a-wcf-receiveactivity.aspx</link><pubDate>Wed, 06 Aug 2008 08:10:20 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1643529</guid><dc:creator>Maurice</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1643529</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/06/using-a-transactionscopeactivity-with-a-wcf-receiveactivity.aspx#comments</comments><description>&lt;p&gt;I got an email from a friend last week asking about using a ReceiveActivity and, while receiving, using a TransactionScopeActivity to transitionally save some data in a database. Seems like a common enough scenario right? Well he was having some problems. If everything worked and the transaction succeeded everything was fine and the answer came back. But if an exception occurred and the transaction was aborted be was receiving a real weird error:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Workflow service unexpectedly unloaded from memory while executing a ReceiveActivity. Make sure that the the workflow does not contain any blocking activities within a ReceiveActivity.&amp;nbsp; (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:&lt;br /&gt;System.InvalidOperationException: Workflow service unexpectedly unloaded from memory while executing a ReceiveActivity. Make sure that the the workflow does not contain any blocking activities within a ReceiveActivity.).&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;If we where to believe the message there was a blocking call, something there most certainly was not!&lt;/p&gt; &lt;p&gt;And to make things more confusing, if we removed the TransactionScopeActivity and just let the exception occur it would bubble back to the client just as it was supposed to. So what gives?&lt;/p&gt; &lt;p&gt;Well a lot of people looked at this and in the end we declared this a pretty bad bug. Mind you our words not those from Microsoft. But we did find a workaround. So lets take a look at a repro and how to fix this. My original test workflow looked like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.UsingaTransactionScopeActivitywithaWCFRe_5F00_11374/image_5F00_2.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="244" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.UsingaTransactionScopeActivitywithaWCFRe_5F00_11374/image_5F00_thumb.png" width="155" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;I receive a WCF request, start a transaction, determine the return value in a code activity, throw an exception and return. Seems reasonable right? Well I thought so but it produces the error claiming there is a blocking statement. While tracking this Marvin actually noticed that the workflow idle event was raised! Excuse me, a workflow is becoming idle to undo a transaction sounds kind of wrong. And of course when a TransactionScopeActivity is used in a regular workflow, ie non WCF call, there is no Idle event.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h4&gt;A partial solution&lt;/h4&gt; &lt;p&gt;So the way to get this to work is create the following workflow:&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.UsingaTransactionScopeActivitywithaWCFRe_5F00_11374/image_5F00_4.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="244" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.UsingaTransactionScopeActivitywithaWCFRe_5F00_11374/image_5F00_thumb_5F00_1.png" width="192" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;So instead of creating a TransactionScopeActivity inside of my ReceiveActivity I am doing it the other way round. Sounds kind of weird right? Well I think so but it does do the right thing as it returns the correct fault information to the client and then undoes any transactional work done.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h4&gt;So why does this workaround work in this case?&lt;/h4&gt; &lt;p&gt;The ReceiveActivity has its CanCreateInstance property set to true so this is the request that actually creates and starts the workflow. This means that the workflow is created and starts executing from the top. Yes that is right, it starts from the top, not from the ReceiveActivity so any activities before that are also executed. I suppose that potentially opens a can of worms but we will leave that be for the moment. In this case the WCF request is received, this starts the workflow, this in turn starts the transaction, the message is received and processed and the transaction either commits or, like in this case, rolls back.&lt;/p&gt; &lt;h4&gt;How about a non creating ReceiveActivity?&lt;/h4&gt; &lt;p&gt;Well I am afraid no luck there as this workaround isn&amp;#39;t going to work then. The problem is that we start a transaction before we start waiting for the additional WCF calls and the TransactionScopeActivity has a a TimoutDuration. So in all likelihood the transaction timeout will occur before the message is received and this effectively cancels the ReceiveActivity meaning it cannot receive the message.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;I think this is a pretty major problem with the way WF and WCF work together. After all transactions a an essential piece of business applications and not being able to use them inside of a WCF request is a deadly sin.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy with care &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1643529" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WCF/default.aspx">WCF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category></item><item><title>CodeCamp 2008</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/02/codecamp-2008.aspx</link><pubDate>Sat, 02 Aug 2008 08:39:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1643090</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1643090</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/08/02/codecamp-2008.aspx#comments</comments><description>&lt;p&gt;Afgelopen jaar hebben we het eerste CodeCamp in Nederland georganiseerd en dat was een groot succes. De meeste deelnemers vroegen om meer, sommige zelfs om een CodeCamp per kwartaal of een heel weekend lang. Nou hebben we dat laatste nog niet gedaan maar we zijn wel aan de slag gegaan om een nieuw CodeCamp te organiseren. Als datum hebben we zaterdag 6 september gekozen. Gelukkig waren &lt;a href="http://www.microsoft.nl/"&gt;Microsoft&lt;/a&gt; en &lt;a href="http://www.class-a.nl/"&gt;Class-a&lt;/a&gt; behulpzaam en kunnen we, net als vorig jaar, weer in het Microsoft Innovation Center in Barneveld terecht. Een mooie datum en locatie om uitgerust van de vakantie een hoop kennis uit te wisselen. &lt;p&gt;Het programma staat nog niet helemaal vast, hou daar de website voor in de gaten, maar je kan er ondermeer de bekende Nederlandse sprekers verwachten. Uiteraard kan je zelf ook nog een sessie voorstellen dus als je een idee hebt voor een leuke sessie laat het dan zo snel mogelijk weten. &lt;p&gt;&amp;nbsp; &lt;p&gt;Dus zet de datum vast in je agenda en meld je zo snel mogelijk aan op de website &lt;a href="http://www.code-camp.nl"&gt;www.code-camp.nl&lt;/a&gt;. &lt;p&gt;&amp;nbsp; &lt;p&gt;Het &lt;a href="http://www.code-camp.nl/"&gt;CodeCamp&lt;/a&gt; is een gezamenlijk initiatief van de &lt;a href="http://www.sdn.nl/"&gt;SDN&lt;/a&gt;, de stichting &lt;a href="http://www.dotned.nl/"&gt;DotNed&lt;/a&gt; en &lt;a href="http://www.vbcentral.nl/"&gt;VB Central&lt;/a&gt;. &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1643090" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WCF/default.aspx">WCF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/WPF/default.aspx">WPF</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>SQL Compact 3.5 on a 64 bit Windows</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/28/sql-compact-3-5-on-a-64-bit-windows.aspx</link><pubDate>Mon, 28 Jul 2008 19:48:36 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1642463</guid><dc:creator>Maurice</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1642463</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/28/sql-compact-3-5-on-a-64-bit-windows.aspx#comments</comments><description>&lt;p&gt;SQL Compact is a great little database and highly recommended. However it was designed for use on small compact, hence its name, devices and that has some drawbacks. One of these is that it doesn&amp;#39;t run as a 64 bits application. And by default if you create a .NET application it is compile as &amp;quot;Any CPU&amp;quot; meaning it will run as a 64 bits application on a 64 bits version of Windows.&lt;/p&gt; &lt;p&gt;I, or I should say &lt;a href="http://blogs.msdn.com/rjacobs/default.aspx"&gt;Ron Jacobs&lt;/a&gt;, ran into that using my &lt;a href="http://code.msdn.microsoft.com/SqlCeWFPersistence"&gt;SqlCeWorkflowPersistenceService&lt;/a&gt; because the sample/test application&amp;nbsp; was set to the default of &amp;quot;Any CPU&amp;quot;. The result is that the LINQ provider cannot load the runtime and a InvalidOperationException with message &amp;quot;Cannot open &amp;#39;WorkflowPersistenceDatabase.sdf&amp;#39;. Provider &amp;#39;System.Data.SqlServerCe.3.5&amp;#39; not installed.&amp;quot; is the result. Now the fix is rather easy but it has to be done in the main program and that is to compile it for X86 instead of Any CPU.&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.SQLCompact3.5ona64bitWindows_5F00_132AE/X86.gif"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="343" alt="X86" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theproblemsolver.SQLCompact3.5ona64bitWindows_5F00_132AE/X86_5F00_thumb.gif" width="500" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Do this and any application using&amp;nbsp; SQL Compact 3.5 will happily run on Windows 64bit as a WOW Application.&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1642463" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>Launching of the Tegelberg</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/27/launching-of-the-tegelberg.aspx</link><pubDate>Sun, 27 Jul 2008 11:48:57 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1642328</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1642328</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/27/launching-of-the-tegelberg.aspx#comments</comments><description>&lt;p&gt;Martine made this picture of me launching of the &lt;a href="http://www.tegelbergbahn.de/"&gt;Tegelberg&lt;/a&gt; in Germany. &lt;/p&gt; &lt;p&gt;&lt;a title="IMG_2339 by Mar10os, on Flickr" href="http://www.flickr.com/photos/mar10os/2705562397/"&gt;&lt;img height="500" alt="IMG_2339" src="http://farm4.static.flickr.com/3203/2705562397_0b8c9d566a.jpg" width="333" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt; A great place to fly with a nice view of &lt;a href="http://en.wikipedia.org/wiki/Neuschwanstein"&gt;Neuschwanstein Castle&lt;/a&gt;. Below a picture I took while flying.&lt;/p&gt;&lt;a title="Neuschwanstein Castle while paragliding by ** Maurice **, on Flickr" href="http://www.flickr.com/photos/mauricedb/2647384342/"&gt;&lt;img height="500" alt="Neuschwanstein Castle while paragliding" src="http://farm4.static.flickr.com/3149/2647384342_a482a020b4.jpg" width="358" /&gt;&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1642328" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Paragliding/default.aspx">Paragliding</category></item><item><title>SQL Server Compact Workflow Persistence Service updated</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/21/sql-server-compact-workflow-persistence-service-updated.aspx</link><pubDate>Mon, 21 Jul 2008 11:47:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1641600</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1641600</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/21/sql-server-compact-workflow-persistence-service-updated.aspx#comments</comments><description>&lt;p&gt;I have just updated the &lt;a href="http://code.msdn.microsoft.com/SqlCeWFPersistence"&gt;SQL Server Compact Workflow Persistence Service&lt;/a&gt; to better handle deserialization issues when loading a workflow. The service now makes sure the WorkflowRuntime ServicesExceptionNotHandled is raised, something it should have done in the first place.&lt;/p&gt; &lt;p&gt;You can download the SQL Server Compact Workflow Persistence Service from &lt;a href="http://code.msdn.microsoft.com/SqlCeWFPersistence"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.TheProblemSolver.nl"&gt;www.TheProblemSolver.nl&lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.WindowsWorkflowFoundation.eu"&gt;http://wiki.WindowsWorkflowFoundation.eu&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1641600" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>FaultHandlerActivity and workflow persistence</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/21/faulthandleractivity-and-workflow-persistence.aspx</link><pubDate>Mon, 21 Jul 2008 10:11:17 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1641593</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1641593</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/21/faulthandleractivity-and-workflow-persistence.aspx#comments</comments><description>&lt;p&gt;I was just working on an issue reported against the &lt;a href="http://code.msdn.microsoft.com/SqlCeWFPersistence"&gt;SQL Server Compact Workflow Persistence Service&lt;/a&gt; I released some time ago. It turns&amp;nbsp; that if you are using workflow persistence your workflow will actually be persisted to the store when an exception is caught. Now in itself not a big problem as your whole workflow needs to be serializable anyway. Except this time where is an additional exception object and when the exception itself cannot be serialized this brings the whole workflow down. In fact it brings more that just the workflow as the whole workflow runtime crashes, not good &lt;img src="http://msmvps.com/emoticons/emotion-6.gif" alt="Sad" /&gt;&lt;/p&gt; &lt;p&gt;The culprit in this case was a SqlCeException which is not serializable! Don&amp;#39;t worry about the more common SqlException because that is perfectly ok.&lt;/p&gt; &lt;p&gt;Still something to double check as these exceptions are, by their very nature, the exceptional case and therefor less likely to be tested.&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.TheProblemSolver.nl"&gt;www.TheProblemSolver.nl&lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.WindowsWorkflowFoundation.eu"&gt;http://wiki.WindowsWorkflowFoundation.eu&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1641593" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/SqlCe/default.aspx">SqlCe</category></item><item><title>Congratulations! You have received the Microsoft MVP Award</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/07/congratulations-you-have-received-the-microsoft-mvp-award.aspx</link><pubDate>Mon, 07 Jul 2008 14:54:59 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1639630</guid><dc:creator>Maurice</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1639630</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/07/07/congratulations-you-have-received-the-microsoft-mvp-award.aspx#comments</comments><description>&lt;p&gt; While on holiday I received the MVP award for another year &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt; &lt;p&gt;Now that is always a nice email to come home to!&lt;/p&gt; &lt;p&gt;Thanks, I appreciate it!&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.theproblemsolver.nl/images/MVP_FullColor_ForScreen.png" alt="" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1639630" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category></item><item><title>Unit testing asynchronous workflow activities</title><link>http://msmvps.com/blogs/theproblemsolver/archive/2008/06/11/unit-testing-asynchronous-workflow-activities.aspx</link><pubDate>Wed, 11 Jun 2008 08:56:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1633904</guid><dc:creator>Maurice</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/theproblemsolver/rsscomments.aspx?PostID=1633904</wfw:commentRss><comments>http://msmvps.com/blogs/theproblemsolver/archive/2008/06/11/unit-testing-asynchronous-workflow-activities.aspx#comments</comments><description>&lt;p&gt;In a &lt;a href="http://msmvps.com/blogs/theproblemsolver/archive/2008/06/02/unit-testing-custom-workflow-activities.aspx"&gt;previous blog post&lt;/a&gt; I demonstrated how &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; allowed us to mock out the workflow runtime infrastructure and create true unit tests for a workflow activity. Now this may not seems like a big deal but because most of the classes in the workflow runtime are sealed mocking them with another mocking framework is pretty much impossible. Now you can test custom activities by wrapping them in a test workflow, creating a workflow runtime, running the workflow and inspecting the result I can hardly call this a unit test as we have to create lots of, complex, depended objects. So TypeMock really opens up some new possibilities here.&lt;/p&gt; &lt;p&gt;But the previous examples where still pretty simple, although mocking the &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/ActivityExecutionContext.html"&gt;ActivityExecutionContext&lt;/a&gt; has always been considered impossible, so lets try something more complicated in the shape of an asynchronous activity. Basically an asynchronous activity is an activity that returns ActivityExecutionStatus.Executing from the Execute method indicating to the workflow runtime that it isn&amp;#39;t done yet. The activity uses ActivityExecutionContext at a later point in time to indicate that it is done by calling the &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/CloseActivity.html"&gt;CloseActivity&lt;/a&gt; function.&lt;/p&gt; &lt;p&gt;Lets take a quick look at our new activity.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WriteLineActivity3 &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;Activity
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;WriteLineActivity3()
    {
        InitializeComponent();
    }

    &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Message { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color:blue;"&gt;protected override &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus &lt;/span&gt;Execute(&lt;span style="color:#2b91af;"&gt;ActivityExecutionContext &lt;/span&gt;executionContext)
    {
        &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus &lt;/span&gt;result = &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus&lt;/span&gt;.Closed;

        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!&lt;span style="color:blue;"&gt;string&lt;/span&gt;.IsNullOrEmpty(Message))
        {
            &lt;span style="color:#2b91af;"&gt;IComparable &lt;/span&gt;queueName = &lt;span style="color:#2b91af;"&gt;Guid&lt;/span&gt;.NewGuid();
            &lt;span style="color:#2b91af;"&gt;WorkflowQueuingService &lt;/span&gt;wqs = executionContext.GetService&amp;lt;&lt;span style="color:#2b91af;"&gt;WorkflowQueuingService&lt;/span&gt;&amp;gt;();
            &lt;span style="color:#2b91af;"&gt;WorkflowQueue &lt;/span&gt;queue = wqs.CreateWorkflowQueue(queueName, &lt;span style="color:blue;"&gt;true&lt;/span&gt;);
            queue.QueueItemAvailable += &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;QueueEventArgs&lt;/span&gt;&amp;gt;(queue_QueueItemAvailable);


            &lt;span style="color:#2b91af;"&gt;WriteLineService3 &lt;/span&gt;service = executionContext.GetService&amp;lt;&lt;span style="color:#2b91af;"&gt;WriteLineService3&lt;/span&gt;&amp;gt;();

            service.WriteLine(Message, queueName);
            result = &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus&lt;/span&gt;.Executing;
        }

        &lt;span style="color:blue;"&gt;return &lt;/span&gt;result;
    }

    &lt;span style="color:blue;"&gt;void &lt;/span&gt;queue_QueueItemAvailable(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;QueueEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:#2b91af;"&gt;ActivityExecutionContext &lt;/span&gt;executionContext = sender &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionContext&lt;/span&gt;;
        executionContext.CloseActivity();
    }
}
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;In this case the return value from the Execute depends on the Message property being filled or not so we need to test this. First a simple test for an activity with an empty message:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
///&lt;/span&gt;&lt;span style="color:green;"&gt;A test for Execute
&lt;/span&gt;&lt;span style="color:gray;"&gt;///&amp;lt;/summary&amp;gt;
&lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;TestMethod&lt;/span&gt;()]
[&lt;span style="color:#2b91af;"&gt;DeploymentItem&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;WFUnitTest1.exe&amp;quot;&lt;/span&gt;)]
[&lt;span style="color:#2b91af;"&gt;VerifyMocks&lt;/span&gt;()]
&lt;span style="color:blue;"&gt;public void &lt;/span&gt;ExecuteTestEmpty()
{
    &lt;span style="color:#2b91af;"&gt;WriteLineActivity3_Accessor &lt;/span&gt;target = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WriteLineActivity3_Accessor&lt;/span&gt;();&lt;span style="color:green;"&gt;
    &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus &lt;/span&gt;expected = &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus&lt;/span&gt;.Closed;
    &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus &lt;/span&gt;actual;

    &lt;span style="color:#2b91af;"&gt;ActivityExecutionContext &lt;/span&gt;executionContext = &lt;br /&gt;        &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionContext&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;WorkflowQueuingService &lt;/span&gt;wqs = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;WorkflowQueuingService&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;WorkflowQueue &lt;/span&gt;queue = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;WorkflowQueue&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;WriteLineService3 &lt;/span&gt;service = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;WriteLineService3&lt;/span&gt;&amp;gt;();

    &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;RecordExpectations &lt;/span&gt;recorder = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.StartRecording())
    {
        executionContext.GetService&amp;lt;&lt;span style="color:#2b91af;"&gt;WriteLineService3&lt;/span&gt;&amp;gt;();
        recorder.FailWhenCalled();
    }

    target.Message = &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
    actual = target.Execute(executionContext);

    &lt;span style="color:#2b91af;"&gt;Assert&lt;/span&gt;.AreEqual(expected, actual);
}
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;In this test I actually check that the runtime service, called WriteLineService3 in this case, is never retrieved. This test is still pretty simple and no more complicated than the test we did previously.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Lets take a look at something more complicated. The following test has the Message property set so it is expected to call the &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/WorkflowRuntimeService.html"&gt;runtime service&lt;/a&gt;. But being an asynchronous activity it is also required to create a WorkflowQueue and bind to its &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/QueueItemAvailable.html"&gt;QueueItemAvailable&lt;/a&gt; event so we will check that has happened. Finally this time the Execute function should return a status of ActivityExecutionStatus.Executing as it isn&amp;#39;t done yet. This test runs like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
///&lt;/span&gt;&lt;span style="color:green;"&gt;A test for Execute
&lt;/span&gt;&lt;span style="color:gray;"&gt;///&amp;lt;/summary&amp;gt;
&lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;TestMethod&lt;/span&gt;()]
[&lt;span style="color:#2b91af;"&gt;DeploymentItem&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;WFUnitTest1.exe&amp;quot;&lt;/span&gt;)]
[&lt;span style="color:#2b91af;"&gt;VerifyMocks&lt;/span&gt;()]
&lt;span style="color:blue;"&gt;public void &lt;/span&gt;ExecuteTestStart()
{
    &lt;span style="color:#2b91af;"&gt;WriteLineActivity3_Accessor &lt;/span&gt;target = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WriteLineActivity3_Accessor&lt;/span&gt;();
    &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus &lt;/span&gt;expected = &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus&lt;/span&gt;.Executing;
    &lt;span style="color:#2b91af;"&gt;ActivityExecutionStatus &lt;/span&gt;actual;


    &lt;span style="color:#2b91af;"&gt;ActivityExecutionContext &lt;/span&gt;executionContext = 
        &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionContext&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;WorkflowQueuingService &lt;/span&gt;wqs = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;WorkflowQueuingService&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;WorkflowQueue &lt;/span&gt;queue = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;WorkflowQueue&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;WriteLineService3 &lt;/span&gt;service = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;WriteLineService3&lt;/span&gt;&amp;gt;();

    &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;RecordExpectations &lt;/span&gt;recorder = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.StartRecording())
    {
        &lt;span style="color:green;"&gt;// Record methods here
        &lt;/span&gt;executionContext.GetService&amp;lt;&lt;span style="color:#2b91af;"&gt;WorkflowQueuingService&lt;/span&gt;&amp;gt;();
        recorder.Return(wqs);
        wqs.CreateWorkflowQueue(&lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;true&lt;/span&gt;);
        recorder.Return(queue);
        queue.QueueItemAvailable += &lt;span style="color:blue;"&gt;delegate&lt;/span&gt;(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;QueueEventArgs &lt;/span&gt;e) { };

        executionContext.GetService&amp;lt;&lt;span style="color:#2b91af;"&gt;WriteLineService3&lt;/span&gt;&amp;gt;();
        recorder.Return(service);
        service.WriteLine(&lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;);
    }

    target.Message = &lt;span style="color:#a31515;"&gt;&amp;quot;A message&amp;quot;&lt;/span&gt;;
    actual = target.Execute(executionContext);

    &lt;span style="color:#2b91af;"&gt;Assert&lt;/span&gt;.AreEqual(expected, actual);
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;A little more complicated than the previous check but not bad at all &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;
&lt;p&gt;In this case we are binding to the QueueItemAvailable event so we need to add another test for the event handler and make sure it informs the workflow runtime we are done.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
///&lt;/span&gt;&lt;span style="color:green;"&gt;A test for queue_QueueItemAvailable
&lt;/span&gt;&lt;span style="color:gray;"&gt;///&amp;lt;/summary&amp;gt;
&lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;TestMethod&lt;/span&gt;()]
[&lt;span style="color:#2b91af;"&gt;DeploymentItem&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;WFUnitTest1.exe&amp;quot;&lt;/span&gt;)]
[&lt;span style="color:#2b91af;"&gt;VerifyMocks&lt;/span&gt;()]
&lt;span style="color:blue;"&gt;public void &lt;/span&gt;queue_QueueItemAvailableTest()
{
    &lt;span style="color:#2b91af;"&gt;WriteLineActivity3_Accessor &lt;/span&gt;target = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WriteLineActivity3_Accessor&lt;/span&gt;();
    &lt;span style="color:#2b91af;"&gt;QueueEventArgs &lt;/span&gt;e = &lt;span style="color:blue;"&gt;null&lt;/span&gt;; &lt;span style="color:green;"&gt;// TODO: Initialize to an appropriate value

    &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionContext &lt;/span&gt;executionContext = 
        &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;ActivityExecutionContext&lt;/span&gt;&amp;gt;();

    &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;RecordExpectations &lt;/span&gt;recorder = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.StartRecording())
    {
        executionContext.CloseActivity();
    }

    target.queue_QueueItemAvailable(executionContext, e);
}
&lt;/pre&gt;
&lt;p&gt;Not bad at all &lt;img src="http://msmvps.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;/p&gt;
&lt;p&gt;That leaves us with writing a unit test for the runtime service itself. This runtime service actually looks like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WriteLineService3&lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;WorkflowRuntimeService
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;WriteLine(&lt;span style="color:blue;"&gt;string &lt;/span&gt;message, &lt;span style="color:#2b91af;"&gt;IComparable &lt;/span&gt;queueName)
    {
        &lt;span style="color:#2b91af;"&gt;Guid &lt;/span&gt;instanceId = &lt;span style="color:#2b91af;"&gt;WorkflowEnvironment&lt;/span&gt;.WorkflowInstanceId;

        &lt;span style="color:#2b91af;"&gt;ThreadPool&lt;/span&gt;.QueueUserWorkItem(state =&amp;gt; WriteLineAsync(message, instanceId, queueName));
    }

    &lt;span style="color:blue;"&gt;private void &lt;/span&gt;WriteLineAsync(&lt;span style="color:blue;"&gt;string &lt;/span&gt;message, &lt;span style="color:#2b91af;"&gt;Guid &lt;/span&gt;instanceId, &lt;span style="color:#2b91af;"&gt;IComparable &lt;/span&gt;queueName)
    {
        &lt;span style="color:#2b91af;"&gt;Thread&lt;/span&gt;.Sleep(&lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(5));

        &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(message);

        &lt;span style="color:#2b91af;"&gt;WorkflowInstance &lt;/span&gt;instance = GetWorkflow(instanceId);
        instance.EnqueueItem(queueName, &lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;);
    }

    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WorkflowInstance &lt;/span&gt;GetWorkflow(&lt;span style="color:#2b91af;"&gt;Guid &lt;/span&gt;instanceId)
    {
        &lt;span style="color:#2b91af;"&gt;WorkflowInstance &lt;/span&gt;result = Runtime.GetWorkflow(instanceId);
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;result;
    }
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Not very complicated or realistic for that matter but still lets write a quick unit test for it like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
///&lt;/span&gt;&lt;span style="color:green;"&gt;A test for WriteLine
&lt;/span&gt;&lt;span style="color:gray;"&gt;///&amp;lt;/summary&amp;gt;
&lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;TestMethod&lt;/span&gt;()]
[&lt;span style="color:#2b91af;"&gt;VerifyMocks&lt;/span&gt;(10000)]
&lt;span style="color:blue;"&gt;public void &lt;/span&gt;WriteLineTest()
{
    &lt;span style="color:#2b91af;"&gt;WriteLineService3_Accessor &lt;/span&gt;target = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WriteLineService3_Accessor&lt;/span&gt;(); 
    
    &lt;span style="color:blue;"&gt;string &lt;/span&gt;message = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty; &lt;span style="color:green;"&gt;// TODO: Initialize to an appropriate value
    &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IComparable &lt;/span&gt;queueName = &lt;span style="color:blue;"&gt;null&lt;/span&gt;; &lt;span style="color:green;"&gt;// TODO: Initialize to an appropriate value

    &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WorkflowInstance &lt;/span&gt;instance = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.CreateMockedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;WorkflowInstance&lt;/span&gt;&amp;gt;();

    &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;RecordExpectations &lt;/span&gt;recorder = &lt;span style="color:#2b91af;"&gt;RecorderManager&lt;/span&gt;.StartRecording())
    {
        &lt;span style="color:#2b91af;"&gt;Guid &lt;/span&gt;instanceId = &lt;span style="color:#2b91af;"&gt;WorkflowEnvironment&lt;/span&gt;.WorkflowInstanceId;
        recorder.Return(&lt;span style="color:#2b91af;"&gt;Guid&lt;/span&gt;.NewGuid());

        target.GetWorkflow(instanceId);
        recorder.Return(instance);
        instance.EnqueueItem(&lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;);
    }

    target.WriteLine(message, queueName);

}
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;The most important thing here is that we can mock the WorkflowInstance object just as easy as the ActivityExecutionContext in the previous tests. I am actually telling TypeMock to wait for 10 seconds with the [VerifyMocks(10000)] attribute. This allows the delay in the service to remain there and still check if the expected response was queued. One thing to note is that I had to create an extra &lt;a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/GetWorkflow.html"&gt;GetWorkflow&lt;/a&gt;() function to wrap the real function on the WorkflowRuntime object. I was unable to mock the latter however I am unsure why this is the case and if mocking it is really impossible.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&lt;a href="http://www.TheProblemSolver.nl"&gt;www.TheProblemSolver.nl&lt;/a&gt; &lt;br /&gt;&lt;a href="http://wiki.WindowsWorkflowFoundation.eu"&gt;http://wiki.WindowsWorkflowFoundation.eu&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1633904" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/NetFx3/default.aspx">NetFx3</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/theproblemsolver/archive/tags/DevCenter/default.aspx">DevCenter</category></item></channel></rss>