我可以从多个接口中编写WCF回调契约吗?

时间:2010-03-23 21:24:20

标签: .net wcf

How can I compose a WCF contract out of multiple interfaces?的跟进问题。

我尝试在单个界面中合并多个回调接口。这会产生一个InvalidOperationException声明最终接口不包含任何操作。从技术上讲,这是事实,但是,继承的接口确实包含操作。

我该如何解决这个问题?或者这是WCF的限制吗?

编辑:

[ServiceContract]
// Using the following line instead would be no problem for me:
// [ServiceContract (CallbackContract = CallbackA)]
interface ServiceA { [OperationContract]void X(); }

[ServiceContract] // same here
interface ServiceB { [OperationContract]void Y(); }

interface CallbackA { [OperationContract]void CB_A() } // required in ServiceA
interface CallbackB { [OperationContract]void CB_B() } // required in ServiceB

interface CallbackC: CallbackA, CallbackB {} // composed callback contract

[ServiceContract (CallbackContract = CallbackC)]
interface ServiceC: ServiceA, ServiceB {} // composed service contract

1 个答案:

答案 0 :(得分:1)

很难说没有看服务合同本身的合同层级,但答案可能依赖于这个原则:

"A service contract can only designate a callback contract if that contract is a subinterface of all callback contracts defined by the contract's own base contracts."

  • (编程WCF服务,O'Reilly,请参阅“回调合同层次结构”下的here)。