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