0

我用 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>

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

4

2 回答 2

0

看一下 WSDL,您可能需要 toPOSThttp://dictionary.vipserv.org/slownik_de_pls/action不是 to http://www.dictionary.vipserv.org/slownik_de_pls/wsdl/

此外,您可能想查看 jQuery,尤其是像这样的 SOAP 库。

于 2012-12-27T12:22:36.180 回答
0

我在 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>
于 2012-12-29T14:20:48.003 回答