Wednesday, July 28, 2010

WCF Interop Services

I was trying to architect and implement an Enterprise Service bus using WCF at work. One of the key components of this Service bus was to consume vendor services that were on non (.Net) platforms. This had been previously implemented using web services, but trying to implement the same using WCF was a whole new ball game. The two main challenges I came across were establishing a secure binding and getting the data types to match.

Challenge one

Get the binding to work correctly. The vendor documentation was quiet limiting with regards to establishing a connection. So after a lot of mucking around and guesses I went to basics and accessed service directly via code. This provided me a much better insight into the expected configuration.

Challenge two

Get the data types to match. This meant generating the data objects from their data schema and then converting it back into XML that can be passed back to the service. Fortunately got the schema (xsd) files for the objects used in the Java web service from the vendor.

After several attempts of trying to generate data-contracts from the XSD and trying to serialize them back to valid XML that I could pass back to the java web service using different combinations of svcutil, xsd.exe, XmlSerializer Class and DataContractSerializer Class. The one that worked was to use xsd.exe to create my data objects and XML Serializer to convert it back to XML to pass back
to the Java web service.

Several attempts to use SVCUtil were in vain, I think it has a long way to go before becoming a mature tool like xsd.exe especially when it comes down to generating data objects from datacontracts. On the other hand the xsd.exe seemed to be more robust and well documented. Following is the line I used in a batch file that I hook to VS pre-build step.

xsd -c -l:c# -n:[Namespace] [schemafile.xsd]

* Each schema requires to be run on its own I One thing that I did notice was that
* One thing I noticed when using Svcutil is that it requires you specify the included/linked schema in the same executing line. Else you will end up with fields(appends a field to the property) being serialized instead of properties. The best option was to use a wild card.

No comments: