Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control the name of a generic WCF Message Contract

Tags:

.net

wcf

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?

like image 226
Paul Turner Avatar asked Oct 18 '10 17:10

Paul Turner


1 Answers

It seems like a lot of work for what you want to accomplish, but I believe you can create a MessageInspector which will allow you to interact directly with the XML.

Client message inspectors implement the IClientMessageInspector interface and service message inspectors implement the IDispatchMessageInspector interface.

http://msdn.microsoft.com/en-us/library/aa717047.aspx

Any service (dispatcher) message inspector must implement the two IDispatchMessageInspector methods AfterReceiveRequest and BeforeSendReply.

The link goes into much more detail, but once you have these implemented, you should be able to add the inspector to your web.config and you should be all set.

like image 63
marcellscarlett Avatar answered Jan 15 '23 17:01

marcellscarlett