Supports calling WebService via HTTP request method, while supporting SoapHeader authentication.
usingGlobalegrow.common;usingGlobalegrow.model;usingsystem.web;usingSystem.Web.Services.Protocols;namespaceglobalegrow.service{/// <summary> ///custom SoapHeader class. /// </summary> Public classCertificate:soapheader {Private StaticServiceConfig M_serviceconfig; /// <summary> ///constructor Function/// </summary> PublicCertificate () {The//=> is used to handle the SoapHeader information required to validate the HTTP request to invoke the WebService service. This. UserName = httpcontext.current.request["UserName"]; This. PassWord = httpcontext.current.request["PassWord"]; } /// <summary> ///Static Constructors/// </summary> StaticCertificate () {//= = When you create an instance of the certificate class, assign a value to Appcontext.serviceconfigM_serviceconfig =serviceconfigutility.load (); Appcontext.serviceconfig=M_serviceconfig; } /// <summary> ///User name/// </summary> Public stringUserName {Get;Set; } /// <summary> ///Password/// </summary> Public stringPassWord {Get;Set; } /// <summary> ///user authentication/// </summary> Public BOOLIsvaild ( out stringmessage) { string_username =M_serviceconfig.webservicetokenaccount; string_password =M_serviceconfig.webservicetokenpassword; if( This. UserName = = _username && This. PassWord = =_password) {Message=""; return true; } Else{message="Sorry, you do not have permission to call this service! "; return false; } } }}
Call:
http://192.168.3.41:8888/permissionservice/permissionservice.asmx/getauthuserbyroleid? Username=admin&password=admin&roleid=11
WebService security authentication based on SoapHeader (II.)