Examples of practical usage of JSON to and from an ASMX web service via jQuery

半腔热情 提交于 2020-01-25 09:05:13

问题


Can anyone recommend an article on sending and receiving JSON to an asp.net web service (any flavor) that uses more practical examples than "hello world".

Ideally, something that covers topics like:

Receive a single complex object from a web service (to display in a form)
Receive a collection of complex objects from a web service (to display in a table)
Send a single complex object to a web service (for updating the database)
Send a collection of complex objects to a web service (for updating the database)


回答1:


I have found this article to be useful in the past. It showcases much of what you are wanting to see. Hope this helps!

Edit: This question on SO has an excellent accepted answer showing the passing of complex data to a ASP.NET MVC controller method. Webservices work similarly in ASP.NET. They can accept an argument with a complex datatype populated with JSON from the client. You could replace the controller method with a similar WebMethod and return a class holding the desired return result:

[WebMethod]
public ReturnResult SaveWidget(Widget widget)
{
    // Save the Widget
    return new ReturnResult()
    { 
        Message = String.Format("Saved widget: '{0}' for ${1}", widget.Name, widget.Price) 
    };
}

With this class defined:

public class ReturnResult
{
    public string Message { get; set; }
}


来源:https://stackoverflow.com/questions/1301802/examples-of-practical-usage-of-json-to-and-from-an-asmx-web-service-via-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!