The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Hiding the XAMLX from a workflow service

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

image

 

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.

image

<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.

image

 

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

Published Tue, May 18 2010 18:07 by Maurice
Filed under: , , , ,

Comments

# re: Hiding the XAMLX from a workflow service@ Tuesday, May 18, 2010 3:00 PM

You can even get rid of the ugly .svc by using .NET 4.0's features to host WCF services via the System.Web.Routing integration.

void Application_Start(object sender, EventArgs e)

{

 RouteTable.Routes.Add(

   new ServiceRoute(

     "Workflow1",

     new WorkflowServiceHostFactory(),

     typeof(Workflow1)));

}

# re: Hiding the XAMLX from a workflow service@ Wednesday, May 19, 2010 2:54 AM

@Christian,

Excellent point!

by Maurice

# re: Hiding the XAMLX from a workflow service@ Friday, May 21, 2010 9:36 AM

Another way to get rid of a physical .svc file is to use following config:

<system.serviceModel>

 <serviceHostingEnvironment>

   <serviceActivations>

     <add relativeAddress="MyService.svc"

           service="DeclarativeServiceLibrary1.Workflow1"

           factory="System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory" />

   </serviceActivations>

 </serviceHostingEnvironment>

</system.serviceModel>

# re: Hiding the XAMLX from a workflow service@ Wednesday, July 07, 2010 4:40 AM

Hi, can you post something about how to use WF4 with ASP.NET MVC applications ? basic Hello world...

Thank you

by azevedo