I have created WCF RESTful service as below:
[OperationContract]
[WebInvoke(Method = "PUT",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/Customer/{customerID}/profile")]
string PutCustomerProfileData(string customerID);
I'm debugging this using Postman and passing JSON data in BODY as below:
{ "customerID":"RC0064211", "TermsAgreed":"true" }
public string PutCustomerProfileData(string customerID)
{
Message requestMessage = OperationContext.Current.RequestContext.RequestMessage;
}
What it returns in RequestMessage is as below:
{<root type="object">
<customerID type="string">RC0064211</customerID>
<TermsAgreed type="string">true</TermsAgreed>
</root>}
I want this request body in JSON form. Can I have it? If not what is the other way that I can create JSON string for mentioned RequestMessage
?
I tried with the
DataContract
andDataMember
and it worked for me.Below is the sample code:
Then I have converted that DataContract to the JSON string and used it further as below: