2011-08-26 36 views
5

我正在使用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也會在其他服務上執行此操作。

+0

如果您轉到添加服務引用的高級設置並檢查「始終生成郵件合同」,會發生什麼情況? –

+0

@拉迪斯拉夫:啊,是的,這似乎解決了它。如果您發佈了答案,我可以投你一票,謝謝。 – codeulike

+0

我的問題得到了'熱門問題'徽章(1000個視圖),但沒有一個單獨的upvote。我應該得到一個反徽章:S – codeulike

回答

6

如果您的服務使用MessageContract s,可能會發生這種情況。默認情況下,代理創建嘗試解開這些消息合約,以便公開的操作直接接受其內容。如果要在客戶端上使用消息合約,則需要在高級設置中通過檢查添加服務參考始終生成消息合同

+0

謝謝,直到現在我都忽略了這個選項。如果它被稱爲'*永遠不會生成垃圾包裝方法*'我可能已經嘗試過了:) – codeulike

相關問題