I have an object that has a generic IList in it that is being returned from a WCF web service method:
[DataContract(Name = "PageableList_Of_{0}")]
public class PageableResults<T>
{
[DataMember]
public IList<T> Items { get; set; }
[DataMember]
public int TotalRows { get; set; }
}
[OperationContract]
PageableResults<ContentItem> ListCI();
When I call this method on the service it executes the entire method fine, but at the very end it throws a System.ExecutionEngineException without an InnerException. I've tried returning a concrete List<> object and that seems to work, but unfortunately I need to find a workaround to return an IList. Are there any attributes I need to put in to solve this?
You'll have to add KnownTypes attribute on the class definition above your class definition for each usage of T. Like this:
[KnownType(typeof(ContentItem))]
[DataContract(Name = "PageableList_Of_{0}")]
public class PageableResults<T>
{
[DataMember]
public IList<T> Items { get; set; }
[DataMember]
public int TotalRows { get; set; }
}
[OperationContract]
PageableResults ListCI();
Alternatively you can define your own collection class, that has a TotalRows property, like this:
[KnownType(typeof(ContentItem))]
[DataContract(Name = "PageableList_Of_{0}")]
public class PageableResults<T> : EntityCollectionWorkaround<T>
{
[DataMember]
public int TotalRows { get; set; }
}
Where EntityCollectionWorkaround is defined here:
http://borismod.blogspot.com/2009/06/v2-wcf-collectiondatacontract-and.html
I don't think you can do this. How will the serializer know what to desearialize to? Lots of things could implement an IList, and an interface doesn't have a constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With