This is generally true in our applications, using jquery as the client framework, and AJAX requests often return HTML or JSON. The HTML is not discussed here. Returning JSON is typically a handler.ashx to handle requests, piecing together strings to return JSON. The WS is thus discarded because WS returns XML and is inconvenient to use.
So I think the perfect solution is to get WS to return JSON and not asp.net the AJAX client box is the ideal solution.
Why did WebService return to JSON when they found that the ASP.net AJAX client framework request WebService returns JSON? Capture analysis to the key in the request headers "Content-type:application/json;utf-8", so WebService use JSON serialization, should be " System.Web.Script.Serialization.JavaScriptSerializer "This class completes the work through the Web.config configuration, putting *. The ASMX was handed over to System.Web.Extensions.Dll. That is, here or using the ASP.net ajax, but the service side of the section, I am here directly with the ASP.net 3.5
The above is long-winded, the concrete method is very simple, see example
Ws1.asmx
Copy Code code as follows:
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Services;
Using System.Web.Services.Protocols;
Using System.Xml.Linq;
Namespace Test2
{
<summary>
Summary description for WS1
</summary>
[WebService (Namespace = "http://onewww.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[ToolboxItem (False)]
[System.Web.Script.Services.ScriptService]
public class WS1:System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld ()
{
Return to "Hello World";
}
[WebMethod]
Public TestUser CreateUser (String Name,int age)
{
return new TestUser {name = name, age = age};
}
}
public class TestUser
{
public string Name {get; set;}
public int Age {get; set;}
}
}
Current 1/3 page
123 Next read the full text