A recent Web service for a program that needs to validate an account to use the method provided by the Web service first thought of attaching the account information to the SOAP header, but found a lot of inconvenience when other colleagues in the company were using a non-. NET program call. Another Google a town, found a way to use the session, said or to find "Web service segment upload large attachment" When you see an example, no wonder that the previous search for Web service verification when the old find the results. The code is relatively simple, the main code is as follows:
<summary>///Authorization Verification, call this method when calling the Web service, after the call is completed, like a normal web site login, as long as the session does not timeout does not need to call this method again///</summary>/ <param name= "AppName" > Program name </param>///<param name= "Appauthorizecode" > Authorization Code </param>/// <returns></returns> [WebMethod (EnableSession = true, MessageName = "Authorized Authentication")] public bool Checkauthorize (stri Ng AppName, String Appauthorizecode {if (AppName = = "account name" && Appauthorizecode = = "123456") session["Login"]
= true;
else session["Login" = false;
return (BOOL) session["Login"]; ///<summary>///Add files, and then call///</summary>///<param name= "model" > Archive entity class </param>///<r eturns></returns> [WebMethod (enablesession=true,messagename= "Add File")] public string addarchive ( Model.archives model) {try {if (session["login"]!= null && session["Login". Equals (TRUE)//Here is the judgment session value, that is, there is no validation. Each method needs to be judged before {//The following code is sample code, you can place your own code as needed BLL. Archives BLL = new BLL. Archives (); File drillAn instantiated if (BLL) for the class.
Addarchive (model))//Add File Return "file add Success";
else return "file add failed";
else return "failed validation"; catch (Exception err) {return err.
message; }///<summary>///authorization Authentication, call this method first when calling the Web service, and after the call is complete like a regular web site login, you do not need to call this method again as long as the session does not timeout///</summary >///<param name= "AppName" > Program name </param>///<param name= "Appauthorizecode" > Authorization Code </param>/ <returns></returns> [WebMethod (EnableSession = true, MessageName = "Authorized Authentication")] public bool Checkauthorize ( String AppName, String Appauthorizecode {if (AppName = = "account name" && Appauthorizecode = = "123456") session["Login"]
= true;
else session["Login" = false;
return (BOOL) session["Login"]; ///<summary>///Add files, and then call///</summary>///<param name= "model" > Archive entity class </param>///<retur ns></returns> [WebMethod (enablesession=true,messagename= "Add File")] public string addarchive (model.archives Model) {try {if (session["Login"]!= null && session["Login"]. Equals (TRUE)//Here is the judgment session value, that is, there is no validation. Each method needs to be judged before {//The following code is sample code, you can place your own code as needed BLL. Archives BLL = new BLL. Archives (); Instantiation of the file Operation class if (BLL.
Addarchive (model))//Add File Return "file add Success";
else return "file add failed";
else return "failed validation"; catch (Exception err) {return err.
message; }
}
You can see how the session is used to verify that the main or the "EnableSession = True" attribute.