ReceiveActivity and self hosting WCF

One of the new, and pretty cool, Windows Workflow Foundation features is the ReceiveActivity that unleashes the power of Windows Communication Foundation to Windows Workflow Foundation. Getting started with a ReceiveActivity is quite simple as long as you start with a sequential Workflow Service Library.

The new service host for Windows Communication Foundation services makes life good as it means you can test a workflow without creating a host application or resorting to IIS.

But sometimes you just want to host the workflow runtime yourself and still use the ReceiveActivity. So how to go about and do that?

For a normal WCF host you would use an instance of ServiceHost but with a ReceiveActivity that isn’t quite going to cut it as the host needs some awareness of WF and ServiceHost is very generic. So instead add a reference to System.WorkflowServices and create an instance of WorkflowServiceHost. The syntax is the same so no surprises there:

WorkflowServiceHost host = new WorkflowServiceHost(typeof(Workflow1));
host.Open();
Console.WriteLine(“Press enter to stop.”);

Console.ReadLine();

 

The app.config contains the runtime configuration but all of it is pretty standard WCF stuff so no surprises:

<?xml version=1.0 encoding=utf-8 ?>

<configuration>

<system.serviceModel>

<services>

<service name=WorkflowConsoleApplication1.Workflow2 behaviorConfiguration=WorkflowConsoleApplication1.Workflow2Behavior>

<host>

<baseAddresses>

<add baseAddress=http://localhost:8731/Design_Time_Addresses/WorkflowConsoleApplication1/Workflow2/ />

</baseAddresses>

</host>

<endpoint address=“”

binding=wsHttpContextBinding

contract=WorkflowConsoleApplication1.IMyContract>

<identity>

<dns value=localhost/>

</identity>

</endpoint>

<endpoint address=mex

binding=mexHttpBinding

contract=IMetadataExchange />

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name=WorkflowConsoleApplication1.Workflow2Behavior >

<serviceMetadata httpGetEnabled=true />

<serviceDebug includeExceptionDetailInFaults=false />

<serviceCredentials>

<windowsAuthentication

allowAnonymousLogons=false

includeWindowsGroups=true />

</serviceCredentials>

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

</configuration>

 

Enjoy!

www.TheProblemSolver.nl
http://wiki.WindowsWorkflowFoundation.eu

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>