views:

3969

answers:

2

I'm using jquery to call a webservice which returns a dataset with a couple of tables in it.

This was working ok until i needed to set up my webmethod to accept a parameter. I reflected this on the client side with

data: "{paramname:'" + paramval+ "'}",

I now get the following error when the webmethod returns. This happens regardless of whats being returned in the dataset

Error:{"Message":"A circular reference was detected while serializing an object of type \u0027System.Globalization.CultureInfo\u0027.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at ...etc

When the webmethod has no parameters the client side js looks the same as below except the data: line is removed.

function ClientWebService(paramval){
$.ajax({
 type: "POST",
 url: "WebService1.asmx/webmethodName", 
 data: "{paramname:'" + paramval+ "'}",
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: function(msg) {
  ParseResult(msg.d);
 },
 error: function(err) {
  if (err.status == 200) {
        ParseResult(err);
  }
  else { alert('Error:' + err.responseText + '  Status: ' + err.status); }
 }
});

}

Edit: As per suggestion to change the request to

data: {paramname: paramval},

yields the following error.

Error:{"Message":"Invalid JSON primitive: paramval.","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.DeserializeT\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"} Status: 500

A: 

What is listoftextboxes, string array? Not sure what your parameter type is on the web method but they should match up.

chief7
My webmethod is set up to accept a string. Heres the method signature. [WebMethod(EnableSession = true)] public DataSet CustomerAddressValues(string listOfCustomerTextboxes)
Ah, the problem is most likely the returning DataSet, serialzing it to json is causing problems. Really you need to convert the DataSet to something more simple that can be easily serialized.
meandmycode
If that were the case then the parameterless function would not work either. Its only with the introduction of a parameter in my webmethod the error occurs. also i've setup up both webmethods to return the exact same data for testing purposes so its not specific to whats inside the dataset either
Can you give us a sample of the serialized json from your client?
chief7
+1  A: 

I changed my webmethod to return

ds.GetXml();

and this worked. Considering datasets are serializeable I'm not sure why I have to do this, but it gets me over this hurdle.