Web Service 中的身份验证策略
来源:互联网 发布:勇士队格林t袖淘宝 编辑:程序博客网 时间:2024/05/21 17:36
自定义SOAP标题可以限制调用服务的用户范围
1using System; 2using System.Web; 3using System.Web.Services; 4using System.Web.Services.Protocols; 5 6[WebService(Namespace = "http://livebaby.cn")] 7[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 8public class Service : System.Web.Services.WebService 9{ 10 public SecurityHeader currentUser; 11 public Service() 12 { 13 14 //如果使用设计的组件,请取消注释以下行 15 //InitializeComponent(); 16 } 17 [WebMethod, SoapHeader("currentUser")] 18 public string GetResult(string queryString) 19 { 20 if(ValidateUser(currentUser.UserName,currentUser.UserPass)) 21 { 22 return "你发送的字符串是:"+queryString; 23 } 24 else 25 return "对不起:" + currentUser.UserName+",您不是合法的用户!"; 26 } 27 //检验SOAP HEADER 28 private bool ValidateUser(string user, string pass) 29 { 30 if (user.Equals("user") && pass.Equals("user")) 31 return true; 32 else 33 return false; 34 } 35} 36//自定义Soap Header Class 37public class SecurityHeader : System.Web.Services.Protocols.SoapHeader 38{ 39 public string UserName; 40 public string UserPass; 41} |
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Text; 7using System.Windows.Forms; 8 9namespace SoapHeader 10{ 11 public partial class Form1 : Form 12 { 13 public Form1() 14 { 15 InitializeComponent(); 16 } 17 18 private void button_Invoke_Click(object sender, EventArgs e) 19 { 20 SoapHeader.localhost.SecurityHeader header = new SoapHeader.localhost.SecurityHeader(); 21 header.UserName = textBox_User.Text; 22 header.UserPass = textBox_Pass.Text; 23 SoapHeader.localhost.Service service = new SoapHeader.localhost.Service(); 24 service.SecurityHeaderValue = header; 25 this.textBox_Output.Text+=service.GetResult(this.textBox_Input.Text)+Environment.NewLine; 26 } 27 } 28} 29 |
- Web Service 中的身份验证策略
- Web Service 中的身份验证策略
- Web Service 中的身份验证策略
- Web Service 中的身份验证策略--使用自定义SOAP 标题
- Web Service 中的身份验证策略--使用自定义SOAP 标题
- Web Service 中的身份验证策略--使用自定义SOAP 标题
- web service身份验证
- Web Service 身份验证
- Web Service身份验证
- 简单Web service 身份验证解决方案
- 简单Web service 身份验证解决方案
- 简单Web service 身份验证解决方案
- 简单Web service 身份验证解决方案
- 简单Web service 身份验证解决方案
- SharePoint Web Service的身份验证
- 简单Web service 身份验证解决方案
- Web Service通过SoapHeader身份验证
- SharePoint Web Service的身份验证
- Windows下读取Linux分区的免费工具——WinAllFS http://www.lirui.name/post/63.html
- 硬盘结构简介http://www.x86asm.com/Print.asp?BoardID=7&ArticleID=66
- 支持FAT32和NTFS的引导扇区源码http://www.x86asm.com/DisplayArticle.asp?BoardID=4&ArticleID=148
- 再随笔
- 使用const 提高函数的健壮性
- Web Service 中的身份验证策略
- 两人世界与三架马车
- Validator框架中的ValidatorForm和DynaValidatorForm使用区别
- 【翻译】被占用文件操作三法
- 有一种记忆叫光荣——感人的老兵退伍留言集
- ORACLE 9I安装参考
- 卸载破解安装vs2005
- 安装Oracle注意事项和重装步骤
- 专家看台:程序员太幸福了,想做管理很危险