java - Creating a JavaScript SOAP Client -


i'm creating soap client js, first time webservices , must have several mistakes in code.

the poit is, code, cant take acces webservice, don't know how access methods inside. webservice gives me following response:

<h1>version</h1> <p>hi there, axis service!</p> <i>perhaps there form invoking service here...</i> 

instead of correct xml method i'm calling.

this code of soap client:

<html>  <script type="text/javascript">      function run(){          var objxmlhttprequest = new xmlhttprequest();         objxmlhttprequest.open("get", "http://localhost:8080/crunchifyws/services/version?wdsl/", true);         objxmlhttprequest.onreadystatechange = function () {         //alert(objxmlhttprequest.readystate+"   "+ objxmlhttprequest.status);         if (objxmlhttprequest.readystate == 4 && objxmlhttprequest.status == 200) {             result = objxmlhttprequest.responsexml;             alert(objxmlhttprequest.responsetext);             alert(objxmlhttprequest.responsexml);           }         }         objxmlhttprequest.setrequestheader("content-type", "text/xml; charset=utf-8");          var packet = '<?xml version="1.0" encoding="utf-8" ?><soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:body><getversion xmlns="http://service.web.com.crunchify/"></getversion></soap:body></soap:envelope>';          objxmlhttprequest.send(packet);         // add mentioned below code if application calls webservice synchronously. otherwise use "onreadystatechange" process response.         response = objxmlhttprequest.responsexml;         alert(objxmlhttprequest.responsetext+ "  "+ response);     } </script>  <head> </head> <body>     <button  onclick="run()">dale!</button> </body> </html> 

i think te mistake should in part, but, said, first time , don't know i'm doing.

solved

the first problem on line :

objxmlhttprequest.open("get", "http://localhost:8080/crunchifyws/services/version?wdsl/", true); 

this url http://localhost:8080/crunchifyws/services/version?wsdl gives list of services can call.

so you'll have :

objxmlhttprequest.open("get", "http://localhost:8080/crunchifyws/services/myservicemethod", true); 

that's first problem think. in second time, have send parameters not entire soap envelope.

var packet = '<?xml version="1.0" encoding="utf-8" ?><soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:body><getversion xmlns="http://service.web.com.crunchify/"></getversion></soap:body></soap:envelope>';  objxmlhttprequest.send(packet); 

like :

var parameters = "param1=15&param2=30" objxmlhttprequest.send(parameters); 

and method send should out of objxmlhttprequest.onreadystatechange = function (){}

this function callback examine response.

don't hesitate @ link : http://www.w3schools.com/xml/xml_dtd.asp

hope help


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -