Workflow Services error: "Operation is not implemented by the service"

I been trying to solve this Workflow Services error on my IssueTracker project for 2 weeks without any progress. :(

Operation is not implemented by the service.
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)\r\n   at

System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)\r\n   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException rethrown at [0]: \r\n   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n   at IssueTrackerTest.IssueProcessService.IIssueProcess.ProcessIssue(Issue issue)\r\n   at IssueTrackerTest.IssueProcessService.IssueProcessClient.ProcessIssue(Issue issue) in C:\\Workspace\\Projects\\IssueTracker\\IssueTrackerTest\\Service References\\IssueProcessService\\Reference.cs:line 285\r\n   at IssueTrackerTest.IssueProcessTest.TestProcessIssue() in C:\\Workspace\\Projects\\IssueTracker\\IssueTrackerTest\\IssueProcessTest.cs:line 88″    string

 

Until today I found this blog post by Damir Dobric.

While invoking an operation on the workflow’s web service you may get following error:

“Operation is not implemented by the service.”

To solve the problem take a look on the ContextToken property of the receive-activity of the workflow service.
If this property is set as shown on the picture below, remove the value, rebuild solution and start all again.

image

 

Thanks Damir for saving my days :)

Workflow Foundation and LINQ2SQL: Of BinaryFormatter and DataContractSerializer

There seem to be quite a lot of questions in forums and blog post about inability of have LINQ to SQL object in a Workflow Foundation’s Activity execution. Most of the time, you will end up getting a error message as below

Type ‘System.Data.Linq.ChangeTracker+StandardChangeTracker’ in Assembly ‘System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ is not marked as serializable.

After I did some research and found out about serialization method in LINQ to SQL here:

http://msdn.microsoft.com/en-us/library/bb386929.aspx

Code generation in LINQ to SQL supports DataContractSerializer serialization. It does not support XmlObjectSerializer or BinaryFormatter. For more information, see Serialization (LINQ to SQL).

However for Workflow Foundation, it is using BinaryFormatter to serialize objects into persistent layer (refer the MSDN document here)

When the workflow runtime encounters a persistence point during workflow instance execution, it calls the persistence service to do the work. The persistence service will then serialize the workflow state into a stream using BinaryFormatter serialization, optionally compress it, and save it into a durable store.

As such there is a crash here which renders LINQ to SQL entities can’t be used in Workflow Foundation. Fortunately Serena Yeoh found a solution and put it into her project at Layer Sample. You can found out more at this forum thread. Basically her code will take LINQ to SQL objects, clone it and serialize it using DataContractSerializer first before committing changes. Then after that it will return the cloned copy.