2009-06-05 93 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