webservice 报文头及返回xml

类

[Serializable]

    public class MySoapHeader : System.Web.Services.Protocols.SoapHeader

    {

        private string userName = string.Empty;

        private string passWord = string.Empty;



        /// <summary>

        /// 构造函数

        /// </summary>

        public MySoapHeader() { } /// <summary>

        /// 构造函数

        /// </summary>

        /// <param name="userName">用户名</param>

        /// <param name="passWord">密码</param>

        public MySoapHeader(string userName, string passWord)

        {

            this.userName = userName;

            this.passWord = passWord;

        }



        /// <summary>

        /// 获取或设置用户用户名

        /// </summary>

        public string clientKey

        {

            get { return userName; }

            set { userName = value; }



        }



        /// <summary>

        /// 获取或设置用户密码

        /// </summary>

        public string secrect

        {

            get { return passWord; }

            set { passWord = value; }

        }



    }

 

public class PublacXml

    {

        //传入xml字符 输入完整的string xml

        public string XmlRt(string R_Sxml)

        {

            StringBuilder XmlStr = new StringBuilder();

            XmlStr.Append("<?xml version=\"1.0\" encoding=\"gb2312\"?>");

            XmlStr.Append("<LOGINUSER>");

            XmlStr.AppendFormat("<LDAPID>{0}</LDAPID>", R_Sxml);

            XmlStr.Append("</LOGINUSER>");

            return XmlStr.ToString();

        }

    }
webservice调用

 [System.Web.Services.Protocols.SoapHeader("myHeader")]

        //查询理赔信息是否成功接口

        [WebMethod(Description = "<b><i>输入重传次数和唯一值 返回理赔 服务合同编号、错误信息、状态</i></b><br><font color='blue'>int</font> sno:重传次数</br><br><font color='blue'>string</font> guid:承保理赔撤销唯一值(2015-05-06)</br>")]

        public string lpstatus(int sno, string guid)

        {

            string sql = "select * from ss_lp a inner join ss_ba b on a.lpid=b.lpid where sno=" + sno + " and guid='" + guid + "'";

            DataTable dt = DBHelper.GetDataTable(sql);

            string d = string.Empty;

            d += "<ERROR>" + "<EX_name>" + dt.Rows[0]["PACK_CARD_CODE"].ToString() + "</EX_name>" + "<EX_mark>" + dt.Rows[0]["CW"].ToString() + "</EX_mark>" + "<EX_statu>" + dt.Rows[0]["shstatus"].ToString() + "</EX_statu>" + "</ERROR>";

            PublacXml xl = new PublacXml();

            string RT_xml = xl.XmlRt(d);

            return RT_xml;

        }
报文头

 public MySoapHeader myHeader = new MySoapHeader();

        //报文头

        private string yanz()

        {

            if (myHeader.clientKey.Equals("1") & myHeader.secrect.Equals("1"))

            {

                return "";

            }

            else

            {

                return "00";

            }

        }
报文头调用

  ServiceReference1.MySoapHeader my = new MySoapHeader();

            my.clientKey = "1";//用户名

            my.secrect = "1";//密码

 

你可能感兴趣的:(webservice)