Workflow Services: ContextManager is NULL-reference

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




When using ContextManager in WorflowService scenario, it can happen that the instance of the manager does not exist at all.
To illustrate this, take a look on following sample:

MyDemoSvcClient demoSvc = new Consumer.WfSvcDemo.MyDemoSvcClient();


IContextManager ctxMg = demoSvc.InnerChannel.GetProperty<IContextManager>();


Sometimes, it can happen that the variable "ctxMg" is empty. This is the case when instead of *HttpContextBinding the common *Binding is used. For example the client uses basicHttpBinding. Usually, after importing of service reference on the client's side, a common WCF binding is used and not expected workflow context binding. That means, if service is configured to use wsHttpContextBinding the client will import wsHttpBinding.

This seems to be strange, but it is a good choice. By avoiding of the context binding, the client is not required to use WorkflowService functionality implemented in System.WorkflowServices.dll. This specially makes a sense in an interop-scenario, where any client could invoke operations on workflow service. However, if the client needs features like context-persistance etc. you ill have to find a way how to do it, without of WCF.

Recap: If you need to deal with workflow context, use one of WCF-context-bindings, which are implemented in System.WorkflowServices assembly. Otherwise you will have to provide context-header value by yourself.

When all works fine you can do something like this to invoke the second operation on already running workflow, after recycling of the client:



If the client has been recycled (restarted) after the first operation has been invoked and the second operation on already running workflow is invoked (see sample above), without of setting of the context value following error will occur:

"There is no context attached to incoming message for the service and the current operation is not marked with "CanCreateInstance = true". In order to communicate with this service check whether the incoming binding supports the context protocol and has a valid context initialized."

Here is the whole example with "restarting":

MyDemoSvcClient demoSvc = new MyDemoSvcClient();
IContextManager ctxMg = demoSvc.InnerChannel.GetProperty<IContextManager>();
IDictionary<string, string> ctx = ctxMg.GetContext();

// Simulates restart of the client.
demoSvc = new MyDemoSvcClient();


Posted Apr 22 2008, 02:41 PM by Damir Dobric


Sumit wrote re: Workflow Services: ContextManager is NULL-reference
on 08-24-2009 15:22

IContextManager is not avaliable in WF4.0. How can we achieve the above using WF4.0 Beta 1 release.

Damir Dobric wrote re: Workflow Services: ContextManager is NULL-reference
on 08-24-2009 15:32

ContextManager is no more required. WF 4.0 provides so called Content Based Correlation. Because the correlation is content related, you do not need at the client side any tricks like in WF3.5.

Take a look on this post:

Guilson wrote re: Workflow Services: ContextManager is NULL-reference
on 12-05-2013 22:56

I have been using WCF LOB Adapter Pack to sync SAP HR data into Microsoft Active Directory. It has been working ok in 32 bit OS. But, when I tried using it in a 64 bit OS, I was gnttieg the error "Cannot Load Microsoft.Data.SAP.SAPClient or any of the dependencies". I installed 64 bit WCF LOB Adapter Pack before trying it out. I tried installing 32 bit version into my pc and it won't let me install it as another version of the Adapter Pack was installed already. I will try some other way. But, if anyone have any information regarding this, please post the solution to fix it. is a .Net Community Blog powered by daenet GmbH.