grady
grady

Reputation: 12785

Use a value object which contains generic ILists with a web service?

I have a value object which contains multiple generic lists:

public IList<SomeClass> MyList { get; set; }
// ...

Now I cant serialize that to make it work with a web service. How could I do that?

Thanks :-)

Upvotes: 1

Views: 328

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064104

If you can't change the existing object, then your main option is to use a DTO that looks similar to the existing object, but which has properties / behaviours that the serializer you are using (XmlSerializer for asmx, DataContractSerializer by default for svc) can handle. For example, it would have:

public List<SomeClass> MyList {get;set;}

or even:

public List<SomeClassDto> MyList {get;set;}

You might be able to map between these representations using AutoMapper, or do it by hand.

If you are using WCF, you might also be able to swap the serializer at runtime to support generic interface-based lists like IList<T>

Upvotes: 1

Related Questions