8

I have created a WCF service which returns IEnumerable<CyberResourceProvisioningAction>.

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

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

Obviously a very generic exception, but my Google-fu indicates that the issue most commonly occurs when returning large numbers of objects in a collection. The suggested fix is to set the <dataContractSerializer maxItemsInObjectGraph="2147483646"/>. Unfortunately this has not fixed my issue. (Didn't think it would as I am returning a small amount of data).

The properties are being set correctly so I am pretty sure my issue has to do with my serialization configuration. Is there something wrong with my classes which is causing the WCF service to error in 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'll edit the post.

ahsteele
  • 26,243
  • 28
  • 134
  • 248
  • 2
    if you have the help page enabled, browse to it to see if you're getting an activation exception; otherwise attach a debugger and trap exceptions. It sounds like it might be a DataContract programming model violation. – alexdej Feb 03 '11 at 20:44
  • @alexdej I've attached a debugger but never trap any exceptions. The exception shows up in the WCF Test Client but not my debugger. – ahsteele Feb 03 '11 at 21:02
  • 1
    Try debugging your WCF host project directly, and test your servicecall with the `WcfTestClient` – Yannick Motton Feb 03 '11 at 21:05

1 Answers1

14

Because of the comment about "DataContract programming model violation" left by alexdej I started looking a bit closer at what was in my properties. I had a Linq type in the property and though it was an IEnumerable it wasn't being enumerated for serialization. Added a .ToList() and all is well.

Community
  • 1
  • 1
ahsteele
  • 26,243
  • 28
  • 134
  • 248
  • 1
    I receive from my Service following error `Type 'System.Data.Entity.Infrastructure.DbQuery1[MYCLASS]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.`. Adding `.ToList()` before return statement sort out my problem. Thanks! – MaciejLisCK Nov 05 '13 at 15:18