I'm trying to make a web service with both a soap and a rest endpoint. But my object has an object property whose type I do not know at compile time. I have created a custom behavior for my rest endpoint that uses Json.NET for serialization because the default DataContractSerializer
cannot serialize my dynamic object. This is all working fine.
[DataContract, JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class TestClass1
{
[DataMember, JsonProperty]
public string p1 { get; set; }
[DataMember, JsonProperty]
public int p2 { get; set; }
}
[DataContract, JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class TestClass2
{
[DataMember, JsonProperty]
public DateTime t1 { get; set; }
[DataMember, JsonProperty]
public int t2 { get; set; }
}
[DataContract]
public class TestObject : SerializableDynamicObject
{
[DataMember, JsonProperty]
public int Id { get; set; }
[DataMember, JsonProperty]
public string Name { get; set; }
[DataMember, JsonProperty]
public object Obj { get; set; } //DataContractSerializer can't serialize this
}
The problem is on my Soap endpoint that still uses DataContractSerializer
. I'm getting an error when I try to run it, because it can't serialize a dynamic object (I assume).
The error I'm getting is this:
An error occurred while receiving the HTTP response to http://localhost:63222/Service1.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
I tried using this method, but to no avail. It still can't serialize my object.
If I remove the object from my TestObject class everything is fine.