tags:

views:

27

answers:

1

I'm generating a WCF service using the message contract model.

I have created a generic request message contract like so:

[MessageContract]
public Request<T>
{
    [MessageBodyMember]
    public T Details { get; set; }
}

I'm used to using [DataContract(Name="Contract{0}")] to produce readable names for generic data contracts, but this approach does not seem to work for me using message contracts.

Is there a way to achieve the same behaviour using the message contract model?

A: 

There's a WrapperName and WrapperNamespace property on the MessageContract attribute that I think does the same thing. E.g.,

[MessageContract(WrapperName = "FooMessage", IsWrapped = true)]
public class Request<T>
{ ... }

Note the addition of the IsWrapped property to indicate that the message should be serialized into the wrapper element.

Tim Roberts
I tried this using WrapperName = "WrapperFor{0}", but this resolved to a pretty nasty name in the WSDL (the Unicode equivalent of {0}) and did not perform the translation I had expected.
Programming Hero