gpt4 book ai didi

c# - WCF Contract 继承的契约(Contract)

转载 作者:行者123 更新时间:2023-11-30 19:51:32 26 4
gpt4 key购买 nike

我正在使用 WCF 制作一个应用程序的原型(prototype),我正在尝试定义一个回调与派生自另一个接口(interface)的接口(interface)签订契约(Contract)。这样做,生成的代理代码(使用 svcutil.exe)看不到基接口(interface)和“NotSupportedException”在尝试时在服务器上抛出调用基接口(interface)中定义的方法。

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

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

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

这是我的合约定义:

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

最佳答案

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

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

服务类需要继承派生契约(即ITestCallback)。

public class Service1 : ITestCallback
{
...
}

Web.config 文件中相应的端点绑定(bind)需要指定正确的协定(如下面“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,我只是通过在项目中添加服务引用来引用。

关于c# - WCF Contract 继承的契约(Contract),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/957116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com