您现在的位置是:网站首页> 编程资料编程资料
ASP.NET中基于soaphead的webservice安全机制_实用技巧_
2023-05-24
443人已围观
简介 ASP.NET中基于soaphead的webservice安全机制_实用技巧_
使用soaphead方法可以在webservice的请求中增加头部信息,当有人调用我们的webservice时,可以通过查询这个请求的头部信息并验证来防止该软件以外的程序调用webservice
一、服务端部分
using System; using System.Web.Services; using System.Web.Services.Protocols; //请注意此命名空间必须有别于代理动态连接库上的命名空间。 //否则,将产生诸如多处定义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 = "此方法要求有调用方自定义设置的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 webservice = new WebService(); AuthHeaderCS auth = new AuthHeaderCS(); auth.Username = "vip"; auth.Password = "vippw"; webservice.AuthHeaderCSValue = auth; textBox1.Text = webservice.SecureMethod();
以上就是基于soaphead的webservice安全机制全部内容,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- ASP.NET中Webservice安全 实现访问权限控制_实用技巧_
- Microsoft .Net Remoting系列教程之三:Remoting事件处理全接触_自学过程_
- Microsoft .Net Remoting系列教程之二:Marshal、Disconnect与生命周期以及跟踪服务_自学过程_
- Microsoft .Net Remoting系列教程之一:.Net Remoting基础篇_自学过程_
- visual studio 2012安装配置方法图文教程 附opencv配置教程_实用技巧_
- ASP.NET配置KindEditor文本编辑器图文教程_实用技巧_
- 《解剖PetShop》之六:PetShop之表示层设计_自学过程_
- 《解剖PetShop》之五:PetShop之业务逻辑层设计_自学过程_
- 《解剖PetShop》之四:PetShop之ASP.NET缓存_自学过程_
- 《解剖PetShop》之三:PetShop数据访问层之消息处理_自学过程_
