c# WebService添加SoapHeader认证

 2023-09-13 阅读 18 评论 0

摘要:1.添加一个cretificate类继承自SoapHeader public class CertificateSoapHeader:SoapHeader { private string username; private string password; public string UserName { get { return username; } set { username = value; } } public string Passw

1.添加一个cretificate类继承自SoapHeader
     public class CertificateSoapHeader:SoapHeader
        {
            private string username;
            private string password;
            public string UserName
            {
                get
                {
                    return username;
                }
                set
                {
                    username = value;
                }
            }
            public string Password
            {
                get
                {
                    return password;
                }
                set
                {
                    password = value;
                }
            }
            public bool ValideUser(string in_UserName, string in_PassWord)
            {
                string cofig_user = ConfigHelper.GetAppSettings("soapUser");
                string config_pwd = ConfigHelper.GetAppSettings("soapPwd");
                if ((in_UserName == cofig_user) && (in_PassWord == config_pwd))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
2.自写的WebService方法中添加[SoapHeader("soapHeader")]
 public class Settle_Pay : System.Web.Services.WebService
    {
        public CertificateSoapHeader soapHeader = new CertificateSoapHeader();
        [WebMethod(EnableSession = true, Description = "更新审批状态")]
        [SoapHeader("soapHeader")]//添加认证标头
        public Settle_PayReturnEntity UpdateSettlePayApproval(string OA_Id, string status)
        {
            Settle_PayReturnEntity returnEntity = new Settle_PayReturnEntity();
         //校验用户名密码
            if (!soapHeader.ValideUser(soapHeader.UserName, soapHeader.Password))
            {
                returnEntity.Type = "E";
                returnEntity.Message = "用户名密码错误";
                return returnEntity;
            }
            List<StringBuilder> sqls = new List<StringBuilder>();
            List<object> objs = new List<object>();
            sqls.Add(new StringBuilder(@" update Settle_Pay set applyStatus='" + status + "' where OA_Id='" + OA_Id + "'"));
            objs.Add(null);

            string err = string.Empty;
            int r = DataFactory.SqlDataBase().BatchExecuteByListSql(sqls, objs, ref err);
            if (r > 0)
            {
                returnEntity.Type = "S";
                returnEntity.Message = "审核通过!";
            }
            else
            {
                returnEntity.Type = "E";
                returnEntity.Message = err;
            }
            return returnEntity;
        }

    }
3.通过SoapUI验证

 



webservice调用方法, 

转载于:https://www.cnblogs.com/lbja2/p/9647183.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/50423.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息