在 WCF 服务中使用 KnowTypeAttribute
我遇到一种情况,我需要将对象列表传递给我的服务。这些对象必须是 ELEMENT 类型。我的 Element 接口像这样定义
public interface IElement{ }
然后我的 DataContracts 继承这个 IElement 类就像这样。 。 。 。
[KnownType(typeof(Common.IElement))]
[DataContract]
public abstract class IPet : IElement
{.....}
我的 Service 接口上也有一个 KnownType 属性,如下所示
[ServiceContract(Name="Pets", SessionMode = SessionMode.Allowed)]
[ServiceKnownType(typeof(Memberships.PetServiceUser))]
[ServiceKnownType(typeof(.Common.IElement))]
[DeliveryRequirements(RequireOrderedDelivery=true)]
public interface IPetService {.....}
问题出在客户端,IElement 类型在客户端上的服务类型反序列化时不可用。知道我在这里可能做错了什么以及如何纠正这个问题吗?
没有任何
I have a situation where I need to pass a list of objects to my service. The objects have to be of type ELEMENT. I have my Element interface defined like so
public interface IElement{ }
Then I have my DataContracts inheriting this IElement class Like so . . . .
[KnownType(typeof(Common.IElement))]
[DataContract]
public abstract class IPet : IElement
{.....}
I also have a KnownType attribute on my Service interface like so
[ServiceContract(Name="Pets", SessionMode = SessionMode.Allowed)]
[ServiceKnownType(typeof(Memberships.PetServiceUser))]
[ServiceKnownType(typeof(.Common.IElement))]
[DeliveryRequirements(RequireOrderedDelivery=true)]
public interface IPetService {.....}
Problem is on the client side, the IElement type is not available on deserialization of service types on client. Any idea what I may be doing wrong here and how I can go about correcting this please?
None
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能百分百确定我理解你在这里尝试做的一切,但对我来说这似乎是颠倒的。使用 KnownType 属性的常用方法是用派生类型修饰基类型。大致如下:
I'm not 100 percent sure I understand everything you're trying to do here, but it seems upside-down to me. The usual way to use the KnownType attribute is to decorate the base type with the derived types. Something along the lines of: