发布于 2016-06-16 07:27:44 | 144 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


这篇文章主要介绍了Asp.net页面中调用soapheader进行验证的操作步骤,感兴趣的小伙伴们可以参考一下

本文为大家分享了Asp.net页面中调用以SOAP头作验证的web services操作步骤,供大家参考,具体内容如下

第一步:用来作SOAP验证的类必须从SoapHeader类派生,类中Public的属性将出现在自动产生XML节点中,即:


<soap:Header>
  <UserSoapHeader xmlns="http://tempuri.org/">
   <UserName>string</UserName>
   <Pwd>string</Pwd>
  </UserSoapHeader>
</soap:Header>

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


/// <summary>
/// WebService 的摘要说明
/// </summary>
[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作验证的步骤,谢谢大家的阅读。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务