How to obtain a host instance within a workflow service?

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

The Workflow Foundation programming model introduces a Workflow Service as a way to build a reach and robust long running composite applications. This model does not allow one to access the host.
Unfortunately, sometimes it is required to access the host. For example, if you need to know the file name of the workflow, when building more sophisticated workflows.

To make this working you need to implement interface IReceiveMessageCallback.

 

    /// <summary>

    /// This class implements interface which has a callback method, which is invoked
    /// when a message operation is invoked.

    /// This context.Properties.Add("ReceiveInstanceCallback", new ReceiveInstanceCallback());

    /// </summary>

    [DataContract(Namespace=”http://daenet.eu/accesshost”)]
    class ReceiveInstanceCallback :
IReceiveMessageCallback

    {
        public void OnReceiveMessage(System.ServiceModel.OperationContext operationContext,
                    System.Activities.ExecutionProperties activityExecutionProperties)

        {
             // This sets the instance of the host to Workflow instance.           
            
WorkflowSchedulerActivity.ServiceHost = operationContext.Host as WorkflowServiceHost ;
        }
    }

The method OnReceiveMessage provides you access to operation context and all hidden WCF staffs you might need. To make it working you will need to register it.
A good place for it is in Execute method of an activity, which is executed before receive activity.

 

protected override void Execute(NativeActivityContext context)

{
     context.Properties.Add("ReceiveInstanceCallback", new ReceiveInstanceCallback());

}


Posted Dec 14 2010, 11:44 AM by Damir Dobric
Filed under: , ,
developers.de is a .Net Community Blog powered by daenet GmbH.