我正在使用WCF對默認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也會在其他服務上執行此操作。
如果您轉到添加服務引用的高級設置並檢查「始終生成郵件合同」,會發生什麼情況? –
@拉迪斯拉夫:啊,是的,這似乎解決了它。如果您發佈了答案,我可以投你一票,謝謝。 – codeulike
我的問題得到了'熱門問題'徽章(1000個視圖),但沒有一個單獨的upvote。我應該得到一個反徽章:S – codeulike