Ron Jacobs

Windows Workflow Foundation

WorkflowServices, CanCreateInstance and Silverlight

WorkflowServices, CanCreateInstance and Silverlight

Rate This
  • Comments 1

I can’t count how many times this has bitten me…  You create a new Workflow Service.  You create a client app, add a service reference and boom!

There is no context attached to the 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.

For some strange reason, our default Workflow Service template is designed to teach you a lesson the first time you run it.  It will blow up with this exception forcing you to go and check CanCreateInstance on the receive activity.  I’m sure this surprised no one because all of you have probably run into this. 

Then I tried calling the WorkflowService from a Silverlight app.  Now instead of the message above I get this exception

System.ServiceModel.CommunicationException was unhandled by user code Message=The remote server returned an error: NotFound.

Not Found?

I thought I was going crazy.  I tried all sorts of things and even opened a bug on WorkflowServices and got the WCF/Silverlight guys involved.  They asked me to look at this under Fiddler and see what the response was and guess what I saw…

HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/10.0.0.0
Date: Tue, 26 Apr 2011 21:31:32 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 539
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Connection: Close

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2006/05/context">a:MissingContext</faultcode><faultstring xml:lang="en-US">There is no context attached to the 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.</faultstring></s:Fault></s:Body></s:Envelope>

Doh! I just wasted a bunch of time and email on this because the exception message was “Not Found”.

I’m still trying to figure out why I got Not Found instead of the other exception text but just in case somebody is trying to understand why they are having trouble invoking a workflow service from Silverlight, don’t forget CanCreateInstance!

image

One more thing… My WCF/Silverlight friends pointed out that this is a well known issue – see Creating and Handling Faults in Silverlight for more info.  The Silverlight-enabled WCF Service correctly handles this so you can look and see how it was done there if you like.

Page 1 of 1 (1 items)