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>
  • 相关阅读:
    PHP 批量生成静态文件目录代码
    PHP 导出Excel 文档
    Samba Server 配置
    PHP curl超时问题
    php ci 2.0框架 ORM
    YII 的基本CURL操作
    PHP 操作socket 实现简易聊天室
    PHP simplexml_load_string 过滤<![CDATA[XXXX]]>
    PHP 获取当天 凌晨 时间戳常用代码
    2019年值得你使用的20大开发工具
  • 原文地址:https://www.cnblogs.com/stonespawn/p/3522978.html
Copyright © 2011-2022 走看看