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" );
