Wednesday, May 16, 2012

Orchestration exposed as WCF service adds default serialization namespace to incoming and outgoing messages of type String, Int32, ..

If we need to publish an orchestration with message types System.String, System.Int32, ... (simple .NET Classes message types) as WCF service, we have to publish selecting "Publish Schemas as WCF service", instead of "Publish BizTalk orchestrations as WCF service"..

THE PROBLEM

I have developed a simple solution, with an orchestration that receives a System.Int32 message and returns a System.String message:


If we publish this orchestration as WCF service, using "Publish BizTalk orchestrations as WCF service", in the generated WSDL, we will find this messages:


Look that message types are int and string, but both namespaces are http://schemas.microsoft.com/2003/10/Serialization/.

I implemented a simple test C# console application to invoke the WCF service:


When I run this test console application, an unexpected exception is thrown:

<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/"> was not expected.
       
Exception type: InvalidOperationException
Source: System.Xml
Target Site: System.Object Read_int()


THE SOLUTION
 
To avoid this error, we have to publish our solution using "Publish Schemas as WCF service" and include in our project a schema with primitive types, like: 


 
And then publish our WCF service publishing this schemas as:


In this step, the operation name have to be the same as operation name in orchestration (ReceiveInt32) and in request and response schema type, we have to select our schema with primitive types:




 

No comments: