zoukankan      html  css  js  c++  java
  • Ajax在调用含有SoapHeader的webservice方法

    ·         [WebService(Namespace = "http://tempuri.org/")]
    ·             [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    ·             public class WebService4JQuery : System.Web.Services.WebService
    ·             {
    ·                 
    ·                 public TestHeader THeader;
    ·          
    ·                 [WebMethod]
    ·                 [SoapHeader("THeader")]
    ·                 public string TestSoapHeader()
    ·                 {
    ·          
    ·                     return "THeader Value: " + THeader.HeaderData;
    ·                 }
    ·             }
    ·          
    ·             public class TestHeader : SoapHeader
    ·             {
    ·                 public string HeaderData { get; set; }
    ·             }


    #JQuery code in the webform page

    <script type="text/javascript">
     
            function CallWebMethodWithHeader() {
     
                var soapXML = 
                "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
                "  <soap:Header>" +
                    "<TestHeader xmlns='http://tempuri.org/'>" +
                        "<HeaderData>111111111111</HeaderData>" +
                    "</TestHeader>" +
                "</soap:Header>" +
                "<soap:Body>" +
                    "<TestSoapHeader xmlns='http://tempuri.org/' />" +
                "</soap:Body>" +
                "</soap:Envelope>";
            
                $.ajax({
                    url: "WebService4JQuery.asmx?op=TestSoapHeader",
                    type: "POST",
                    dataType: "xml",
                    contentType:"text/xml; charset=utf-8",
                    data: soapXML,
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader('SOAPAction', 'http://tempuri.org/TestSoapHeader');
     
                    },
     
                    success: function (data) {
                        alert("webmethod call success");
                    },
                    error: function (err) {
                        alert("webmethod call failed");
                    }
     
                });
     
            }
        </script>
  • 相关阅读:
    【CF1009F】Dominant Indices(长链剖分优化DP)
    长链剖分学习笔记
    【洛谷5294】[HNOI2019] 序列(主席树维护单调栈+二分)
    【洛谷5286】[HNOI2019] 鱼(计算几何)
    【洛谷5292】[HNOI2019] 校园旅行(思维DP)
    【UVA1309】Sudoku(DLX)
    初学DLX
    【LOJ2461】「2018 集训队互测 Day 1」完美的队列(分块+双指针)
    【LOJ6062】「2017 山东一轮集训 Day2」Pair(线段树套路题)
    【LOJ6060】「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set(线性基)
  • 原文地址:https://www.cnblogs.com/stonespawn/p/3522978.html
Copyright © 2011-2022 走看看