Years have gone by ...
Online to see a verification method, here to record. Directly on the code
Write the server validation method first
/// <summary> ///Verify that you have permission to access/// </summary> /// <returns></returns> Private BOOLcheckischeckauthorization () {//gets the current web operation contextWeboperationcontext WOC =weboperationcontext.current; //get authorization in the current request header if(WOC = =NULL)return true; varAuth = WoC. incomingrequest.headers["Authentication"]; if(!string. IsNullOrEmpty (auth) && auth = ="Authentication")return true; WoC. Outgoingresponse.statuscode=System.Net.HttpStatusCode.MethodNotAllowed; return false; } PublicUsers Getuserbyid (stringID) {if(Checkischeckauthorization ()) {return_listcollection.firstordefault (v = v.id = =ID); } return NULL; }
The client then sets the value of authentication when calling the method. The code is as follows
private static async void Getuserbyid (string id) { Console.WriteLine ("-----------gets user----------by id"); HttpClient HttpClient = new HttpClient (); HTTPCLIENT.DEFAULTREQUESTHEADERS.ADD ("Authentication", "Authentication"); var result = await Httpclient.getasync ("HTTP://LOCALHOST:31572/SERVICE1.SVC/GETUSERBYID/1"); Result. Ensuresuccessstatuscode (); Console.WriteLine (Result. Content.readasstringasync (). Result); }
It's done.
WCF rest service for Android and ISO call 5-------validation