![](/img/trans.png)
[英]Code Contracts: IEnumerator<T>.GetEnumerator() weird inherited contract?
[英]WCF Contract Inherited Contracts
我正在使用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();
}
}
您需要将[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,我只是通过在项目中添加服务引用来引用。
您是否尝试将[ServiceContract]标签添加到ITestCallback?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.