在WCF服务中使用KnowtyPeattribute
-
13-09-2020 - |
题
我有一个情况,我需要将对象列表传递给我的服务。对象必须是类型元素。我有我的元素接口定义如此
public interface IElement{ }
.
然后我有我的DataContracts继承这个iElement类。。。。
[KnownType(typeof(Common.IElement))]
[DataContract]
public abstract class IPet : IElement
{.....}
.
我在我的服务界面上也有一个已知型属性,如此
[ServiceContract(Name="Pets", SessionMode = SessionMode.Allowed)]
[ServiceKnownType(typeof(Memberships.PetServiceUser))]
[ServiceKnownType(typeof(.Common.IElement))]
[DeliveryRequirements(RequireOrderedDelivery=true)]
public interface IPetService {.....}
.
问题在客户端,IElement类型在客户端上的服务类型的反序列化上不可用。任何想法我可能在这里做错了什么,我如何能够纠正这个?
none
解决方案
我不是100%,肯定我理解你想要在这里做的一切,但它似乎颠倒了我。常用方法使用nemardType属性是用派生类型装饰基本类型。沿着以下方式的东西:
[DataContract]
[KnownType(typeof(Pet))]
[KnownType(typeof(...
...
public class Element: IElement
{
....
. 不隶属于 StackOverflow