Custom Collection null when passed through WCF Service

311 Views Asked by At

We have some custom collections such as this:

   [Serializable]
public class OccupationCollection : Collection<Occupation>
{
}

We use these in objects like the following:

private OccupationCollection _occupations;

  public OccupationCollection CurrentOccupations
    {
        get 
        {
            if (this._occupations == null)
                return new OccupationCollection();
            else
                return _occupations; 
        }
    }

Now we are making a call to a WCF service, passing objects that contain these type of lists. The lists always end up being null in the service.

I'm pretty sure this has somthing to do with serialization or something like that.

What would the simplest solution that would require minimal changes to the existing objects to get this to work?

1

There are 1 best solutions below

0
On

Have you hosted your service over HTTP? If yes, can you use fiddler to check the HTTP traffic and confirm whether serialized version of the parameter is being sent across the wire? If yes, there can be a parameter mismatch in contract between server and client. Also is the object holding OccupationCollection decorated with Serializable/DataContract attribute? If you have DataContract attribute, ensure that the properties that need to be serialized are marked with Datamember attribute.

More details out here.. http://blog.functionalfun.net/2009/09/if-your-wcf-service-is-unexpectedly.html