. NET WebService does not support overloading of Web methods, but you can achieve the purpose of overloading Web methods by setting the MessageName field of the WebMethod property.
By setting the enablesession=true of the WebMethod property, you can have webservice support the session.
By setting the Usehttpget=false of the Scriptmethod property, you can have the Web method accept only the POST request, or, if usehttpget=true, allow the Web method to accept the GET request.
You can format the Web method response by setting the Responseformat of the Scriptmethod property. such as: Responseformat = Responseformat.json.
On the code description:
WebService code for. NET:
[WebMethod (Description ="Verifying logon Actions", enablesession =true, MessageName ="Login")] [Scriptmethod (Usehttpget=false, Responseformat =Responseformat.json)] PublicResult Login (stringUserName,stringpwd) {Result RC=NULL; Try { if(UserName = ="1"&& pwd = ="1") {session["User"] =NewUserInfo {UserName = UserName, pwd =pwd}; RC= Result.toresult ("true","Login Successful"); } Elserc = Result.toresult ("false","Logon Failure"); } Catch(Exception ex) {//You can save the log hererc = Result.toresult ("false", ex. Message); } returnRC; } [WebMethod (Description="Verify Login", enablesession =true, MessageName ="IsLogin")] [Scriptmethod (Usehttpget=false, Responseformat =Responseformat.json)] Publicresult IsLogin () {result RC=NULL; Try{RC= session["User"] !=NULL? Result.toresult ("true","already logged in"): Result.toresult ("false","not logged in"); } Catch(Exception ex) {RC= Result.toresult ("false", ex. Message); } returnRC; } Public classResult { Public stringCode {Get;Set; } Public stringMessage {Get;Set; } Public StaticResult Toresult (stringCodestringmessage) { return NewResult {code = code, Message =message}; } }
HTML code under the same site:
<! DOCTYPE Html>"Content-type"Content="text/html; Charset=utf-8"/> <title></title> <meta charset="Utf-8"/> <script src="Http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script>function Login () {varURL ="Http://localhost/wst/Service.asmx/Login"; $.ajax ({url:url, type:'POST', Data:'{"UserName": "1", "pwd": "1"}',//corresponds to parameter one by one of the WebService Web methodDataType:'JSON', Cache:false, ContentType:'Application/json',// error:function () {}, Success:function (data) {if(DATA.D! =NULL) {alert (Data.d.code+" "+data.d.message); } ElseAlert"request failed! "); } }); } </script>"Button"Value="Login"onclick="Login ()"/></body>Use jquery ajax to access the homologous webserver method.
An analysis of the overloads of the. Net WebService method, support sessions, support request requests, and response formats