Web Service Encryption Processing

Source: Internet
Author: User

Server-side Web service new KlmywgSoapHeader.cs

usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Runtime.InteropServices;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.HtmlControls;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.Services;usingSystem.Web.Services.Protocols;/// <summary>///Summary description of Klmywgsoapheader/// </summary> Public classklmywgsoapheader:soapheader{ Public stringUserName;  Public stringPassWord; Private stringM_username; Private stringM_password; [DllImport ("DataEncrypt.dll")]     Public Static extern stringDesencrypt (stringValue,stringKey); [DllImport ("DataEncrypt.dll")]     Public Static extern stringDesunencrypt (stringValue,stringKey); stringkey;  PublicKlmywgsoapheader () {Key= configurationmanager.appsettings["Key"].        ToString (); M_username= configurationmanager.appsettings["Webserviceusername"].        ToString (); M_password= configurationmanager.appsettings["Webservicepassword"].        ToString (); M_password=Desunencrypt (M_password, key); }     Public stringValidate () {PassWord=Desunencrypt (Password,key); if(M_username = = UserName && M_password = =PassWord) {            return "true"; }        Else        {            return "Do not have permission"; }    }}

WebService.cs

usingSystem;usingsystem.web;usingSystem.Web.Services;usingSystem.Web.Services.Protocols; [WebService (Namespace="http://tempuri.org/")][webservicebinding (ConformsTo=wsiprofiles.basicprofile1_1)]//to allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream. //[System.Web.Script.Services.ScriptService] Public classservice:system.web.services.webservice{ PublicKlmywgsoapheader Header =NewKlmywgsoapheader ();  PublicService () {//If you are using a design component, uncomment the following line//InitializeComponent ();} [WebMethod] [SoapHeader ("Header")]     Public stringHelloWorld () {stringresult=header.       Validate (); if(Result = ="true")       {           return "Hello World"; }       Else           returnresult; }    }

Web page invocation

usingSystem;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.HtmlControls;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Xml.Linq; Public Partial class_default:system.web.ui.page {Localhost.klmywgsoapheader header=NewLocalhost.klmywgsoapheader (); localhost. Service Service=Newlocalhost.        Service (); protected voidPage_Load (Objectsender, EventArgs e) {header. UserName= configurationsettings.appsettings["Webserviceusername"].        ToString (); Header. PassWord= configurationsettings.appsettings["Webservicepassword"].        ToString (); Service.klmywgsoapheadervalue=header; stringresult =service.        HelloWorld ();    Response.Write (Result); }}

Web Service Encryption Processing

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.