Web Service的安全访问【SoapHeader身份认证】

web service安全访问方式可以以下安全措施:

(1)是谁调用?—–soapheader身份认证

(2)来自哪里?—–访问IP认证

(3)加密传输?—–SSL安全访问

本文主要讲解通过SoapHeader来增强Web Service的安全性

(1)自定义soapheader派生类

(2)添加基于SoapHeader验证的web service接口方法:

CredentialSoapHeader soap = new CredentialSoapHeader(); string msg = string.Empty; #region 退款 /// <summary> /// 统计退款个数 /// </summary> /// <param name="itemid">项目ID</param> /// <param name="productid">产品ID</param> /// <param name="state">退款状态:待处理,处理中,已退款</param> /// <returns></returns>  [WebMethod] [SoapHeader("soap")] public int RefundCount(int itemid, int productid, int state) { if (soap.VerifyCredentials(soap.Username, soap.Password, out msg)) { int count = 0; return count; } else { return 0; } }

(3)客户端调用

/// <summary> /// 获取安全凭证 /// </summary> /// <returns></returns> private static CTOCInterface.CredentialSoapHeader GetInterfaceSoapHeader() { CTOCInterface.CredentialSoapHeader header = new CTOCInterface.CredentialSoapHeader(); header.Username = MODEL.SystemConfigInfo.KEY_WTCTOCServiceUsername; header.Password = MODEL.SystemConfigInfo.KEY_WTCTOCServicePassword; return header; } /// <summary> /// 统计退款个数 /// </summary> /// <param name="userlogin"></param> /// <returns></returns> protected static int RefundCount(int itemid, int productid, int state) { using (CTOCInterface.CTOCGroupPurchaseSoapClient client = new CTOCInterface.CTOCGroupPurchaseSoapClient()) { try { return client.RefundCount(GetInterfaceSoapHeader(), itemid,productid,state); } catch { return null; } } }

原文链接:https://www.cnblogs.com/Loyalty/archive/2012/06/04/2535044.html

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/18076

(0)
上一篇 2023年6月1日 16:05
下一篇 2023年6月2日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml