Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > C#/.NET技巧

Asp.net页面中调用soapheader进行验证的操作步骤

来源:中文源码网    浏览:134 次    日期:2024-05-11 07:20:07
【下载文档:  Asp.net页面中调用soapheader进行验证的操作步骤.txt 】


Asp.net页面中调用soapheader进行验证的操作步骤
本文为大家分享了Asp.net页面中调用以SOAP头作验证的web services操作步骤,供大家参考,具体内容如下
第一步:用来作SOAP验证的类必须从SoapHeader类派生,类中Public的属性将出现在自动产生XML节点中,即:


string
string


public class UserSoapHeader : SoapHeader
{
private string _userName;
private string _pwd;
//public的属性将自动生成xml结点
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
public string Pwd
{
get { return _pwd; }
set { _pwd = value; }
}
}
第二步:
在WebServices服务类中添加一个public的属性(必须public),类型为从UserSoapHeader
///
/// WebService 的摘要说明
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
//此属性将作为验证属性
//方法的SoapHeaderAttribute中的名称与此变量一致
public UserSoapHeader userHeader;
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
[SoapHeader("userHeader")]//这里很重要,名称要和定义的验证属性名称一致!
public string HelloWorld()
{
//进入此方法后,userHeader将自动有值
if (userHeader != null)
{
return "this is retVal : " + userHeader.UserName;
}
return " check not successed ";
}
}
第三步:在客户端进行调用:
1. 添加WEB引用
2. 实例化服务类
3. 实例化SOAP头(在客户端将会自动生成作来作验证的属性;该属性类型为:UserSoapHeader;该属性的名称为:UserSoapHeaderValue) ;自动生成的属性生成规则为:验证类型名称+Value;
4. 调用服务提供的方法。
WebService s = new WebService();
UserSoapHeader a = new UserSoapHeader();
a.UserName = "admin";
a.Pwd = "zz";
s.UserSoapHeaderValue = a; //此属性是自动生成的
Response.Write( s.HelloWorld() ); // this is retVal : admin
很简单吧,希望大家都能够掌握asp.net中用soapheader作验证的步骤,谢谢大家的阅读。

相关内容