简体   繁体   中英

Javascript soap client doesn't work (wash_out service)

I wrote Web Service in Ruby (using wash_out). Here is link : http://dictionary.vipserv.org/slownik_de_pls/wsdl

I found solution to write javascript soap client. Code below:

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

Response is always null. What is wrong? Cheers, thanks.

Take a look at the WSDL, you probably need to POST to http://dictionary.vipserv.org/slownik_de_pls/action instead of to http://www.dictionary.vipserv.org/slownik_de_pls/wsdl/ .

Also, you might want to look at jQuery, and in particular a SOAP library like this one .

I have soap client in Ruby (Savon). There it works fine. I found other solution in jQuery, but I've got parse error. Below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM