1

I tried to make the SOAP call according to the Simplest SOAP example

I am able to send the request through this code but there is no response coming from the server. The sample code i given below:

enter code here

<html>



   <head>
     <title>SOAP call sample</title>
     <script language="Javascript">
     <!--     

     function xmlhttpPost() {
      var symbol = "MSFT";
var xmlhttp = new XMLHttpRequest();

xmlhttp.open("POST", "http://www.webservicex.net/stockquote.asmx?op=GetQuote",true);

xmlhttp.onreadystatechange=function() {

 if (xmlhttp.readyState == 4) {

     alert("ready state callback:"+xmlhttp.readyState);

     alert("response text or XML"xmlhttp.responseText);

     var json = XMLObjectifier.xmlToJSON(xmlhttp.responseXML);

  var result = json.Body[0].GetQuoteResponse[0].GetQuoteResult[0].Text;

  json = XMLObjectifier.xmlToJSON(XMLObjectifier.textToXML(result));

  alert(symbol + ' Stock Quote: $' + json.Stock[0].Last[0].Text); 

 }

}


xmlhttp.setRequestHeader("SOAPAction", "http://www.webserviceX.NET/GetQuote");

xmlhttp.setRequestHeader("Content-Type", "text/xml");

xmlhttp.setRequestHeader("POST","/stockquote.asmx HTTP/1.1");

xmlhttp.setRequestHeader("Host","www.webservicex.net");

xmlhttp.setRequestHeader("Content-Length",1000);

alert("setrequest header completed");

var xml = '<?xml version="1.0" encoding="utf-8"?>' +
 '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + 
   '<soap:Body> ' +
     '<GetQuote xmlns="http://www.webserviceX.NET/"> ' +
       '<symbol>' + symbol + '</symbol> ' +
     '</GetQuote> ' +
   '</soap:Body> ' +
 '</soap:Envelope>';

xmlhttp.send(xml);

alert("request sent"+xmlhttp);

     }
//-->
  </script>

</head>

<form name="main">

  <table>

     <tr>

       <td> <input value="Submit to eBay => " type="button" 
onclick='JavaScript:xmlhttpPost()'></td>
       <td><textarea name="eBayXMLResponse" wrap="soft" rows="40" cols="50" style="overflow:scroll" ID="Textarea1"></textarea></td>
     </tr>
  </table>
 </form>

</html>

I tried this sample with dynamic web project through eclipse and running through apache-tomcat-7.0.25 app server.Is this enough to run this sample? Please help me to display the response in the browser console. i am struggling for a week in this issue..... please let me know if anybody has idea about this.

Community
  • 1
  • 1
  • Maybe you need a packet capture between the client and the server, to see what happened. – ciphor Mar 04 '12 at 09:46
  • hi ciphor, please tell me clearly what is required to get SOAP response? – PONMAHESWARAN KUMAR Mar 04 '12 at 09:57
  • There are multiple possible reasons, 1. the request is not sent out; 2. the server is not working; 3. the response is not sent out; the packet capture would help you to clarify which situation you've met. – ciphor Mar 04 '12 at 11:58
  • can you tell me how to implement the packet capture in this sample? – PONMAHESWARAN KUMAR Mar 04 '12 at 12:46
  • the callback function return the xmlhttp.readyState as 4 i.e. request finished and response is ready.but in my code the xmlhttp.responseXML value is showing as NULL. – PONMAHESWARAN KUMAR Mar 04 '12 at 12:52
  • when the callback function is getting called, the xmlhttp.responseXML is NULL.but the readystate returning the value as 4(request finished and response is ready.) – PONMAHESWARAN KUMAR Mar 04 '12 at 13:01
  • you can use the software "wireshark" to capture the packet between client and server – ciphor Mar 04 '12 at 13:10
  • this wireshark what it will do? – PONMAHESWARAN KUMAR Mar 04 '12 at 13:16
  • Actually, from your comments, I got the information that the client received the response but failed to parse it, is it correct? – ciphor Mar 04 '12 at 13:20
  • ya correct. i used the wireshark . it is working. it is capturing the network packet.the status i given below 3403 1381.157522 192.168.0.149 192.168.0.4 DNS 79 Standard query A www.webservicex.net 3405 1381.868253 192.168.0.4 192.168.0.149 DNS 109 Standard query response CNAME webservicex.net A 173.201.44.188 – PONMAHESWARAN KUMAR Mar 04 '12 at 13:50
  • please give an idea to display the data on browser console. Please see my above code and according to that give your suggestion. – PONMAHESWARAN KUMAR Mar 04 '12 at 13:55
  • Did the line "alert("ready state callback:"+xmlhttp.readyState);" printed out? – ciphor Mar 04 '12 at 14:36
  • Then at which line did it go wrong? – ciphor Mar 05 '12 at 04:02
  • alert(xmlhttp.responseText) is returning nothing. if we put alert(xmlhttp.responseXML) it is returning NULL. – PONMAHESWARAN KUMAR Mar 05 '12 at 04:57
  • one more thing i want to add as : xmlHttpReq.status is returning 0. actually if the request is processed successfully it should return 200 and if the page is not found means the status value should be 404 but it is returning 0 – PONMAHESWARAN KUMAR Mar 05 '12 at 07:06
  • ciphor, when i connect my host machine into our domain this code is working on Internet explorer but it is not working on other browsers like safari and firefox... please suggest to make this work on cross domain if you know.... – PONMAHESWARAN KUMAR Mar 08 '12 at 06:10

1 Answers1

0

try making the soap request using jquery. This works for me:

var soapAction = this.Namespace + this.Contract + '/' + pMethod;
var soapResponse = pMethod + 'Response', soapResult = pMethod + 'Result';
$.ajax({
    type: "POST",
    url: this.URI,
    data: envelope,
    contentType: "text/xml",
    dataType: "xml",
    beforeSend: function (xhr) {
        xhr.setRequestHeader("SOAPAction", soapAction);
    },
    success: function (pData) {
        var answer;
        $(pData).find(soapResponse).each(function () {
            answers=this.parseResult(($(this).find(soapResult))[0]);
        });
        onSuccess(answers);
    },
    error: onError
});
davibq
  • 1,089
  • 11
  • 31