本文介绍了请WCF MessageContract澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 MessageContract Attribute 在 WCF 中的工作方式有点困惑.

I'm bit confused with how MessageContract Attribute works in WCF.

当我放置 MessageContract 时,代理显示两个参数而不是 1.例如

When I put the MessageContract the proxy shows two parameters instead of 1.e.g.

GetResultResponse GetOperation(GetResultRequest request)

[MessageContract]
public class GetResultRequest 
{
   [MessageHeader]
   public Header Header { get; set; }
   [MessageBodyMember]
   public List<Person> PersonList { get; set; }

}

代理生成此方法签名:

GetOperation(ref Header, List<Person> personList)

当我删除 MEssageContract 属性时:代理生成正确的签名:

When I remove MEssageContract Attributes:Proxy Generates correct signatures:

GetOperation(GetResultRequest request)

有人可以确认这是否是预期的行为吗?

Could anyone please confirm if this is the expected behavour?

推荐答案

这是默认行为.当您生成代理时,默认情况下它不会创建消息合同.您可以在添加服务参考中的高级配置中启用此功能(通过检查始终生成消息合同)或通过.打开它后,您将获得与服务相同的具有单个消息协定参数的方法.

That is default behavior. When you generate proxy it doesn't create message contracts by default. You can turn this on in advanced configuration in Add Service reference (by checking Always generate message contracts) or by /messageContract switch in svcutil. Once you turn it on you will get methods with single message contract parameter as you have on the service.

这篇关于请WCF MessageContract澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 14:03