如何控制通用 WCF 消息协定的名称 [英] How can I control the name of a generic WCF Message Contract

查看:24
本文介绍了如何控制通用 WCF 消息协定的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用消息契约模型生成 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; }
}

我习惯于使用 [DataContract(Name="Contract{0}")] 来为通用数据合同生成可读的名称,但这种方法似乎对我使用 message 不起作用合同.

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?

推荐答案

对于您想要完成的工作,似乎需要做很多工作,但我相信您可以创建一个 MessageInspector,它允许您直接与 XML 交互.

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.

客户端消息检查器实现 IClientMessageInspector 接口,服务消息检查器实现 IDispatchMessageInspector 接口.

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

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

任何服务(调度程序)消息检查器都必须实现两个 IDispatchMessageInspector 方法 AfterReceiveRequestBeforeSendReply.

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

该链接更详细,但是一旦您实现了这些,您应该能够将检查器添加到您的 web.config 中,并且您应该已经设置好了.

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.

这篇关于如何控制通用 WCF 消息协定的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆