views:

16

answers:

1

I'm attempting to test a [MessageContract] class against an existing sample message, and I'm looking for a way to simplify development by reading the sample message file into an instance of my [MessageContract] class and seeing how it worked out (I'm dealing with a particularly complex contract here, of non-WCF origin).

My [MessageContract] class looks something like this:

[MessageContract(IsWrapped = true, WrapperName = "wrapper", WrapperNamespace = "somens")]
public class RequestMessage
{
    [MessageHeader(Name = "HeaderElem", Namespace = "otherns")]
    public XElement CorrelationTimeToLive { get; set; }

    [MessageBodyMember(Name = "id", Namespace = "somens")]
    public XElement id { get; set; }
}

I can read the file into an instance of the Message class, using code such as the following:

var xr = XmlReader.Create("sample_message.xml");
var msg = Message.CreateMessage(xr, int.MaxValue, MessageVersion.Soap12);

That's not particulary helpful, however, because it doesn't allow me to test my [MessageContract] class at all.

Somewhere in the guts of WCF is a system for turning this Message instance into an instance of a particular [MessageContract] class, but what is it?

A: 

You will need to deserialize the XML into an instance of your data contract. This is what WCF is doing for you under the covers.

Here is a quick tutorial that will show you how to invoke the DataContractSerializer manually for your XML.

Andrew Hare
Uh, there's no `[DataContract]` here. This is a `[MessageContract]` with things like `[MessageHeader]` and `[MessageBodyMember]` properties.
Mark
Also, the XML file is not just the body part of the soap message, it's the WHOLE COMPLETE envelope.
Mark