Click here to Skip to main content
Email Password   helpLost your password?

Introduction

A lot of talking about AJAX is taking place here and there; AJAX is the acronym of "Asynchronous JavaScript and XML", a technology based on XMLHttpRequest, which is now supported by all main browsers. The basic idea is quite simple - and not actually a breakthrough - but it allows updating a page following a server request, without reloading the entire set of data. Some examples can be found on GMail or Google Suggest. For additional information about AJAX, you can see Wikipedia.

In this article, we propose a solution based on AJAX that has a great advantage with respect to those commonly found in Internet: calls are made to the Web Services.

This permits:

  1. On the server side, we only have to expose a Web Service with the required methods (instead of generating dynamic pages incorporating data that are based on a custom syntax or on a generic XML).
  2. On the client side, we use the WSDL (Web Service Description Language) to automatically generate a JavaScript proxy class so as to allow using the Web Service return types - that is similar to what Visual Studio does when a Web Reference is added to the solution.

The following diagram shows the SOAP Client workflow for asynchronous calls:

The Client invokes the "SOAPClient.invoke" method using a JavaScript function and specifies the following:

The "SOAPClient.invoke" method executes the following operations (numbers refer to the previous diagram):

  1. It gets the WSDL and caches the description for future requests.
  2. It prepares and sends a SOAP (v. 1.1) request to the server (invoking method and parameter values).
  3. It processes the server reply using the WSDL so as to build the corresponding JavaScript objects to be returned.
  4. If the call mode is async, the callback method is invoked, otherwise it returns the corresponding object.

Using the code

After having exposed our idea about consuming a Web Service via JavaScript, we only have to analyze the code.

Let's start with the class for the definition of the parameters to be passed to the Web method: "SOAPClientParameters":

function SOAPClientParameters()
{
    var _pl = new Array();
    this.add = function(name, value) 
    {
        _pl[name] = value; 
        return this; 
    }
    this.toXml = function()
    {
        var xml = "";
        for(var p in _pl)
        {
            if(typeof(_pl[p]) != "function")
                xml += "<" + p + ">" + 
                       _pl[p].toString().replace(/&/g, 
                         "&").replace(/</g, 
                         "<").replace(/>/g, 
                         ">

The code simply consists of an internal dictionary (associative array) with the parameter name (key) and the related value; the "add" method allows appending new parameters, while the "toXml" method provides XML serialization for SOAP requests (see "SOAPClient._sendSoapRequest").

Let's define the "SOAPClient" class, which can only contain static methods in order to allow async calls, and the only "public" method within this class: "SOAPClient.invoke".

Note: since JavaScript does not foresee access modifiers - such as "public", "private", "protected", etc. - we'll use the "_" prefix to indicate private methods.

function SOAPClient() {}
SOAPClient.invoke = function(url, method, 
                      parameters, async, callback)
{
    if(async)
        SOAPClient._loadWsdl(url, method, 
                    parameters, async, callback);
    else
        return SOAPClient._loadWsdl(url, method, 
                   parameters, async, callback);
}

The "SOAPClient.invoke" method interface is described above; our implementation checks whether the call is async (call result will be passed to the callback method) or sync (call result will be directly returned). The call to the Web Service begins by invoking the "SOAPClient._loadWsdl" method:

SOAPClient._loadWsdl = function(url, method, parameters, async, callback)
{
    // load from cache?

    var wsdl = SOAPClient_cacheWsdl[url];
    if(wsdl + "" != "" && wsdl + "" != "undefined")
        return SOAPClient._sendSoapRequest(url, method, 
                    parameters, async, callback, wsdl);
    // get wsdl

    var xmlHttp = SOAPClient._getXmlHttp();
    xmlHttp.open("GET", url + "?wsdl", async);
    if(async) 
    {
        xmlHttp.onreadystatechange = function() 
        {
            if(xmlHttp.readyState == 4)
                SOAPClient._onLoadWsdl(url, method, 
                     parameters, async, callback, xmlHttp);
        }
    }
    xmlHttp.send(null);
    if (!async)
        return SOAPClient._onLoadWsdl(url, method, parameters, 
                                    async, callback, xmlHttp);
}

The method searches the cache for the same WSDL in order to avoid repetitive calls:

SOAPClient_cacheWsdl = new Array();

If the WSDL is not found in the cache (it's the first call in the current context), it is requested from the server using an XMLHttpRequest, according to the required mode (sync or not). Once an answer is obtained from the server, the "SOAPClient._onLoadWsdl" method is invoked:

SOAPClient._onLoadWsdl = function(url, method, 
             parameters, async, callback, req)
{
    var wsdl = req.responseXML;
    SOAPClient_cacheWsdl[url] = wsdl;
    return SOAPClient._sendSoapRequest(url, method, 
                       parameters, async, callback, wsdl);
}

A WSDL copy is stored into the cache and then the "SOAPClient._sendSoapRequest" method is executed:

SOAPClient._sendSoapRequest = function(url, method, 
                 parameters, async, callback, wsdl)
{
    var ns = (wsdl.documentElement.attributes["targetNamespace"] + 
              "" == "undefined") ? 
              wsdl.documentElement.attributes.getNamedItem(
              "targetNamespace").nodeValue : 
              wsdl.documentElement.attributes["targetNamespace"].value;
    var sr = 
        "<?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>" +
        "<" + method + " xmlns=\"" + ns + "\">" +
        parameters.toXml() +
        "</" + method + "></soap:Body></soap:Envelope>";
    var xmlHttp = SOAPClient._getXmlHttp();
    xmlHttp.open("POST", url, async);
    var soapaction = 
      ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;
    xmlHttp.setRequestHeader("SOAPAction", soapaction);
    xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    if(async) 
    {
        xmlHttp.onreadystatechange = function() 
        {
            if(xmlHttp.readyState == 4)
                SOAPClient._onSendSoapRequest(method, 
                     async, callback, wsdl, xmlHttp);
        }
    }
    xmlHttp.send(sr);
    if (!async)
        return SOAPClient._onSendSoapRequest(method, 
                    async, callback, wsdl, xmlHttp);
}

The service namespace is taken out of the WSDL (using different XPath queries for Internet Explorer and Mozilla / FireFox), then a SOAP v. 1.1 request is created and submitted. The "SOAPClient._onSendSoapRequest" method will be invoked upon receiving the server response:

SOAPClient._onSendSoapRequest = function(method, 
                     async, callback, wsdl, req)
{
    var o = null;
    var nd = SOAPClient._getElementsByTagName(
             req.responseXML, method + "Result");
    if(nd.length == 0)
    {
        if(req.responseXML.getElementsByTagName(
                     "faultcode").length > 0)
            throw new Error(500, 
              req.responseXML.getElementsByTagName(
              "faultstring")[0].childNodes[0].nodeValue);
    }
    else
        o = SOAPClient._soapresult2object(nd[0], wsdl);
    if(callback)
        callback(o, req.responseXML);
    if(!async)
        return o;        
}

The server response is processed looking for faults: if found, an error is raised. Instead, if a correct result is obtained, a recursive function will generate the return type by using the service description:

SOAPClient._soapresult2object = function(node, wsdl)
{
    return SOAPClient._node2object(node, wsdl);
}

SOAPClient._node2object = function(node, wsdl)
{
    // null node

    if(node == null)
        return null;
    // text node

    if(node.nodeType == 3 || node.nodeType == 4)
        return SOAPClient._extractValue(node, wsdl);
    // leaf node

    if (node.childNodes.length == 1 && 
       (node.childNodes[0].nodeType == 3 || 
        node.childNodes[0].nodeType == 4))
          return SOAPClient._node2object(node.childNodes[0], wsdl);
    var isarray = SOAPClient._getTypeFromWsdl(node.nodeName, 
                  wsdl).toLowerCase().indexOf("arrayof") != -1;
    // object node

    if(!isarray)
    {
        var obj = null;
        if(node.hasChildNodes())
            obj = new Object();
        for(var i = 0; i < node.childNodes.length; i++)
        {
            var p = SOAPClient._node2object(node.childNodes[i], wsdl);
            obj[node.childNodes[i].nodeName] = p;
        }
        return obj;
    }
    // list node

    else
    {
        // create node ref

        var l = new Array();
        for(var i = 0; i < node.childNodes.length; i++)
            l[l.length] = 
              SOAPClient._node2object(node.childNodes[i], wsdl);
        return l;
    }
    return null;
}

SOAPClient._extractValue = function(node, wsdl)
{
    var value = node.nodeValue;
    switch(SOAPClient._getTypeFromWsdl(
           node.parentNode.nodeName, wsdl).toLowerCase())
    {
        default:
        case "s:string":            
            return (value != null) ? value + "" : "";
        case "s:boolean":
            return value+"" == "true";
        case "s:int":
        case "s:long":
            return (value != null) ? parseInt(value + "", 10) : 0;
        case "s:double":
            return (value != null) ? parseFloat(value + "") : 0;
        case "s:datetime":
            if(value == null)
                return null;
            else
            {
                value = value + "";
                value = value.substring(0, value.lastIndexOf("."));
                value = value.replace(/T/gi," ");
                value = value.replace(/-/gi,"/");
                var d = new Date();
                d.setTime(Date.parse(value));                                        
                return d;                
            }
    }
}
SOAPClient._getTypeFromWsdl = function(elementname, wsdl)
{
    var ell = wsdl.getElementsByTagName("s:element");    // IE

    if(ell.length == 0)
        ell = wsdl.getElementsByTagName("element");    // MOZ

    for(var i = 0; i < ell.length; i++)
    {
        if(ell[i].attributes["name"] + "" == "undefined")    // IE

        {
            if(ell[i].attributes.getNamedItem("name") != null && 
               ell[i].attributes.getNamedItem("name").nodeValue == 
               elementname && ell[i].attributes.getNamedItem("type") != null) 
                return ell[i].attributes.getNamedItem("type").nodeValue;
        }    
        else // MOZ

        {
            if(ell[i].attributes["name"] != null && 
               ell[i].attributes["name"].value == 
               elementname && ell[i].attributes["type"] != null)
                return ell[i].attributes["type"].value;
        }
    }
    return "";
}

The "SOAPClient._getElementsByTagName" method optimizes XPath queries according to the available XML parser:

SOAPClient._getElementsByTagName = function(document, tagName)
{
    try
    {
        return document.selectNodes(".//*[local-name()=\""+ 
                                           tagName +"\"]");
    }
    catch (ex) {}
    return document.getElementsByTagName(tagName);
}

A factory function returns the XMLHttpRequest according to the browser type:

SOAPClient._getXmlHttp = function() 
{
    try
    {
        if(window.XMLHttpRequest) 
        {
            var req = new XMLHttpRequest();
            if(req.readyState == null) 
            {
                req.readyState = 1;
                req.addEventListener("load", 
                    function() 
                    {
                        req.readyState = 4;
                        if(typeof req.onreadystatechange == "function")
                            req.onreadystatechange();
                    },
                    false);
            }
            return req;
        }
        if(window.ActiveXObject) 
            return new ActiveXObject(SOAPClient._getXmlHttpProgID());
    }
    catch (ex) {}
    throw new Error("Your browser does not support XmlHttp objects");
}

SOAPClient._getXmlHttpProgID = function()
{
    if(SOAPClient._getXmlHttpProgID.progid)
        return SOAPClient._getXmlHttpProgID.progid;
    var progids = ["Msxml2.XMLHTTP.5.0", 
                   "Msxml2.XMLHTTP.4.0", 
                   "MSXML2.XMLHTTP.3.0", 
                   "MSXML2.XMLHTTP", 
                   "Microsoft.XMLHTTP"];
    var o;
    for(var i = 0; i < progids.length; i++)
    {
        try
        {
            o = new ActiveXObject(progids[i]);
            return SOAPClient._getXmlHttpProgID.progid = progids[i];
        }
        catch (ex) {};
    }
    throw new Error("Could not find an installed XML parser");
}

Points of Interest

By using a single little (less than 10 KB) JavaScript library and, on the server side, simply exposing a Web Service with remote methods, you can use AJAX to create dynamic Web applications with no need for reloading the entire page.

See the on-line demo for an example of usage.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralPlz tell me how to call ur script---- URGENT
Subho1986
1:45 21 Jan '10  
<pre></pre>Hi,

We are facing problems while using the soapclient.js script. I have mentioned below the web services which we are trying to hit. The service can be found in http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=46

When I am trying to run the code its giving me en error stating ‘IPAddress’ is not defined. But from the wsdl I believe it’s the input parameter. Will be great for us if you kindly let us know where
we are going wrong. Its needed urgently for our current project.
<b>Code Details</b>:
/*
Summary
GeoIPService enables you to easily look up countries by IP address / Context

Endpoint
http://www.webservicex.net/geoipservice.asmx

Disco
http://www.webservicex.net/geoipservice.asmx?Disco

WSDL Location
http://www.webservicex.net/geoipservice.asmx?wsdl

*/
<apex:includeScript value="{!$Resource.soapClientJS}"/>;

   <script>
      function GetSoapResponse()
      {
            try {
                  alert('hi');
                  var pl = new SOAPClientParameters();
                 
                  var url ="http://www.webservicex.net/geoipservice.asmx"; // web service URL
                  var pl = new SOAPClientParameters();
                  pl.add(IPAddress,'216.239.59.99'); // add parameter to web service method
                          
                  SOAPClient.invoke("http://www.webservicex.net/geoipservice.asmx?wsdl", "GetGeoIP", pl, true, GetSoapResponse_callBack); //PLZ CHECK THE CALLING OF UR FUNCTION HERE
            }
            catch(err) {
                  alert(err);
           
            }                                
                 
      }
      function GetSoapResponse_callBack(r, soapResponse)
      {
            alert('I am in callback');
            if(soapResponse.xml)      // IE
                  alert(soapResponse.xml);
            else      // MOZ
                  alert((new XMLSerializer()).serializeToString(soapResponse));
      }
     
      </script>
<apex:form >
            <apex:commandButton id="TEST2" onclick="GetSoapResponse()"/>
</apex:form>


Thanx in advance for ur support.
GeneralRe: Plz tell me how to call ur script---- URGENT
Matteo Casati
3:28 21 Jan '10  
You must specify the parameter name as string:
pl.add("IPAddress","216.239.59.99");

HTH
GeneralRe: Plz tell me how to call ur script---- URGENT
indranily81
3:52 21 Jan '10  
Hi Mat,

I am also facing the same issue. I just put the input parameter in quotes but this time no response is coming. I have tried to debug the code and in debug mode I saw the wsdl is coming as null in the below line;

var ns = (wsdl.documentElement.attributes["targetNamespace"] + "" == "undefined") ? wsdl.documentElement.attributes.getNamedItem("targetNamespace").nodeValue : wsdl.documentElement.attributes["targetNamespace"].value;

just not sure if it is the cause of the error.

I am following the same code as subho mentioned.


Thanks
indranily81
GeneralRe: Plz tell me how to call ur script---- URGENT
Matteo Casati
4:04 21 Jan '10  
OMG no idea about this behavior! Your wsdl seems perfect! Pls try to debug the response watching the full xml returned...
Good luck!
QuestionMatteo I need help
Arlind.burnutciu
23:23 28 Dec '09  
Hi, Matteo

I am new in Javascript and I am trying to understand as much as I can from your grear example about WebServices...
Here on this line of code I dont understnd what you replace, and where do you refere by location.href.replace(...)

var url = document.location.href.replace("demo.htm", "trying.asmx");

Thx, Lindi
AnswerRe: Matteo I need help
Matteo Casati
3:33 21 Jan '10  
Hi Lindy, the line:
var url = document.location.href.replace("demo.htm", "trying.asmx");

specify the webservice absolute url supposing that it's located in the same folder of demo.htm file. Anyway you can also use a relative path (referred to the current page), e.g.
var url = "../services/trying.asmx"

HTH
Generalwsdl is null error [modified]
nix2009
23:39 25 Nov '09  
Hi, I tried to play around with the 2.4 library and all I get is a "wsdl is null" error in my error console (Firefox 3.5.5). I tired to demo code directly.

However if I run the demo on the following webpage: http://www.guru4.net/articoli/javascript-soap-client/demo/en.aspx#d1[^] everything works.

Anybody had this problem before?

You can check the code here:

http://www.linkflora.pl/demos/dotnet/default.htm[^]

modified on Thursday, November 26, 2009 4:53 AM

GeneralRe: wsdl is null error
Matteo Casati
12:57 26 Nov '09  
Hello Artur,
your server is not able to execute ASP.NET Web Services properly: I've tried to open your demo .asmx file (http://www.linkflora.pl/demos/dotnet/webservicedemo.asmx[^]) directly in browser but I've got the source code as response! (JFYI the right behavior is this one: http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx[^])
HTH
Generalwsdl in client
pabz_sarquilla
9:28 28 Oct '09  
hi Matteo,

I'm new to SOAP and WSDL, and your article thought me how and what is needed for my app.
Question, what needs to be done if the WSDL is given in clientside? I'm assuming invoke method would be changed but not sure what effect will it produce?

Thanks,
Pabz
Generalproblem with the request
andré brunelli
6:40 28 Jul '09  
Hi,

I have a problem with the use of your solution in my code. when I try to send a message to the server by your javascript solution, the server receives the message and invokes the right webmethod, but it doesdn't receive any parameters sent by the client. I am using Netbeans 6.5, JAX-WS and Apache Tomcat to devellop the webservice. can you help me?

thanks,
André Brunelli
GeneralProblem to get the response from the web service
Matrix81818181
9:22 3 Jun '09  
Hi, i'm using Axis with javascript SoapClient 2.4. I can call easily with my web service (java) but when I received to response and I want to show it (alert(reponse)), I only see "null".

Do I have to make some correction (in the soapclient.js or my webpage) to properly use the response content ?

Here an example of the code I use :
function SendSoapMessage()
{
var pl = new SOAPClientParameters();

pl.add("param","test");

SOAPClient.invoke("{PROXY URL}", "addItem", pl, true, SoapCallBack);
}

function SoapCallBack(reponse, xmlString)
{
alert(reponse);
alert(xmlString);
}

QuestionPOSTING XML
Member 4595585
4:20 2 Jun '09  
Hi,

How do I post an XML string for eg. "<?xml version='1.0' encoding='ISO-8859-1' ?><DEALER_INFO><DEALER_CODE>hjk123<DEALER_CODE>   <ID_NUMBER>8312345678964<ID_NUMBER><DEALER_INFO>"
to a web service function?
GeneralA minor improvement to it and it saves me a LOT of effort ;P
Gr1mR33p3r
2:43 7 May '09  
I made 2 minor changes to this library which I would like to share.

First off, GREAT library.

Secondly, the changes:
I changed the code
; if(typeof(_pl[p]) != "function")
xml += "<" + p + ">" +
_pl[p].toString().replace(/&/g,
"&").replace(/</g,
"<").replace(/>/g,
">


to
; if (typeof(_pl[p]) != "function") 
if (p.indexOf(" ") != -1)
{
xml += "<" + p + ">" + _pl[p].toString().replace(/&/g, "&amp;") + "</" + p.substring(0, p.indexOf(" ")) + ">";
}
else
{
xml += "<" + p + ">" + _pl[p].toString().replace(/&/g, "&amp;") + "</" + p + ">";
}


I basically don't remove < and > from the content and I also only add the FIRST word to the closing bracket. What this allows me to do is to post more complex xml, specifically a nested xml item:

var pl = new SOAPClientParameters();
pl.add("MapName", "Layers");
pl.add("LayerIDs", "");

//Build LegendPatch paramater
var lpatch = new SOAPClientParameters();
with (lpatch)
{
add("AreaPatch", "");
add("Height", "20");
add("ImageDPI", "96");
add("LinePatch", "");
add("Width", "20");
}

pl.add("LegendPatch", lpatch.toXml());


and also allows me to pass extra parameters such as subtypes:

mapdesc.add('MapArea xmlns:q1="http://www.esri.com/schemas/ArcGIS/9.3" xsi:type="q1:MapExtent"',"blahblahblahetc...");

Smile
GeneralRe: A minor improvement to it and it saves me a LOT of effort ;P
Member 4595585
5:12 2 Jun '09  
Hi,

How do I post an XML string for eg. "<?xml version='1.0' encoding='ISO-8859-1' ?><DEALER_INFO><DEALER_CODE>hjk123<DEALER_CODE>   <ID_NUMBER>8312345678964<ID_NUMBER><DEALER_INFO>"
to a web service function?
GeneralRe: A minor improvement to it and it saves me a LOT of effort ;P
Gr1mR33p3r
19:38 2 Jun '09  
Make the changes as I said above and then try this:

var pl = new SOAPClientParameters();

//Build DealerInfo paramater
var dInfo = new SOAPClientParameters();
with (dInfo)
{
add("DEALER_CODE", "hjk123");
add("ID_NUMBER", "8312345678964");
}

pl.add("DEALER_INFO", dInfo.toXml());

SOAPClient.invoke(SOAP_SERVICE_URL, "helloWorld_callback", pl, true, helloWorld);
Questionproblem if proxy use in case of cross domain access
nawash
14:00 6 May '09  
hi, Your AJAX SOAP wrapper is great but I can not get it to work in the particular case of cross domain call. I use a proxy which is :


<?php

// Is it a POST or a GET?
$path = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
//$url = HOSTNAME.$path;
$url = $path;

// Open the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['url']) {
$postvars = '';
while ($element = current($_POST)) {
$postvars .= key($_POST).'='.$element.'&';
next($_POST);
}
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$xml = curl_exec($session);

// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");

echo $xml;
curl_close($session);
?>



in my web page (index4.html), on my local http server I use your lib this way :

<script type="text/javascript" src="soapclient.js"></script>
<script type="text/javascript">

var url = document.location.href.replace("index4.html","martinproxy.php?url=http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx");


function HelloWorld()
{
var pl = new SOAPClientParameters();
SOAPClient.invoke(url, "HelloWorld", pl, true, HelloWorld_callBack);

}
function HelloWorld_callBack(r)
{
alert(r);
}
</script>



All I get is null in the alert dialog and the content of http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx in req.responseXML of SOAPClient._onSendSoapRequest
I can not sort it out, can you help ?
thx
GeneralDonate w PayPal
smoore4
3:58 6 Mar '09  
I hope all you guys are donating as I did....this code is a huge timesaver.
GeneralRe: Donate w PayPal
Matteo Casati
4:22 6 Mar '09  
Thank you a lot Steven!
I hope some guys will follow your advice Poke tongue
GeneralDoes it work with SOAP 1.2?
skummy
23:55 24 Nov '08  
Good work Smile!

But I only get it worked by using your WSDL-File. It seems that your WSDL-File is written in SOAP 1.1! But new implementations like JAXWS 2.1 use SOAP 1.2 and so your script does not work for me because the parsing of the WSDL-File is wrong.

Can you modify your script or can somebody show me how it works with SOAP 1.2?

Thanks
Sandro
GeneralResult object is empty. Debug tips wanted.
NikDaSwede
9:01 9 Sep '08  
Hi,

I do get a soapResponse but the object in the callBack procedure is empty.

The first alert message shows me the soapResonse. Excellent.
Tha last alert message just says "Parsed reply is :".

Do you have any debugging tips?
What should I look for?
How do perform alerts from a *.js file?

Thanks in advance,
NikDaSwede

/************* code snippet **************/
.
.
.
SOAPClient.invoke(url, "AuthenticateUser", pl, true, AuthenticateUser_callBack);
}
function AuthenticateUser_callBack(u, soapResponse)
{
if(soapResponse.xml) // IE
alert("Reply received\r\n\r\n" + soapResponse.xml);
else // MOZ
alert("Reply received\r\n\r\n" + (new XMLSerializer()).serializeToString(soapResponse));

var text = '';
for(i in u) {
text += "response[" + i + "] = " + u[i] + "\r\n";
}

alert("Parsed reply is : \r\n\r\n" + text);
}
.
.
/************* code snippet **************/
GeneralUsing webservice on tomcat + axis
S.Kern
12:18 30 Jun '08  
Hello Matteo,
I've tried your excellent SOAP-client in combination with the tomcat server (V5.5)
and the webservice toolkit "AXIS" (axis1, V1.4).

AXIS seems to return the result of the webservice in a funcname+"Return"- Tag
instead of funcname+"Result".

After adding a second result-check to your code my test works fine:
...
SOAPClient._onSendSoapRequest = function(method, async, callback, wsdl, req)
{
var o = null;
var nd = SOAPClient._getElementsByTagName(req.responseXML, method + "Result");
if (nd.length==0)
nd = SOAPClient._getElementsByTagName(req.responseXML, method + "Return");

if(nd.length == 0)

...

Greetings
AnswerRe: Using webservice on tomcat + axis
dibeonline
11:45 13 Dec '08  
I try your edit code is't work but I edit a litter in your code it work. I think its up to version of Axis.
if(nd.length == 0)
nd = SOAPClient._getElementsByTagName(req.responseXML, "ns:return");

GeneralBug in Soap Client version 2.1 on Safari
harel gruia
23:44 31 May '08  
The folowing statement doesn't work Safari

if(o.constructor.toString().indexOf("function Array()") > -1)

I've replaced it with my own implementation

if(GetObjectType(o) == "Array")

where

function GetObjectType(obj)
{
var sObjectType = "Unknown";

// Handle primitive types first.
switch(typeof obj)
{
case "string":
return "String";
case "boolean":
return "Boolean";
case "number":
return "Number";
case "function":
return "Function";
case "object":
if(typeof obj.length == "number") // Assuming Array type.
sObjectType = "Array";
else
sObjectType = "Object";
break;
} // switch

try
{
if(obj == null || typeof obj != "object")
return sObjectType;

var sConstructor = obj.constructor.toString();
var nInx1 = sConstructor.indexOf("function");
var nInx2 = sConstructor.indexOf("(");

if(nInx1 >= 0 && nInx2 > 0 && nInx1 < nInx2 && nInx2 < sConstructor.length)

sObjectType = sConstructor.substring(nInx1+9,nInx2);

}catch(e){}

return sObjectType
} // GetObjectType

GeneralIE7 and WSO2
Sean Montague
11:13 19 Mar '08  
At least with wso2, SOAPClient._getXmlHttp should be:

if(window.XMLHttpRequest) {
try {
document.implementation.createDocument('','doc',null);
var req = new XMLHttpRequest();
} catch (e) {
try {
new ActiveXObject('Microsoft.XMLDOM');
var req = new ActiveXObject(SOAPClient._getXmlHttpProgID());
} catch (e) {}
}
// some versions of Moz do not support the readyState property and the onreadystate event so we patch it!
if(req.readyState == null) {
req.readyState = 1;
req.addEventListener("load",
function() {
req.readyState = 4;
if(typeof req.onreadystatechange == "function")
req.onreadystatechange();
},
false);
}
return req;
} else {
return new ActiveXObject(SOAPClient._getXmlHttpProgID());
}
GeneralProblem with Firefox
cameleoni
1:25 26 Oct '07  
I have a problem with using soapclient.js in Firefox. It works well in IE.
It's perhaps security issue, error console told me that there is no privilege to run method
XMLHttpRequest.open


Please help.


cameleoni


Last Updated 24 Jan 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010