我怎样才能组成一个WCF合同出了多个接口? [英] How can I compose a WCF contract out of multiple interfaces?
问题描述
我已经得到了多个接口。所有这些都应该由单一的合同接口继承和曝光。
I've got multiple interfaces. All of them should be inherited and exposed by a single contract interface.
interface A { void X(); }
interface B { void Y(); }
interface C: A, B {} // this is the public contract
这怎么可能呢?我不能添加的ServiceContract A和B,因为这将导致多个端点。我不希望新覆盖在C中的每一个方法。
How is this possible? I can't add ServiceContract to A and B because that would lead to multiple endpoints. And I don't want to new-override every method in C.
推荐答案
你是完全正确的属性,如 [的ServiceContract]
键,如不会继承 - 你需要明确设置它们应该是服务合同的任何接口上。这同样适用于 [DataContract]
属性的具体数据类 - 这些都不是继承的,要么 - 如果一个子类的数据契约本身应该是一个数据的合同,它需要必须明确标记为多。默认情况下,尝试WCF让你很明确你的目的(这是一件好事,我会说)。
You're are absolutely correct that attributes like [ServiceContract]
and such are not inherited - you need to explicitly set them on any interface that should be a service contract. The same applies to [DataContract]
attributes on concrete data classes - those are not inherited, either - if a descendant class of a data contract should itself be a data contract, it needs to be explicitly marked up as much. WCF by default tries to make you be very explicit about your intent (which is a good thing, I would say).
不知道你从创作这样的接口获得,但你可以最肯定有一个服务实现(具体的类),它实现了多个有效的WCF服务合同(接口) - 没有任何问题与建立
Not sure what you gain from composing interfaces like this, but you can most definitely have a service implementation (concrete class) which implements multiple valid WCF service contracts (interfaces) - no problem at all with that setup.
这篇关于我怎样才能组成一个WCF合同出了多个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!