【问题标题】:Javascript soap client doesn't work (wash_out service)Javascript 肥皂客户端不起作用(洗出服务)
【发布时间】:2012-12-27 11:35:14
【问题描述】:

我用 Ruby 编写了 Web 服务(使用wash_out)。这是链接:http://dictionary.vipserv.org/slownik_de_pls/wsdl

我找到了编写 JavaScript 肥皂客户端的解决方案。代码如下:

<html>
<head>
    <title>SOAP JavaScript Client Test</title>
    <script type="text/javascript">
        function soap() {
    try
    {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http://www.dictionary.vipserv.org/slownik_de_pls/wsdl/', true);

            // build SOAP request
            var sr = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="urn:WashOut"><soap:Body><tns:get_word_response><value xsi:type="xsd:string">robic</value></tns:get_word_response></soap:Body></soap:Envelope>';


            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {

                        alert('done use firebug to see responce');
                    }
                }
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);
        alert(xmlhttp.responseXML.xml);
            // send request
            // ...
    }
    catch(error)
    {
      alert(error);
    }
        }
    </script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="soap();" />
        </div>
    </form>
</body>
</html>

响应始终为空。怎么了? 干杯,谢谢。

【问题讨论】:

    标签: javascript ruby soap


    【解决方案1】:

    查看 WSDL,您可能需要将 POST 转为 http://dictionary.vipserv.org/slownik_de_pls/action 而不是 http://www.dictionary.vipserv.org/slownik_de_pls/wsdl/

    另外,您可能想查看 jQuery,尤其是 SOAP 库 like this one

    【讨论】:

      【解决方案2】:

      我在 Ruby (Savon) 中有肥皂客户端。在那里它工作正常。我在 jQuery 中找到了其他解决方案,但我遇到了解析错误。下面:

      <html>
       <head>
          <title>Calling Web Service from jQuery</title>
          <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
          <script type="text/javascript">
              $(document).ready(function () {
                  $("#btnCallWebService").click(function (event) {
                      var wsUrl = "http://dictionary.vipserv.org/slownik_de_pls/wsdl";
      
                      var soapRequest = '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="urn:WashOut" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:get_word><wartosc>machen</wartosc></tns:get_word></env:Body></env:Envelope>';
                      $.ajax({
                          type: "POST",
                          url: wsUrl,
                          contentType: "text/xml",
                          dataType: "xml",
                          data: soapRequest,
                          success: processSuccess,
                          error: processError
                      });
      
                  });
              });
      
              function processSuccess(data, status, req) {
                  if (status == "success")
                      $("#response").text($(req.responseXML).find("get_word_response").text());
              }
      
              function processError(data, status, req) {
                  alert(req.responseText + " " + status);
              }  
      
          </script>
      </head>
      <body>
          <h3>
              Calling Web Services with jQuery/AJAX
          </h3>
          Enter your name:
          <input id="txtName" type="text" />
          <input id="btnCallWebService" value="Call web service" type="button" />
          <div id="response" />
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-27
        • 2013-04-03
        • 2017-07-04
        • 2021-11-16
        • 2023-03-20
        相关资源
        最近更新 更多