WCF合同继承合同

Jas*_*ker 2 .net c# wcf

我正在使用WCF对应用程序进行原型设计,并且我正在尝试使用从另一个接口派生的接口来定义回调契约.这样做时,生成的代理代码(使用svcutil.exe)看不到基接口,并且在尝试调用基接口中定义的方法时,服务器上会抛出"NotSupportedException".

我还尝试在代理类中手动定义基接口,以便能够在客户端实现方法 - >相同的行为.

有谁知道为什么它不起作用?

感谢您的帮助,并对转发感到抱歉!

这是我的合同定义:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

Ste*_*nan 6

您需要将[ServiceContract]属性添加到ITestCallback接口.

[ServiceContract]
public interface ITestCallback : IPing
{
    [OperationContract]
    void TestCB ();
}
Run Code Online (Sandbox Code Playgroud)

服务类需要继承派生合同(即ITestCallback).

public class Service1 : ITestCallback
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

这对我有用; 希望对你有效.我没有使用svcutil,我只是通过在项目中添加服务引用来引用.