zoukankan      html  css  js  c++  java
  • JS,Jquery 调用 C#WebService

    1,需要在服务下面把代码的注释去掉

      // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
      //[System.Web.Script.Services.ScriptService]

    2,JS 调用方法如下

    var request = '<?xml version="1.0" encoding="utf-8"?>';
                request += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'
                request += '<soap12:Body>'
                request += '<UpdateFacultativere xmlns="http://tempuri.org/">'
                request += '   <facNum>12313</facNum>'
                request += '  <facVerstion>2</facVerstion>'
                request += '   <date>string</date>'
                request += ' <description>string</description>'
                request += ' </UpdateFacultativere>'
                request += '</soap12:Body>'
                request += '</soap12:Envelope>'
    
                var req = new XMLHttpRequest();
                req.open("POST", 'http://localhost:34869/CRMService.asmx', true)
                // Responses will return XML. It isn't possible to return JSON.
                //req.setRequestHeader("Accept", "application/xml, text/xml, */*");
                req.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
                req.setRequestHeader("Content-Length:", request.length);
    
                req.setRequestHeader("SOAPAction", "http://tempuri.org/UpdateFacultativere");
                req.onreadystatechange = function () { DoR(req, successCallback, errorCallback); };
                req.send(request);
    

      

    3,Jquery调用方法如下

                $.ajax({
                    url: 'http://localhost:34869/CRMService.asmx/UpdateFacultativere',
                    data: {facNum :'02020',facVerstion:10, date:'10292', description:'2222'},
                    dataType: "xml",
                    type: "POST",
                    success: function (xml) {
                        debugger
                        alert(xml);
                    },
                    error: function (xml, status) { 
                        debugger
                    }
                }
                );
  • 相关阅读:
    无缘无故Spring MVC报错空指针异常
    无缘无故Spring MVC报错空指针异常
    无缘无故Spring MVC报错空指针异常
    SpringMVC整合Shiro
    SpringMVC整合Shiro
    SpringMVC整合Shiro
    (数据挖掘)大数据Flume+kafka+zookeeper+Strom/Spark/Fink......
    (数据分析)大数据Flume+kafka+zookeeper+Strom/Spark/Fink......
    java中的堆、栈和方法区
    mvn clean -U -e -B -X的作用+如何在eclipse中使用mvn clean -U -e -B -X?
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/2718060.html
Copyright © 2011-2022 走看看