使用soaphead方法可以在webservice的请求中增加头部信息,当有人调用我们的webservice时,可以通过查询这个请求的头部信息并验证来防止该软件以外的程序调用webservice
一、服务端部分
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
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;
}
}
}
|
二、客户端部分加上验证的请求
?
|
1
2
3
4
5
6
|
WebService webservice = new WebService();
AuthHeaderCS auth = new AuthHeaderCS();
auth.Username = "vip";
auth.Password = "vippw";
webservice.AuthHeaderCSValue = auth;
textBox1.Text = webservice.SecureMethod();
|
以上就是基于soaphead的webservice安全机制全部内容,希望能给大家一个参考,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 45
-
2025-05-29 70
-
2025-06-04 93
-
2025-05-25 39
-
2025-05-29 66
热门评论

