How to create workflow control client

If we wan't to manually control the worlflow instance, we can use the new contract called IWorkflowInstanceManagement introduced in .Net Framework4.0. This contract defines a series of control operations that allow you remotely control workflow instances hosted by WorkflowServiceHost. WorkflowControlEndpoint is a standard endpoint that provides an implementation of the IWorkflowInstanceManagement contract. WorkflowControlClient is a class that is used to send the control operations to the WorkflowControlEndpoint. The default binding for WorkflowControlEndpoint is NetNamedPipeBinding.

The implemention and configuration on server side:

            WorkflowService serice = XamlServices.Load("http://www.cnblogs.com/service1.xamlx") as WorkflowService;
                        
            WorkflowServiceHost host = new WorkflowServiceHost(serice, new Uri(@"http://localhost:8080/MyService"));            
            //host.AddServiceEndpoint("IService", new BasicHttpBinding(), "");
            //host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });
            //host.Description.Behaviors.Add(new SqlWorkflowInstanceStoreBehavior()
            //{
            //    ConnectionString=@"Data Source=.\SQLEXPRESS;Initial Catalog=InstanceStore;Integrated Security=SSPI;Asynchronous Processing=True",
            //    HostLockRenewalPeriod = new TimeSpan(0, 0, 5),
            //    RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2),
            //    InstanceEncodingOption=InstanceEncodingOption.GZip,            
            //    InstanceCompletionAction = InstanceCompletionAction.DeleteAll,
            //    InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry,
            //                }
            //);

            host.Open();

            Console.WriteLine(@"Service is listening on http://localhost:8080/MyService");
            Console.WriteLine("Press enter to exit...");         

            Console.ReadLine();
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        
       <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />       
        
    </startup>
  <system.serviceModel>
    <services>
      <service name="Service1" behaviorConfiguration="">        
        <endpoint binding="basicHttpBinding" address="" contract="IService"></endpoint>
        <endpoint binding="basicHttpBinding" address="wce" kind="workflowControlEndpoint"></endpoint>        
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>        
        <behavior name="">
          <sqlWorkflowInstanceStore connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=InstanceStore;Integrated Security=SSPI;Asynchronous Processing=True">            
          </sqlWorkflowInstanceStore>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True"/>
        </behavior>        
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

The implemention and configuration on client side:

            System.ServiceModel.Activities.WorkflowControlClient clientCntrol = new System.ServiceModel.Activities.WorkflowControlClient("Control");
            clientCntrol.Terminate(new Guid("BCEC45E0-8CEB-4421-8DB5-533748E1E7A3"));
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8080/MyService" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
                name="BasicHttpBinding_IService" />
          <endpoint name="Control" address="http://localhost:8080/MyService/wce" binding="basicHttpBinding" contract="System.ServiceModel.Activities.IWorkflowInstanceManagement"></endpoint>
        </client>
    </system.serviceModel>
</configuration>

 

posted @ 2012-06-21 17:00  Leo Tang  阅读(662)  评论(4)    收藏  举报