新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
webservice安全機制如何在ASP.NET中實現(xiàn)-創(chuàng)新互聯(lián)
這篇文章將為大家詳細講解有關(guān)webservice安全機制如何在ASP.NET中實現(xiàn),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
使用soaphead方法可以在webservice的請求中增加頭部信息,當有人調(diào)用我們的webservice時,可以通過查詢這個請求的頭部信息并驗證來防止該軟件以外的程序調(diào)用webservice
一、服務(wù)端部分
using System; using System.Web.Services; using System.Web.Services.Protocols; //請注意此命名空間必須有別于代理動態(tài)連接庫上的命名空間。 //否則,將產(chǎn)生諸如多處定義AuthHeader這樣的錯誤。 namespace SoapHeadersCS { //由SoapHeader擴展而來的AuthHeader類 public class AuthHeaderCS : SoapHeader { public string Username; public string Password; } //[WebService(Description="用于演示SOAP頭文件用法的簡單示例")] public class HeaderService { public AuthHeaderCS sHeader; [WebMethod(Description = "此方法要求有調(diào)用方自定義設(shè)置的soap頭文件")] [SoapHeader("sHeader")] public string SecureMethod() { if (sHeader == null) return "ERROR:你不是VIP用戶!"; string usr = sHeader.Username; string pwd = sHeader.Password; if (AuthenticateUser(usr, pwd)) { return "成功:" + usr + "," + pwd; } else { return "錯誤:未能通過身份驗證"; } } private bool AuthenticateUser(string usr, string pwd) { if ((usr != null) && (pwd != null)) { return true; } return false; } } }
文章題目:webservice安全機制如何在ASP.NET中實現(xiàn)-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://www.dlmjj.cn/article/hsesc.html