in the project I'm working on, we have a requirement to have a DataContract, which may contain some undefined JSON.
DataMember is some JSON that only makes sense to the client. We want to allow the client to send us json, which we do not know about.
Example:
public class Contract { [DataMember] public int clientId; [DataMember] public string json; }
Obviously, having a contract defined this way will require the client to exit json as follows:
{ "clientId":1, "json": "{\"test\":\"json\"}" }
Obviously, this is not what we need. The json user that the client should send us should look like this:
{ "clientId":1, "json": {"test":"json"} }
Possible solutions that we investigated:
- use Stream as the contract parameters for the request body. It works, but puts the work on our side, and does not use the framework.
- Defining "json" as a dynamic object. Does not work. Failed to get property written correctly.
- Using the Newtonsoft library, modify the standard contract serializer at the WCF endpoint to serialize all inputs to JObject. We also handle serialization on demand, and this causes problems in our application. We would rather avoid this.
Does anyone have a possible solution to this problem?
EDIT
The service offers json leisure resources. It defines a single endpoint with webHttpBinding. The operation is defined as follows (simplified to simplify):
[WebInvoke(Method = "POST", UriTemplate = "...", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] [OperationContract] Stream Create(Contract c);
In addition, the service is decorated with the following attribute:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
Thanks. Jf