Javascript AJAX / SOAP client

Very useful little gem! I had posted on working around the limitations of MS’s NTLM authentication “double-hop” issue by using AJAX methods to retrieve information from secured web services in conjunction with IE’s security zones. Although SOAP is XML and nothing stops a person from manually creating a SOAP wrapper, this tool actually extracts information from the WSDL file and can pull values from the result.

You will need to follow certain WSDL conventions and make sure that you pass a Domino web service/agent URL in a particular fashion, and make a slight change in the JS file of the soap client.


The script needs five parameters; the WSDL address, method name, parameters, boolean to mark asynchronous, and a method name to call when done. The WSDL address has to use a particular URL convention which is the web service URI appended with “?WSDL”. This means that the agent that you use to fork the logic of the web service will need to have a little piece of code to forward the user to the page that has the WSDL

strQs = docCtx.QUERY_STRING(0)
If Instr(strQs,"wsdl") > 0 Then
	Print "[/yourDirectory/yourDb.nsf/wsdl]"
	Exit Sub
End If

In order to place the extra parameter into a Domino URL you will need to append the full command in the URL, which in my case is “?OpenAgent”. Then you can add the “&WSDL” onto the end of the URL. The final piece is the slight change in the JS source which normally appends a “?WSDL” to the end of the URL. This needs to be changed to “&WSDL” for Domino.

xmlHttp.open("GET", url + "&wsdl", async);

This is what the eventual call will look like:

url =http://myServer.domain.com/directory/db.nsf/ws?openagent;
var pl = new SOAPClientParameters();
pl.add("param1", "test1");
pl.add("param2", "test2");
SOAPClient.invoke(url, "getSomeData", pl, true, SoapResults_callBack);

The SoapResults_callBack function is what gets called when the SOAP request returns to the client.

function SoapResults_callBack(r,y,z){
	xH=getXMLHTTP();
	xH.open("GET", "http://server.domain/xslFile.xsl" ,false);
	xH.send(null);
	var xslFile = xH.responseXML;
	document.getElementById("results").innerHTML = xslt(y,xslFile)
}

The last thing that you may want to do is an XSLT transformation to take the SOAP XML and convert it into (X)HTML for your page. This can get tricky by itself as each browser works its XSL transformation magic a little different. Here is the script that I am using to grab the XML and the XSL to do the magic in the major browsers:

function xslt(xmlDoc,xslDoc) {
	var transform;
	if (typeof ActiveXObject != 'undefined') {
		transform = xmlDoc.transformNode(xslDoc);
	}
	else {
		var xsl = new XSLTProcessor();
		xsl.importStylesheet(xslDoc);
		var fragment=xsl.transformToFragment(xmlDoc, document);
		if( fragment.childNodes.length>0 ){
			transform = fragment.childNodes[0].innerHTML;
		}else{
			alert("error");
		}
	}
	return transform;
}

and lastly, my copy/paste cross browser function to grab an XML/HTTP object:

function getXMLHTTP(){
	var A = null;
	// let's see if we are using IE, check for latest version first
	try{
		A = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			A = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(oc){
			A = null;
		}
	}
	if(!A && typeof XMLHttpRequest != "undefined") {
		// at this point we are using non-IE
		A = new XMLHttpRequest();
	}
	return A;
}

There you have it, SOAP from javascript with ease. Happy hunting!

One Response to “Javascript AJAX / SOAP client”

  1. Matteo Casati Says:

    “Very useful little gem”? Thank you! :-)

    Great work for Domino compatibility.

    Regards,
    Matteo

Leave a Reply