I am encountering an exception when my WCF service attempts to create the data contract response class.
I thought that this problem might be have resulted from WCF not knowing how to Serialize IEnumberable, so I marked it as a known type. This did not work.
Any help on this would be quite welcome!!!
Details below.
Many thanks,
Mark
Service Contract:
[ServiceContract]
public interface IRefundService
{
[OperationContract]
RefundSearchCriteriaResponse FindRefunds(RefundSearchCriteriaRequest refundSearchCriteriaRequest);
}
Data Contract:
[DataContract]
[KnownType(typeof(List
public class RefundSearchCriteriaResponse
{
[DataMember]
public IEnumerable
[DataMember]
public int ItemCount { get; set; }
}
Exception Details:
Exception: InvalidDataContractException
Message: Type 'System.Linq.OrderedEnumerable`2[Asos.Operations.Finance.ElectronicFunds.Entity.Refund,System.Nullable`1[System.Int64]]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.
Call stack:
System.Runtime.Serialization.dll!System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(string message, System.Type type) + 0x12a bytes
------------------------------------------------------------------------------------------
System.Runtime.Serialization.dll!System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(int id, System.RuntimeTypeHandle typeHandle, System.Type type = {Name = "OrderedEnumerable`2" FullName = "System.Linq.OrderedEnumerable`2[[Asos.Operations.Finance.ElectronicFunds.Entity.Refund, Asos.Operations.Entity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}) + 0x20f bytes
------------------------------------------------------------------------------------------
System.Runtime.Serialization.dll!System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(int id = 28, System.RuntimeTypeHandle typeHandle, System.Type type) + 0x4b bytes

Mark ConwayPosted Jun 8, 2011, 2:45 PM
Changing the IEnumerable
Data Contract:
[DataContract]
[KnownType(typeof(List
public class RefundSearchCriteriaResponse
{
[DataMember]
[DataMember]
public int ItemCount { get; set; }
}
Mark ConwayPosted Jun 8, 2011, 4:55 AM
My Refund type is marked as a [DataContract] and its properties are marked as DataMembers.
The thing is, the service method used to just return IEnumerable
This service only started failing to serialize the response when I wrapped the IEnumerable
Posted Jun 8, 2011, 1:04 AM
http://www.kim-team.com/blog/2008/12/business-objects-and-wcf/
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/be796bd0-2502-4bd3-96d9-60bf7d68930d
http://blogs.msdn.com/b/youssefm/archive/2009/08/10/serializing-plain-old-clr-objects-poco-types-with-datacontractserializer.aspx