[DataContract]
public class AssetData
{
[DataMember]
public string Name { get; set; }
[DataMember]
public List<AssetData> ChildAssets { get; set; }
[DataMember]
public int Priority { get; set; }
[DataMember]
public AssetData ParentNode { get; set; }
}
[ServiceKnownType(typeof(Dictionary<string, AssetData>))]
public interface IRtxEquipmentConfiguration
{
[OperationContract]
object GetData(string sKey, string sRequest);
}
For the above OperationContract "GetData" the server is returning a Dictionary of AssetData.
I have marked AssetData as a DataContract and all its fields as DataMembers.
At the client side, I was getting wcf error “The socket connection has been disposed.\r\nObject name: ‘System.ServiceModel.Channels.SocketConnection’.”. I suspected this error is because of the field ChildAssets.
When I disable this field alone (By removing DataMember tag), then at the client side, I was able to get all the Dictionary elements and with in each element all the fields except ChildAssets.
I am able to see remaining fields Name, ParentNode and Priority.
Any clue why WCF fails to serialize a List with in a Dictionary element?
I have fixed the issue by adding
IsReference = trueto my DataContract class AssetData. The object graph has references to other instances of AssetData class. ChildAssets members are just references to other instances of AssetData.