WCF - IEnumerable <T> format using DataMember Exception: the underlying connection was closed: the connection was unexpectedly closed

I created a WCF service that returns an IEnumerable<CyberResourceProvisioningAction> .

The CyberResourceProvisioningAction type has the AccountInformation IEnumerable<CyberResourceProvisioningActionAccountInfo> property. When I decorate the AccountInformation property with a DataMemberAttribute, I get an exception:

WCF System.Net.WebException: underlying connection was closed: connection was unexpectedly closed

Obviously, a very general exception, but my Google-fu indicates that the problem most often occurs when returning a large number of objects in the collection. A suggested fix is ​​to set <dataContractSerializer maxItemsInObjectGraph="2147483646"/> . Unfortunately, this did not fix my problem. (I did not think it would be when I return a small amount of data).

Properties are set correctly, so I'm sure my problem is with my serialization configuration. Is there something wrong with my classes that causes a WCF error this way?

 [DataContract] public class CyberResourceProvisioningAction { [DataMember] public string Action { get; set; } [DataMember] public DateTime RcdChgDateTime { get; set; } [DataMember] public string CyberResourceName { get; set; } [DataMember] public IEnumerable<CyberResourceProvisioningActionAccountInfo> AccountInformation { get; set; } } 

CyberResourceProvisioningActionAccountInfo

 [DataContract] public class CyberResourceProvisioningActionAccountInfo { [DataMember] public string Name { get; set; } [DataMember] public string Value { get; set; } } 

If additional configuration information is required, let me know and I will edit the message.

+8
c # ienumerable wcf
source share
1 answer

Due to the comment on “breaking the DataContract programming model” left by alexdej , I started to get a little closer to what was in my properties. I had a Linq type in a property, and although it was IEnumerable, it did not list for serialization. Added .ToList() , and all is well.

+14
source share

All Articles