zoukankan      html  css  js  c++  java
  • WebService之Soap头验证入门

    1、新建一个类,如"AuthHeaderUser",继承于"System.Web.Services.Protocols.SoapHeader"类

    2、新建WebService,有一个AuthHeaderUser类型的属性

    3、新建WebService的一个Web方法,指定Soap头信息,如:
    [SoapHeader("AuthenticationUser")]
    [WebMethod(Description="返回股票行情信息")]
    public DataSet GetQuotedPrice()
    {
    if (AuthenticationUser != null) //step4,验证Soap头是否为空
    {
    //验证
    WebServiceSoapHeaderAuthentication.DAL.LoginResult lr =
    new WebServiceSoapHeaderAuthentication.DAL.UserDAL().Login(AuthenticationUser.UserId, AuthenticationUser.Password);
    if (lr == LoginResult.Succeed)//登录成功
    return new WebServiceSoapHeaderAuthentication.DAL.QuotedPriceDAL().GetQuotedPriceDataset();
    else
    throw new ApplicationException("Log in failed : " + lr.ToString());
    }
    else
    throw new SoapHeaderException("......", SoapException.ClientFaultCode);
    }

    4、client引用:
    //Web服务
    localhost1583QuotedPriceService.QuotedPriceService service =
    new WebServiceSoapHeaderAuthentication.QuotedPriceViewForm.localhost1583QuotedPriceService.QuotedPriceService();

    //准备Soap头
    WebServiceSoapHeaderAuthentication.BOL.User u = CurrentUser.getInstance();
    localhost1583QuotedPriceService.AuthHeaderUser login_user =
    new WebServiceSoapHeaderAuthentication.QuotedPriceViewForm.localhost1583QuotedPriceService.AuthHeaderUser();
    login_user.UserId = u.UserId;
    login_user.Password = u.UserPassword;

    //Soap头赋值
    service.AuthHeaderUserValue = login_user;

    DataSet ds = service.GetQuotedPrice();
    //todo:......

    5、完毕

  • 相关阅读:
    MaxScript 计算执行时间差
    MaxScript 几种类GUID的生成方法
    MaxScript 防坑规范指南
    样式测试
    设置.MAX文件程序关联
    Python相关网站(持续更新)
    Python程序使用cx_freeze打包(报错)
    Python对Excel的操作(模块win32com)
    Python对Excel的操作(模块xlrd)
    python模块安装
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4263164.html
Copyright © 2011-2022 走看看