[英]Why does WCF generated proxy wrap contract interface methods with new methods with different signatures?
我使用WCF对SQL Server 2008 SSRS Web服务(... / reportserver / ReportService2005.asmx?wsdl)进行了子操作,据我所知,默认的WCF配置选项。
虽然它在生成本地代理类时做了一些奇怪的事情。
我将使用ListChildren方法作为示例:
在客户端,WCF会像您期望的那样生成这样的接口:
public interface ReportingService2005Soap {
ListChildrenResponse ListChildren(ListChildrenRequest request);
}
它还生成一个实现该接口的“客户端”代理:
public partial class ReportingService2005SoapClient :
System.ServiceModel.ClientBase<ReportingService2005Soap>, ReportingService2005Soap
{
[EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
ListChildrenResponse ReportingService2005Soap.ListChildren(ListChildrenRequest request)
{
return base.Channel.ListChildren(request);
}
public ServerInfoHeader ListChildren(string Item, bool Recursive, out CatalogItem[] CatalogItems) {
ListChildrenRequest inValue = new ListChildrenRequest();
inValue.Item = Item;
inValue.Recursive = Recursive;
ListChildrenResponse retVal = ((ReportingService2005Soap)(this)).ListChildren(inValue);
CatalogItems = retVal.CatalogItems;
return retVal.ServerInfoHeader;
}
}
正如您所看到的,客户端代理实现了接口,然后通过显式实现接口(因此必须强制转换为接口方法)以及另外使用EditorBrowsableState.Advanced属性来“隐藏”它。
然后它添加了一个使用'out'参数的额外包装器方法。
有没有办法停止,如果这样做,并让它直接实现接口?
它在这里做了什么导致你使用带有'out'参数的包装器方法的路径,然后你发现你不能非常容易地模拟服务,因为包装器方法不是虚拟的,并且没有在任何接口中定义。
注意:我在这里使用SSRS Web服务作为示例,但我已经看到WCF也在其他服务上执行此操作。
如果您的服务使用MessageContract
则可能会发生这种情况。 默认情况下,代理创建会尝试解包这些消息协定,以便公开的操作直接接受其内容。 如果要在客户端上使用消息协定,则需要通过选中“ 始终生成消息协定” ,在“ 添加服务引用”的高级设置中对其进行配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.