I want to create a web method that accepts a List of custom objects (passed in via jQuery/JSON).
When I run the website locally everything seems to work. jQuery and ASP.NET and everyone is happy. But when I put it on one of our servers it blows up. jQuery gets a 500 error after the ajax request with the response being:
System.InvalidOperationException: EditCustomObjects Web Service method name is not valid.
Here’s the web service method:
[WebMethod]
public void EditCustomObjects(int ID, List<CustomObject> CustomObjectList)
{
// Code here
}
And my jQuery code (which I don’t think matters, since the error seems to be happening on the web service level):
var data = JSON.stringify({
ID: id,
CustomObjectList: customObjectList
});
$.ajax({
type: "POST",
url: "/manageobjects.asmx/EditCustomObjects",
data: data,
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function(xml, ajaxStatus) {
// stuff here
}
});
The customObjectList is initialized like so:
var customObjectList = [];
And I add items to it like so (via a loop):
var itemObject = {
ObjectTitle = objectTitle,
ObjectDescription = objectDescription,
ObjectValue = objectValue
}
customObjectList.push(itemObject);
So, am I doing anything wrong here? Is there a better way of passing an array of data from jQuery to an ASP.NET web service method? Is there a way to resolve the “Web Service method name is not valid.” error?
FYI, I am running .NET 2.0 on a Windows Server 2003 machine, and I got the code for the above from this site: http://elegantcode.com/2009/02/21/javascript-arrays-via-jquery-ajax-to-an-aspnet-webmethod/
EDIT: Someone requested some more info on the web service, I’d rather not provide the whole class but here is a bit more that may help:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ManageObjects : Custom.Web.UI.Services.Service
{
}
Bara
I make the assuption based on comments that you can directly go to the web service in the browser.
Just to isolate your custom object from configuration, you could put another service in place like:
Call that from a client side jQuery ajax call. If this works, then it is probably related to your object specifically and not configuration on the server side. Otherwise, keep looking on the server side config track.
EDIT: Some sample code:
And here is an example of where I post a complex data type JSON value
This actually includes two arrays of objects inside it… my NewProcedureData type is defined in a class which lays those out.
EDIT2:
Here is how I handle a complex object in one instance:
NOTE !IMPORTANT the procedureSaveData name must match exactly on the client and server side for this to work properly.
EDIT3: more code example:
Hope this helps.