简体   繁体   English

WCF合同继承合同

[英]WCF Contract Inherited Contracts

I'm protyping an application with WCF and I'm trying to define a Callback Contract with an interface that derives from another one. 我正在使用WCF对应用程序进行原型设计,并且我正在尝试使用从另一个接口派生的接口来定义回调契约。 Doing so, the generated proxy code (using svcutil.exe) does not see the base interface and a "NotSupportedException" is thrown on the Server when trying to call methods defined in base interface. 这样做时,生成的代理代码(使用svcutil.exe)看不到基接口,并且在尝试调用基接口中定义的方法时,服务器上会抛出“NotSupportedException”。

I have also tried to manually define the base interface in the proxy class so as to be able to implement the methods in the client -> Same behavior. 我还尝试在代理类中手动定义基接口,以便能够在客户端中实现方法 - >相同的行为。

Does anyone knows why it does not work? 有谁知道为什么它不起作用?

Thanks for any help and sorry for the repost! 感谢您的帮助,并对转发感到抱歉!

Here is my contract definition : 这是我的合同定义:

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();
    }
}

You'll need to add the [ServiceContract] attribute to the ITestCallback interface. 您需要将[ServiceContract]属性添加到ITestCallback接口。

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

The service class needs to inherit the derived contract (ie. ITestCallback). 服务类需要继承派生合同(即ITestCallback)。

public class Service1 : ITestCallback
{
    ...
}

The corresponding endpoint binding in the Web.config file needs to specify the correct contract (as in the endpoint address for "ws" below). 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>

This worked for me; 这对我有用; hope it works for you. 希望对你有效。 I didn't use the svcutil, I just referenced by adding a service reference in a project. 我没有使用svcutil,我只是通过在项目中添加服务引用来引用。

您是否尝试将[ServiceContract]标签添加到ITestCallback?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM