Hi , i am creating a WCF Restful service in which i want save the json object coming from the javascript as querystring by POST operation..I am getting the json object as querystring but can't access it in wcf restful, please help..........
My javascript code
var myRequest = new XMLHttpRequest();
myRequest.onreadystatechange=function(dataString) {
if (myRequest.readyState == 4 && myRequest.status == 200) {
console.log('Sent to server: ' + dataString + '');
window.localStorage.removeItem(dataString);
}
else if (myRequest.readyState == 4 && myRequest.status != 200) {
console.log('Server request could not be completed');
saveDataLocally(dataString);
}
}
var url="http://localhost:58168/RestServiceImpl.svc/json";
myRequest.open("POST",url+"?"+dataString,true);
myRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
myRequest.send(dataString);
alert('Saved to server: ' + dataString + '');
My Request in javascript
![while sending the json object as querystring to wcf restful server]
RequestURL:http://localhost:58168RestServiceImpl.svcjson?"firstName":"shuresh","lastName":"kumar"}
Request Header: Content-Type:application/x-www-form-urlencoded Origin:chrome-extension://ddijiilbgbjgciahjmonfahapadmkcfp User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/27.0.1453.116 Safari/537.36
Query String Parameters {"firstName":"shuresh","lastName":"kumar"}
Form Data {"firstName":"shuresh","lastName":"kumar"}:
WCF Restful service contract
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json?dataString={dataString}")]
string JSONData(string dataString);
RestServiceImpl.svc.cs
public string JSONData(string dataString)
{
return "You requested product " + dataString;
}
I can't access the json object(dataString) in the service contract.please help me how to access the json object that is append in the querystring in the wcf restful above code.
http://localhost:58168/RestServiceImpl.svc/json?"firstName":"shuresh","lastName":"kumar"}