Cannot self-host a workflow service using C# expressions - by InLocoAbsentia

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 741537 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 5/10/2012 8:43:59 AM
Access Restriction Public


Workflow Foundation supports hosting workflow services outside of Internet Information Services and the Windows Activation Service via System.ServiceModel.Activities.WorkflowServiceHost.  In .NET 4.5 Beta, Workflow Foundation supports C# expression syntax in workflow definitions (.xamlx files).  These workflow services work as expected when hosted in IIS or WAS.  However, workflow servcies using C# expressions hosted in user processes consistently throw FaultExceptions, not matter how simple the workflow.  VB services work as expected.  Reference this MSDN forum thread:
Sign in to post a comment.
Posted by David V. Corbin on 10/9/2012 at 6:05 AM
This issue remains in the RTM version of 4.5 (even though every reference I could find only mentions it in the context of the Beta). This is very annoying as one would typically not look at issues that were discovered during a Beta while using a released product.

At the very least, this information needs to be much more discoverable [for example being a bold note directly on the reference MSDN pages for the WorkflowService and WorkflowServiceHost].

The "workaround" did address my issues, but the amount of time it took to locate the solution was the equivilant of a few thousand dollars in billable hours.

David V. Corbin
Microsoft ALM Ranger
Posted by Microsoft on 6/8/2012 at 9:06 AM
Thank you for your feedback. I apologize that we are still in the process of creating documentation for this scenario, and that it is not simple to engineer this scenario in .Net 4.5 without documentation.

I have reproduced your issue, and I think the below expression Compilation code provides the solution to the problem.

static void Main(string[] args)
            // Create and cache the workflow definition
            WorkflowService workflow1 =


            var host = new WorkflowServiceHost(workflow1, new Uri("http://localhost:8293/Service1.xamlx"));
            Console.WriteLine("Press enter to quit");

        static void Compile(WorkflowService workflowService)
            TextExpressionCompilerSettings settings = new TextExpressionCompilerSettings
                Activity = workflowService.Body,
                Language = "C#",
                ActivityName = workflowService.Name + "_CompiledExpressionRoot",
                ActivityNamespace = string.Join(".", "CompiledExpressions"),
                RootNamespace = null,
                GenerateAsPartialClass = false,
                ForImplementation = false, // Important tip - ForImplementation should only be true when compiling an ActivityBuilder, it must be false when compiling an Activity such as a WorfkflowService body.

            TextExpressionCompilerResults results =
                new TextExpressionCompiler(settings).Compile();

            if (results.HasErrors)
                throw new Exception("Compilation failed.");

            ICompiledExpressionRoot compiledExpressionRoot =
                    new object[] { workflowService.Body }) as ICompiledExpressionRoot;

                workflowService.Body, compiledExpressionRoot);

For some further details of C# expressions in .Net 4.5 and expression compilation, you can also in the interm refer to this blog post:

Thank you for your patience, and please do reply as soon as possible if this does not address your problem.
Posted by MS-Moderator10 [Feedback Moderator] on 5/11/2012 at 12:50 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 5/10/2012 at 9:43 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(