我创建了 WCF RESTful 服务,如下所示:
[OperationContract]
[WebInvoke(Method = "PUT",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/Customer/{customerID}/profile")]
string PutCustomerProfileData(string customerID);
我正在使用Postman调试它并在 BODY 中传递JSON数据,如下所示:
{ "customerID":"RC0064211", "TermsAgreed":"true" }
public string PutCustomerProfileData(string customerID)
{
Message requestMessage = OperationContext.Current.RequestContext.RequestMessage;
}
它在 RequestMessage 中返回的内容如下:
{<root type="object">
<customerID type="string">RC0064211</customerID>
<TermsAgreed type="string">true</TermsAgreed>
</root>}
我想要这个 JSON 格式的请求正文。我可以拥有吗?如果不是,我可以为提到的创建 JSON 字符串的另一种方法是什么RequestMessage
?