Hello all,
I keep getting this error message (Invalid JSON primitive) when I try
to call an Ajax.Request with the 'applicatio/json' content type. I've
tried formatting the parameters in a variety of ways, but no luck.
Can anyone help?
Here's what I have:
CLIENT:
new Ajax.Request("/myService.asmx/GetComplexData",{
onSuccess: onSuccess,
onFailure: onFailure,
method:"post",
contentType:"application/json; charset=utf-8",
parameters: {s: 'bob'}
});
SERVER:
[WebMethod]
public string GetComplexData(string s)
{
return s;
}
Note that other calls are working. If I remove the content type, this
woks ok, but it just populates the string parameter with the value of
"s" from the client. Additionally, I tried this on the server, but to
no avail:
[WebMethod]
public string GetComplexData(object s)
{
return "ok";
}
It seems like there's some way I'm supposed to format the parameters
to make
MS.NET happy, but I can't figure out how it is. The server
can obviously handle it, because if I use their big fat client library
it sends json objects over and puts them into a dictionary object
without a hitch.
If anyone can offer some suggestions of even point in the right
direction, I would be most appreciative.
Thanks,
-M
Full Error Message:
-----------------------------
{"Message":"Invalid JSON primitive: s.","StackTrace":" at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
\r\n at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32
depth)\r\n at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String
input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer
serializer, String input, Type type, Int32 depthLimit)\r\n at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T]
(String input)\r\n at
System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext
context, JavaScriptSerializer serializer)\r\n at
System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData
methodData, HttpContext context)\r\n at
System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext
context, WebServiceMethodData
methodData)","ExceptionType":"System.ArgumentException"}