开发者

Using KnowTypeAttribute in WCF Service

开发者 https://www.devze.com 2023-01-06 00:39 出处:网络
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 El开发者_开发技巧ement interface defined like so

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 El开发者_开发技巧ement 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


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:

[DataContract]
[KnownType(typeof(Pet))]
[KnownType(typeof(...
...
public class Element: IElement
{
....
0

精彩评论

暂无评论...
验证码 换一张
取 消