Document Information

Last modified:
2007/05/31 18:21 by thron7

Using gSOAP and WSDL with qooxdoo

Preface

The interface of your server provided API is communicated to the web clients through the WSDL (Web Service Description Language) file. gSOAP can be used, to create this file.

To convert this interface to usefull JavaScript functions, we will use a xslt transformation with the help of the wsdl.xslt file, to be used in concert with the wsdl.js library. The description can be found Here .

Please note that I modified the original files quit a bit to avoid having to use any server side transformation.

As we are using a fat JavaScript client, why not use JavaScript to do the transformation for us. This approach is described in detail Here (Gecko specific).

The following short script will read in both files and do the transformation for Gecko.

<script language="JavaScript" id="interface"></script>
 
<script type="text/javascript" src="wsdl.js"></script>
<script language="JavaScript"> <!-- 
    var xslStylesheet;
    var xsltProcessor = new XSLTProcessor();
    var myDOM;
 
    var xmlDoc;
 
    function Init(){
        // load the xslt file, wsdl.xslt
        var myXMLHTTPRequest = new XMLHttpRequest();
        myXMLHTTPRequest.open("GET", "wsdl.xslt", false);
        myXMLHTTPRequest.send(null);
 
        xslStylesheet = myXMLHTTPRequest.responseXML;
        xsltProcessor.importStylesheet(xslStylesheet);
 
        // load the soap generated wsdl - file, server.wsdl
        myXMLHTTPRequest = new XMLHttpRequest();
        myXMLHTTPRequest.open("GET", "server.wsdl", false);
        myXMLHTTPRequest.send(null);
 
        xmlDoc = myXMLHTTPRequest.responseXML;
 
        var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
 
        myDOM = fragment;
        document.getElementById("interface").appendChild(fragment);
    }
    Init ();

Now you can call the generated functions in JavaScript like this :

function loginResponse ( resp )
  {
    var user = resp [ "UserId" ];
    var loginID = resp [ "LoginId" ];
    
    proxies.Service.getTime.func = timeResponse;
    proxies.Service.getTime ( resp );
  }
 
  function timeResponse ( time )
  {
      // which ever response ...
  }
 
  // first we set the response handler
  proxies.Service.login.func = loginResponse;
  // then we call the  function to call the server.
  proxies.Service.login ( "user", "PWD_test" );

Finally the above implementation is for Gecko only. Following is the cross browser implementation to create the interface ...

Please note that these fuctions are within the wsdl.js file and you can simply include this file and use the buildService - function.

<script language="JavaScript" id="interface"></script>
 
<script type="text/javascript" src="wsdl.js"></script>
<script language="JavaScript"> <!-- 
 
var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);
var html;
 
function buildMyService (iXmlStr, iXslStr) {
    var xmlDoc = getDom(iXmlStr);
    var xslDoc = getDom(iXslStr);
    html = xslt(xmlDoc, xslDoc);
    if ( isIE )
      document.getElementById("interface").innerTEXT = (html != null) ? html : "XSLT Failed!"
    else 
      document.getElementById("interface").innerHtml = (html != null) ? html : "XSLT Failed!"
 
    var pre = "<PRE>" + html + "</PRE>";
    document.getElementById("example").innerHTML = pre;
};
 
function getXmlHttpRequest() {
  var xmlHttp = false;
  if (isIE) {
    try { // IE JavaScript version 1
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e)  {
      try { // IE JavaScript version 2
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
  }
  else {
    try {
      xmlHttp = new XMLHttpRequest();
    } catch (e)  {
      xmlHttp = false;
    }
  }
  return xmlHttp;
};
 
function getDom(iXmlStr)  {
  var xmlHttp = getXmlHttpRequest ();
  xmlHttp.open("GET", iXmlStr, false);
  xmlHttp.send(null);
  return xmlHttp.responseXML;
};
 
function xslt(iXmlDoc, iXslDoc) {
    var html = null;
    try {
        if (isIE) {
            iXmlDoc.async = false;
            iXmlDoc.resolveExternals = false;
            iXslDoc.async = false;
            iXslDoc.resolveExternals = false;
            html = iXmlDoc.transformNode(iXslDoc);
        }
        else {
            var xsltProc = new XSLTProcessor();
            xsltProc.importStylesheet(iXslDoc);
            var resultDoc = xsltProc.transformToDocument(iXmlDoc);
            var xmlSerial = new XMLSerializer;
            html = xmlSerial.serializeToString(resultDoc);
        }
    } catch (e) {
        // Do something
    }
    return html;
};
 
buildMyService ( "server.wsdl", "wsdl.xslt" );

Information

Last modified:
2007/05/31 18:21 by thron7

Account

Not logged in

 
 

Job Offers

To further improve qooxdoo we are seeking javascript developers. Read more...

Rich Ajax Platform (RAP)

RAP uses qooxdoo, Java and the Eclipse development model to build rich web applications. Read more...

qooxdoo Web Toolkit (QWT)

Similar to GWT this framework allows to create impressive qooxdoo applications just using Java. Read more...

Pustefix

Pustefix is a MVC-based web application framework using Java and XML/XSLT. Read more...

 
SourceForge.net Logo

Bad Behavior has blocked 0 potential spam attempts in the last 7 days.