0

Ruby で Web サービスを作成しました (wash_out を使用)。ここにリンクがあります: http://dictionary.vipserv.org/slownik_de_pls/wsdl

JavaScript SOAP クライアントを作成するための解決策を見つけました。以下のコード:

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

応答は常に null です。なにが問題ですか?乾杯、ありがとう。

4

2 に答える 2

0

Ruby(Savon)にsoapクライアントがあります。そこでは正常に動作します。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 に答える
0

WSDLを見てください。おそらく、の代わりに行う必要がPOSTありhttp://dictionary.vipserv.org/slownik_de_pls/actionますhttp://www.dictionary.vipserv.org/slownik_de_pls/wsdl/

また、jQuery、特にこのようなSOAPライブラリを確認することをお勧めします。

于 2012-12-27T12:22:36.180 に答える