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.
/// 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());
class ReceiveInstanceCallback : IReceiveMessageCallback
public void OnReceiveMessage(System.ServiceModel.OperationContext operationContext,
// 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());
Dec 14 2010, 11:44 AM