WCF rest service for Android and ISO call 5-------validation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.