Renaming a Workflow foundation 4 service

Workflow Foundation allows you to create a workflow as a service using WCF. You can do this by choosing a “Declarative Sequential Service Library” project from the WCF tab:

image

This will (as usual) create a new project with the service declared in Service1.xamlx. Opening this file will open the workflow designer. In web.config you can find the WCF configuation (greatly simplified because of the new simplified configuration feature in WCF):

  <system.serviceModel>
    <services>
      <service name="Service1" behaviorConfiguration="IntroToWFServices.Service1Behavior" >
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="IntroToWFServices.Service1Behavior">
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

 

I don’t know about you, but I don’t like the Service1 naming that Visual Studio automatically uses. So if you want to rename the workflow you should take special care. Start by renaming the Service1.xamlx file to (for example) TestService.xamlx. Next you need to close the workflow designer (if it is open) because otherwise the next edit will always be undone when you save. Then open the TestService.xamlx file using the Xml editior (right-click the file, then select Open With…, then select the xml editor). You will see this xaml:

<Service xmlns=http://schemas.microsoft.com/netfx/2009/xaml/servicemodel 
xmlns:m="clr-namespace:MyDataContracts;assembly=MyDataContracts"
xmlns:p=http://schemas.microsoft.com/netfx/2009/xaml/activities
xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <WorkflowServiceImplementation ConfigurationName="TestService" Name="TestService"> <p:Sequence DisplayName="Sequential Service" sad:XamlDebuggerXmlReader.FileName="C:\Users\Peter\Documents\Visual Studio 10\Projects\IntroToWFServices\IntroToWFServices\TestService.xamlx"> <p:Sequence.Variables> <p:Variable x:TypeArguments="CorrelationHandle" Name="handle" /> <p:Variable x:TypeArguments="m:MyData" Name="data" /> </p:Sequence.Variables> <Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" OperationName="GetData" ServiceContractName="Contract1" ValueType="m:MyData"> <Receive.AdditionalCorrelations> <p:InArgument x:TypeArguments="CorrelationHandle" x:Key="ChannelBasedCorrelation">[handle]</p:InArgument> </Receive.AdditionalCorrelations> <Receive.KnownTypes> <x:Type Type="x:Int32" /> </Receive.KnownTypes> <p:OutArgument x:TypeArguments="m:MyData">[data]</p:OutArgument> </Receive> <SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendResponse" ValueType="x:String"> <p:InArgument x:TypeArguments="x:String">[data.Data.ToString()]</p:InArgument> </SendReply> </p:Sequence> </WorkflowServiceImplementation> </Service>

 

You need to update the ConfigurationName attribute of the WorkflowServiceImplementation element to be the same as the service name in the WCF configuration:

  <system.serviceModel>
    <services>
      <service name="TestService" behaviorConfiguration="IntroToWFServices.Service1Behavior" >
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="IntroToWFServices.Service1Behavior">
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

In Beta 2 bits you will be able to do this using the designer (hehe).