WCF契约继承契约 [英] WCF Contract Inherited Contracts

查看:274
本文介绍了WCF契约继承契约的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我protyping与WCF的应用程序,我试图定义一个回调 与源于另外一个接口的合同。 这样,生成的代理code(使用svcutil.exe的)没有看到基 接口和一个NotSupportedException异常正试图抛出时,在服务器上 要调用基接口中定义的方法。

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

有谁知道它为什么不工作呢?

感谢您的帮助和抱歉转贴!

下面是我的合同的定义:

 命名空间wcfContract
{

[的ServiceContract(命名空间=测试)]
公共接口IPing
{
[OperationContract的]
无效平();
}

公共接口ITestCallback:IPing< -------------- IPing方法
没有看到在所有的代理
{
[OperationContract的]
无效TestCB();
}

[的ServiceContract(命名空间=测试,CallbackContract =
typeof运算(ITestCallback))]
公共接口ITEST:IPing
{
[OperationContract的]
无效测试();
}
}
 

解决方案

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

  [的ServiceContract]
公共接口ITestCallback:IPing
{
    [OperationContract的]
    无效TestCB();
}
 

服务类需要继承的衍生合约(即ITestCallback)。

 公共类服务1:ITestCallback
{
    ...
}
 

相应的终点在Web.config文件绑定需要指定正确的合同(如端点地址为WS下)。

 <服务>
  <服务名称=WcfService.Service1behaviorConfiguration =WcfService.Service1Behavior>
    <! -  ITestCallback需要在合同中注明 - >
    <端点地址=WS绑定=的wsHttpBinding合同=WcfService.ITestCallback>
    < /端点>
    <端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
  < /服务>
< /服务>
 

这为我工作;希望它为你工作。我没有使用SvcUtil工具,我只是在一个项目中添加一个服务引用引用。

I'm protyping an application with WCF and I'm trying to define a Callback Contract with an interface that derives from another one. 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.

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]
public interface ITestCallback : IPing
{
    [OperationContract]
    void TestCB ();
}

The service class needs to inherit the derived contract (ie. 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).

<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.

这篇关于WCF契约继承契约的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆