In Windows Workflow Foundation 4 it’s easy to create a workflow and expose it as a WCF service. But one thing is that it exposes a XAMLX endpoint to each client can see the service actually implemented as a workflow service instead of a regular service. One way to hide that is to use a regular SVC file as the implementation and point that to a workflow using the WorkflowServiceHostFactory.
See the original XAMLX extension
To change this to an SVC extension we need to do a few things. First we need to use a regular workflow instead of a workflow service. The reason is a regular workflow is compiled into the assembly while a workflow service isn’t compiled. So first step is to add a Workflow1.xaml workflow and copy the content of the Service1.xamlx into it.
<Activity mc:Ignorable="sap" x:Class="DeclarativeServiceLibrary1.Workflow1" sap:VirtualizedContainerService.HintSize="317,384" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://tempuri.org/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Sequence DisplayName="Sequential Service" sad:XamlDebuggerXmlReader.FileName="c:\users\maurice\documents\visual studio 2010\Projects\DeclarativeServiceLibrary1\DeclarativeServiceLibrary1\Workflow1.xaml" sap:VirtualizedContainerService.HintSize="277,344">
<Sequence.Variables>
<Variable x:TypeArguments="p1:CorrelationHandle" Name="handle" />
<Variable x:TypeArguments="x:Int32" Name="data" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<p1:Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" sap:VirtualizedContainerService.HintSize="255,90" OperationName="GetData" ServiceContractName="p:IService">
<p1:Receive.CorrelationInitializers>
<p1:RequestReplyCorrelationInitializer CorrelationHandle="[handle]" />
</p1:Receive.CorrelationInitializers>
<p1:ReceiveMessageContent>
<OutArgument x:TypeArguments="x:Int32">[data]</OutArgument>
</p1:ReceiveMessageContent>
</p1:Receive>
<p1:SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendResponse" sap:VirtualizedContainerService.HintSize="255,90">
<p1:SendMessageContent>
<InArgument x:TypeArguments="x:String">[data.ToString()]</InArgument>
</p1:SendMessageContent>
</p1:SendReply>
</Sequence>
</Activity>
Next we add a WCF Service named Workflow1.svc. Delete the code behind file and add a factory pointing to “System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory”
<%@ ServiceHost Service="DeclarativeServiceLibrary1.Workflow1"
Factory="System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory" %>
And that is all there is to it [:)]
Select the Workflow1.svc and press F5 to fire up the WCF Test Client to test the SVC worklfow.
A side benefit is that using the WorkflowServiceHostFactory allows us to derive from it and add our own logic to the WorkflowServiceHost like adding WorkflowExtensions.
Enjoy!
www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu