I paste C # 's code:
Copy Code code as follows:
Namespace iwebs.webs{
Using System;
Using System.Web.Services;
Using System.Web.Services.Protocols;
Using System.Xml;
Using System.Xml.XPath;
Using System.Web.Script.Services;
Using Iwebs;
[WebService (Name= "Cjjer", description= "a return user information, order information WebService, the requested cell phone number maximum 12", namespace= "http://www.cjjer.com/webs/")]
[System.Web.Script.Services.ScriptService]
public class cjjer:webservice{
public class reqheader:soapheader{
public string UserName;
public string Password;
}
public Reqheader header;
[WebMethod (Description = "Enter the int value ID of a single user, return the user class", messagename= "GetUser", EnableSession = False)]
[Scriptmethod (Responseformat = Responseformat.json)]
[SoapHeader ("header", Direction = soapheaderdirection.in)]
Public model.member getuser (int uid) {
This. Chechheader (header);
Return (new DAL. Members ()). GetByID (UID);
}
[WebMethod (Description = "Enter a user's mobile number, return the user class", messagename= "Getuserbymobile", EnableSession = False)]
[Scriptmethod (Responseformat=responseformat.json)]
[SoapHeader ("header", Direction = soapheaderdirection.in)]
Public Model.member Getuserbymobile (string umobile) {
This. Chechheader (header);
Return (new DAL. Members ()). Getbymobile (Umobile);
}
[WebMethod (Description = "Enter a user's mobile number, return order array", messagename= "Getordersbymobile", EnableSession = False)]
[Scriptmethod (Responseformat=responseformat.json)]
[SoapHeader ("header", Direction = soapheaderdirection.in)]
Public iwebs.model.order[] Getordersbymobile (string umobile) {
This. Chechheader (header);
Return (new DAL. Orders ()). Getbymobile (umobile,-365);
}
[WebMethod (Description = "Enter a user's ID, return order array", messagename= "Getordersbyuserid", EnableSession = False)]
[Scriptmethod (Responseformat=responseformat.json)]
[SoapHeader ("header", Direction = soapheaderdirection.in)]
Public iwebs.model.order[] Getordersbyuserid (int uid) {
This. Chechheader (header);
Return (new DAL. Orders ()). Getordersbyuserid (uid,-365);
}
private void Chechheader (Reqheader header) {
if (header!= null) {
if (header. MustUnderstand)
{
string UserName = Header.username;
string PassWord = Header.password;
if (UserName = = "Cjjer" && PassWord = = "000000")
{
return;
}
Else
{
throw new ApplicationException (String.Format ("username [{0}] or password [{1}] error", Username,password));
}
}
Else
{
throw new ApplicationException ("The message header containing the username and password information is not in the correct format");
}
}
Else
{
throw new ApplicationException ("Please submit a message header containing the username and password information");
}
}
};
}
Note that this request must be submitted to the SoapHeader, where the [System.Web.Script.Services.ScriptService]
This is the use of ajax.net processing JSON request, if not need to be free, if necessary, download ajax.net, and then put System.web.extensions.design.dll,system.web.extensions.dll in the bin, according to AJ Ax. NET default Web.config modify your Web.config and view it in the browser *. asmx file, if you use the WSDL to see the XML WSDL, the first step is successful.
One of the notes is:
Web.config
It is important to have two nodes in the HttpHandler:
Copy Code code as follows:
<remove verb= "*" path= "*.asmx"/>
<add verb= "*" path= "*.asmx" validate= "false" Type= "System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35 "/>
These two statements let ScriptHandlerFactory handle the webservice request.
Use AJAX requests when Http_request.setrequestheader ("Content-type", "Application/json");
Plus, the default return is JSON.
Attach the web. Config and the associated DLL file:
C # JSON
It makes sense when C # code is created.