Archive for January, 2007

Soap Headers in WCF, where have they gone.

WCF offers several different approaches for writing Web Services; Contract first, Code first, with slight variations on either approach.

I personally prefer the Code first approach and find it much easier to think of messages in terms of objects. With the Code First approach in WCF, you define a contract which will later be used to generate your WSDL. WCF provides Data Contracts as the preferred approach to abstracting out your message.

To use Data Contracts you mark your class with the DataContract attribute and the properties you wish to expose for serialisation with the DataMember attribute, the object would then serialised using the DataContractSerializer; a limitation with this approach is that you don’t have full control over serialisation, so it would be difficult to work with classes that may have been generated using xsd.exe for example.

WCF offers another Code First solution that gives you full control over serialisation; you can mark your classes with the Serializable attribute and the Service Contract Interface with XmlSerializerFormat attribute to leverage the XmlSerializer.

The XmlSerializerFormat approach seemed like an ideal solution to a recent project, giving me full control over the serialization of the soap body. I next needed to do a similar thing to the soap header. WCF uses Message Contracts to give you control over the soap message, you basically decorate the class that represents your message with the MessageContract attribute then properties in that class with MessageHeader and MessageBody attributes, represent the SOAP header and SOAP body respectively.

The abstraction the SOAP envelope using the Message Contract is not compatible with the XmlSerializerFormat approach, you can only use it with DataContract approach and there doesn’t appear to be a similar abstraction to use with the XmlSerializerFormat approach. This has left me a bit puzzled as to the best way to harness the XmlSerializer for SOAP headers. I’m sure the answer must be to dip into the WCF pipeline at another point to process the header, but nowhere feel’s natural to do so.

Any thoughts or ideas on this would be welcome.

Comments (2) del.icio.us

New Year’s Resolution, Blog More

I haven’t written a blog post for ages, so as a (few weeks after) New Year’s resolution I am going to try to write a bit more regularly.

I am studying for the MCPD Web Developer exam, so hopefully I will get a bit of inspiration from some of the things I learn.

I have also been looking at WCF in work, so will probably have a few posts related to that, as I try to get to grips with what seems a very powerful way to develop web services.

There is a whole host of other new thing to learn, such as LINQ, WWF and WPF. Where am I going to find the time??

Comments del.icio.us