首页 > Web开发 > 详细

WebService它Soap头验证进入

时间:2015-06-20 19:34:51      阅读:311      评论:0      收藏:0      [点我收藏+]

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、完成

WebService它Soap头验证进入

原文:http://www.cnblogs.com/gcczhongduan/p/4590850.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!