2009-06-05 55 views
2

我正在用WCF模擬應用程序,並試圖定義一個回調 契約與從另一個派生的接口。 這樣做時,生成的代理服務器代碼(使用svcutil.exe)看不到接口基址 ,並嘗試使用 來調用在基本接口中定義的方法時,服務器上將拋出「NotSupportedException」。WCF契約繼承合同

我也嘗試在代理類 中手動定義基接口,以便能夠在客戶端 - >相同行爲中實現方法。

有誰知道它爲什麼不起作用?

感謝您的任何幫助和遺憾的轉發!

這裏是我的合同的定義:

namespace wcfContract 
{ 

    [ServiceContract(Namespace = "Test")] 
    public interface IPing 
    { 
     [OperationContract] 
     void Ping(); 
    } 

    public interface ITestCallback : IPing  
    //<-------------- IPing method not seen at all in proxy 
    { 
     [OperationContract] 
     void TestCB(); 
    } 

    [ServiceContract(Namespace = "Test", CallbackContract = 
     typeof(ITestCallback))] 
    public interface ITest : IPing 
    { 
     [OperationContract] 
     void Test(); 
    } 
} 

回答

6

您需要將[ServiceContract]屬性添加到ITestCallback接口。

[ServiceContract] 
public interface ITestCallback : IPing 
{ 
    [OperationContract] 
    void TestCB(); 
} 

服務類需要繼承派生合約(即ITestCallback)。

public class Service1 : ITestCallback 
{ 
    ... 
} 

相應的端點在Web.config文件結合需要指定正確的合同(如在端點地址爲「WS」下文)。

<services> 
    <service name="WcfService.Service1" behaviorConfiguration="WcfService.Service1Behavior"> 
    <!-- ITestCallback needs to be the contract specified --> 
    <endpoint address="ws" binding="wsHttpBinding" contract="WcfService.ITestCallback"> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 

這對我有效;希望對你有效。我沒有使用svcutil,我只是通過在項目中添加服務引用來引用它。

+0

非常感謝! – 2009-06-05 18:13:32

2

你嘗試添加[的ServiceContract]標籤ITestCallback?

+0

我做了 - 無濟於事。 – 2009-06-05 17:58:48