我使用WCF对SQL Server 2008 SSRS Web服务(.../reportserver/ReportService2005.asmx?wsdl)进行了子操作,据我所知,默认的WCF配置选项.
虽然它在生成本地代理类时做了一些奇怪的事情.
我将使用ListChildren方法作为示例:
在客户端,WCF会像您期望的那样生成这样的接口:
public interface ReportingService2005Soap {
ListChildrenResponse ListChildren(ListChildrenRequest request);
}
Run Code Online (Sandbox Code Playgroud)
它还生成一个实现该接口的"客户端"代理:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,客户端代理实现了接口,然后通过显式实现接口(因此必须强制转换为接口方法)以及另外使用EditorBrowsableState.Advanced属性来"隐藏"它.
然后它添加了一个使用'out'参数的额外包装器方法.
有没有办法停止,如果这样做,并让它直接实现接口?
它在这里做了什么导致你使用带有'out'参数的包装器方法的路径,然后你发现你不能非常容易地模拟服务,因为包装器方法不是虚拟的,并且没有在任何接口中定义.
注意:我在这里使用SSRS Web服务作为示例,但我已经看到WCF也在其他服务上执行此操作.
如果您的服务使用MessageContracts,可能会发生这种情况.默认情况下,代理创建会尝试解包这些消息协定,以便公开的操作直接接受其内容.如果您还想在客户端上使用消息合同,则需要通过选中始终生成消息合同,在添加服务引用的高级设置中对其进行配置.
| 归档时间: |
|
| 查看次数: |
2130 次 |
| 最近记录: |