locked
Self hosting, with WorkflowServiceHost, WF4RC RRS feed

  • Question

  • Hello all, evaluating WF4RC for use in our business, in particular self hosting a WorkflowService. I have been following Milner's excellent intro article [ http://msdn.microsoft.com/en-us/library/ee342461.aspx ], except that it is WF4B2, and as we all know there are some significant differences between B2 and RC.

    More specifically, I am working through his self-hosting bit toward the end of the article.

    I have a WorkflowService I would like to host

    <WorkflowService mc:Ignorable="sap" ConfigurationName="Service1" sap:VirtualizedContainerService.HintSize="307,366" Name="Service1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" 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/activities" 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:s4="clr-namespace:System;assembly=System.ServiceModel" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" 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:t="clr-namespace:TensorWorkflow;assembly=TensorWorkflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
      <p1:Sequence DisplayName="Sequential Service" sad:XamlDebuggerXmlReader.FileName="C:\Documents and Settings\john.gerula\My Documents\Visual Studio 2010\Projects\Oaccac\Tensor\TensorWorkflow\Services\TensorWorkflowService\TensorWorkflowService.xamlx" sap:VirtualizedContainerService.HintSize="277,336" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces">
    
        <p1:Sequence.Variables>
    
          <p1:Variable x:TypeArguments="CorrelationHandle" Name="handle" />
    
          <p1:Variable x:TypeArguments="t:Workflow" Name="data" />
    
        </p1: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>
    
        <Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" sap:VirtualizedContainerService.HintSize="255,86" OperationName="SubmitWorkflow" ServiceContractName="p:ITensorWorkflowService">
    
          <Receive.CorrelationInitializers>
    
            <RequestReplyCorrelationInitializer CorrelationHandle="[handle]" />
    
          </Receive.CorrelationInitializers>
    
          <ReceiveMessageContent DeclaredMessageType="t:Workflow">
    
            <p1:OutArgument x:TypeArguments="t:Workflow">[data]</p1:OutArgument>
    
          </ReceiveMessageContent>
    
        </Receive>
    
        <SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendResponse" sap:VirtualizedContainerService.HintSize="255,86">
    
          <SendMessageContent DeclaredMessageType="x:Boolean">
    
            <p1:InArgument x:TypeArguments="x:Boolean">[True]</p1:InArgument>
    
          </SendMessageContent>
    
        </SendReply>
    
      </p1:Sequence>
    
    </WorkflowService>
    
    

    I used the designer, and it is a part of my solution as source file "TensorWorkflowService.xamlx". Its properties, Build Action "Content", Copy to Output Directory "Do not copy", Custom Tool "MSBuild:Compile".

    This is a snippet from my hosting console

        host = new WorkflowServiceHost ("TensorWorkflowService.xamlx", new Uri ("http://localhost:9897/Services/Workflow"));
    
        host.AddDefaultEndpoints ();
    
        WorkflowControlEndpoint endpoint = new WorkflowControlEndpoint (new NetNamedPipeBinding (), new EndpointAddress ("net.pipe://localhost/Workflow/Endpoint"));
    
        host.AddServiceEndpoint (endpoint);
    
    

    As you can see, it's almost verbatim from Milner's article. However, surprise surprise, it fails! When I attempt to compile and run, I receive this exception at run-time

    WorkflowServiceHost requires that the serviceImplementation provided is an Activity or a WorkflowService.
    
    Parameter name: serviceImplementation
    
    

    Since B2, it appears any explicit constructors with filename parameters have been removed. I have tried a couple of different things, like interpreting the xamlx using ActivityXamlServices.Load (), but the service doesn't like WorkflowServices.

    Since documentation is short and samples outdated or few, is anyone in a position to help me understand

    1. what is the recommended usage of WorkflowServiceHost in WF4RC?
    2. what is the recommended path from designer xamlx to WorkflowService in WF4RC? [because even if ctor supported filenames, i do not understand how xamlx would find its way to bin directory with its current settings - are we intended to copy\deploy the xamlx?]

    Any help\insight would be much appreciated.

    Thank you!
    Monday, March 1, 2010 9:07 PM

Answers

  • WorkflowServiceHost ctor takes a serviceImplementation object. You can load it using code similar to the following:

    WorkflowServiceHost host = new WorkflowServiceHost(XamlServices.Load("ExpenseReportService.xamlx"), 
    new Uri(http://localhost:9897/Services/Expense));

    If no directory is specified, it loads from current folder, so copying xamlx to the bin folder works.

    Depending on the needs, if you don't want to deploy xamlx file, use code like this works: new WorkflowServiceHost(new Workflow1(), new Uri(http://localhost:9897/Services/Expense));

    Best Regards,

    Leo


    This posting is provided "AS IS" and confers no rights or warranties.

    • Proposed as answer by Leo.Chen Monday, March 8, 2010 8:53 AM
    • Marked as answer by johnny.five Monday, March 8, 2010 3:33 PM
    Monday, March 8, 2010 8:53 AM