wcf object serialization without datacontract/datamemember attributes strange behavior
-
I am using .net framework wcf client and server . The signature of the WCF service interface is simple:
ResponseMessage SendMessage(RequestMessage message)
I create a new type that inherits from "ResponseMessage". This type holds 1 property:
public class TestResponseMessage : ResponseMessage
{
public List<ISomeInterface> Members { get; set; }
}http://stackoverflow.com/questions/17616271/wcf-contracts-without-the-annotations
It is said that "Members" property should be able to serialize without the need of the [DataContract] on the class and [DataMember] on the property, but it doesn't work - if I don't use it, I get null in the TestResponse.
The reason for asking this is that we've encountered a very strange behavior in our product - sometimes this serialization works and sometimes it doesn't, and it seems to behave differently with same client/server versions on different machines.
Any insights about this will be very welcome.
-
I am using .net framework wcf client and server . The signature of the WCF service interface is simple:
ResponseMessage SendMessage(RequestMessage message)
I create a new type that inherits from "ResponseMessage". This type holds 1 property:
public class TestResponseMessage : ResponseMessage
{
public List<ISomeInterface> Members { get; set; }
}http://stackoverflow.com/questions/17616271/wcf-contracts-without-the-annotations
It is said that "Members" property should be able to serialize without the need of the [DataContract] on the class and [DataMember] on the property, but it doesn't work - if I don't use it, I get null in the TestResponse.
The reason for asking this is that we've encountered a very strange behavior in our product - sometimes this serialization works and sometimes it doesn't, and it seems to behave differently with same client/server versions on different machines.
Any insights about this will be very welcome.
I think certain kinds of "advice" without reference to the actual documentation is worthless (as in this case). If one consults the actual documentation (help) re: "Data Contracts" it notes that: "All .NET Framework primitive types, such as integers and strings, as well as certain types treated as primitives, such as DateTime and XmlElement, can be serialized with no other preparation and are considered as having default data contracts." and "New complex types that you create must have a data contract defined for them to be serializable." I would say that your "Members" property is NOT a "primitive" type and therefore must have a "data contract". (The SO example conveniently only shows primitive types).