在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在websevrice 中,soap header是十分重要的哦,主要是安全性的考虑,在asp.net 2.0中,可以简单地应用soap header来 using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public ValidationSoapHeader Authentication; private const string DEV_TOKEN = "12345"; public Service() { //Uncomment the following line if using designed components //InitializeComponent(); } [SoapHeader("Authentication")] [WebMethod] public string HelloWorld() { if (Authentication != null && Authentication.DevToken == DEV_TOKEN) { return "Hello World"; } else { throw new Exception("Authentication Failed"); } } } using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Services.Protocols; /// <summary> /// Summary description for ePhoneCredentials /// </summary> public class ValidationSoapHeader : SoapHeader { private string _devToken; public ValidationSoapHeader() { public ValidationSoapHeader(string devToken) { this._devToken = devToken; } public string DevToken { get { return this._devToken; } set { this._devToken = value; } } } header.DevToken = "12345"; localhost.Service ws = new ConsoleMyCsharpClient.localhost.Service(); ws.ValidationSoapHeaderValue = header; Console.WriteLine(ws.HelloWorld());
TrackBack:http://www.cnblogs.com/jackyrong/archive/2007/05/23/757708.html |
请发表评论