JQuery and WCF - GET Method passes null
Posted
by user70192
on Stack Overflow
See other posts from Stack Overflow
or by user70192
Published on 2010-04-25T15:47:22Z
Indexed on
2010/04/25
15:53 UTC
Read the original article
Hit count: 313
Hello,
I have a WCF service that accepts requests from JQuery. Currently, I can access this service. However, the parameter value is always null. Here is my WCF Service definition:
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string ExecuteQuery(string query)
{
// NOTE: I get here, but the query parameter is always null
string results = Engine.ExecuteQuery(query);
return results;
}
Here is my JQuery call:
var searchUrl = "/services/myService.svc/ExecuteQuery";
var json = { "query": eval("\"test query\"") };
alert(json2string(json)); // Everything is correct here
if (json != null) {
$.ajax({
type: "GET",
url: searchUrl,
contentType: "application/json; charset=utf-8",
data: json2string(json),
dataType: "json"
});
}
What am I doing wrong? It seems odd that I can call the service but the parameter is always null. Thank you
© Stack Overflow or respective owner