1

I have a CLR-class that I want to send via a WCF service (Net TCP Binding). Both the client and server use the same data classes and service interfaces. There are no stubs generated. Here are the basic parts of two classes:

[DataContract]
public class ContainerClass
{
    //some primitive data with [DataMember] ...

    [DataMember] /**/
    public virtual BindingList<ItemClass> Items{ get; private set; }
}

[DataContract]
public class ItemClass
{
    //some primitive data with [DataMember] ...

    public ContainerClass Parent { get; set; } // (no [DataMember])
}

The data is correctly transmitted, if I omitt the [DataMember] attribute of the BindingList (marked with /**/). Of course, whithout the items.

As soon as I add the [DataMember], a call to the service method, which returns an object of type ContainerClass fails with the following error message:

The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

A contract mismatch is impossible by design. There is probably an internal server error of which I am not notified.

How can I solve this problem and make the server send the items to the client?

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70

1 Answers1

1

Most likely BindingList<> fails to serialize. To get more detailed error you need to enable tracing. See this post on how to do it.

It's usually not good idea to use complex collection classes within your DTO. Consider arrays/lists instead, you can always reconstruct BindingList<> on client side.

Community
  • 1
  • 1
UserControl
  • 14,766
  • 20
  • 100
  • 187
  • It seems, you are right. Although I performed some positive tests with `BindingLists`. – Nico Schertler Oct 18 '12 at 21:06
  • I just found another reason. A base class, which I marked as `[Serializable]` implemented the `INotifyPropertyChanged` interface and the according event. Because it was no `[DataContract]`, the serializer tried to serialize all members including the event, which failed. I added the `[DataContract]` attribute and it worked. – Nico Schertler Oct 19 '12 at 15:55