开发者

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

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

I have created a generic request message contract like so:

[MessageContr开发者_StackOverflow中文版act]
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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜