Over a week ago the Web Services Contract First (WSCF) project announced the "blue" version which supports WCF.  WSCF is a great tool that saved my butt on a large integration project with one of our fine 3-letter agencies a few years back.  The tool boasts the ability to take a WSDL and Schema files and turn them into C# or VB code.  When I saw the new release I had to give it a try.

My first run went smooth but I noted the WSCF tool generated the service contract interface type without the "I" prefix.  I reported this to the team and they promptly fixed it and even tried it against the DOJ LEXS WSDLs that I was working on.  Many thanks to Christian Weyer and Alex Meyer-Gleaves for responding so quickly.

In the government data sharing space there is a lot of contract first development happening.  The NIEM IEPD process encourages developing both the business need and data schemas before you begin coding the exchange.  I think this is a great approach to take and helps everyone from the business analysts to the technical analysts understand the exchange, the data to be exchanged, and the overall process. 

Having an open source tool like WSCF is a great addition to your toolbox when interop is key.

As I migrated a soon-to-be-released open source project to it’s new solution I used WSCF to generate all the classes and service stub.  The following are some tips I have when you are using WCF + XmlSerializer; these really have nothing to do with WSCF, you will get the same if you use SvcUtil directly.  That said I think WSCF generates the classes from the schemas with a lot less effort and actually better than Svcutil directly.

Tips for WCF + XmlSerializer

Tip 1: For types that are marked with a MessageContractAttribute and IsWrapped=True, if you inherit from a base class that exposes a public XmlSerializerNamespaces property the namespaces are not properly serialized.  XmlSerializerNamespaces are used when you want to control the namespace prefixing and output during serialization.  This is accomplished by creating a public field with the name "xmlns" and marking it up with the XmlNamespaceDeclarationAttribute.  The XmlSerializer uses the presence of this field to output the Xml Namespaces and the associated prefixes within the element from the object in the object graph where the attribute was applied.

Tip 2: If you have a class marked with the MessageContractAttribute and you inherit from a base class within that class then the base class must also be marked with the MessageContract attribute.  WCF gives you a nice error message explaining this because it is unable to start the service.

Tip 3: In some cases both SvcUtil and WSCF generate ReplyAction="*" on the WSDL.  This could potentially make it fail in an interop scenario.  Not exactly sure what causes that but in any case, if you have trouble then remove that from the service contract.  A tell tale sign is that when you view the WSDL page for your service you do not see any of the operations listed.