// SOAPDocProxyD.js
// Author: R. Cunnings

// SOAP proxy implementation...this function makes the SOAP invocation
// and returns the DOM object containing the parsed response message
// along with the request and response message XML.

// constructor for header class
function classHeader(strName, strNS, strContent, strAttributes)
{
	this.strName = strName;
	this.strNamespace = strNS;
	this.strContent = strContent;
	this.strAttributes = strAttributes;
}

// SOAP document style request message over HTTP
// parameters:
// (1) strURL... the URL for the HTTP 'POST' request.
// (2) strSOAPAction... the value of the 'SOAPAction" HTTP header sent along with the 'POST' request.
// (3) strBodyContent... the contents of the SOAP Body element to be sent in the request message.
// (4) arrHeaders... an array of type classHeader containing any headers to be sent in the SOAP request message.
// (5) objTextAreaReq... a text area object into which the request message XML will be placed.
// (6) objTextAreaResp... a text area into which the response message XML will be placed.
//
function SendSOAPRequest(strURL, strSOAPAction, strBodyContent, arrHeaders, objTextAreaReq, objTextAreaResp)
{
	var objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	var strRequestMsg = "";
	var index = 0;

	objXMLHTTP.Open("POST", strURL, false, "", "");
	objXMLHTTP.setRequestHeader("SOAPAction", '"' + strSOAPAction + '"');
	objXMLHTTP.setRequestHeader("Content-Type:", 'text/xml; charset="utf-8"');
	strRequestMsg = '<?xml version="1.0" encoding="UTF-8"?>\r\n';
	strRequestMsg = strRequestMsg + '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">\r\n';

	// construct any header elements required
	if (arrHeaders.length > 0)
	{
		strRequestMsg=strRequestMsg + '<SOAP-ENV:Header>\r\n';
		for (index = 0 ; index < arrHeaders.length; index++)
		{
			objHeader = arrHeaders[index]; 
			strRequestMsg = strRequestMsg + '<h:' + objHeader.strName + ' xmlns:h="' + objHeader.strNamespace + '"';
			if (objHeader.strAttributes != "")
			{
				strRequestMsg = strRequestMsg + ' ' + objHeader.strAttributes;
			}
			strRequestMsg = strRequestMsg + '>';
			strRequestMsg = strRequestMsg + objHeader.strContent;
			strRequestMsg = strRequestMsg + '</h:' + objHeader.strName + '>\r\n'; 
		}
		strRequestMsg=strRequestMsg + '</SOAP-ENV:Header>\r\n';
	}
	strRequestMsg=strRequestMsg + '<SOAP-ENV:Body>\r\n';
	strRequestMsg=strRequestMsg + strBodyContent;
	strRequestMsg=strRequestMsg + '\r\n</SOAP-ENV:Body>\r\n';
	strRequestMsg=strRequestMsg + '</SOAP-ENV:Envelope>';
	objXMLHTTP.Send (strRequestMsg);
    
	objTextAreaReq.value = strRequestMsg;
	objTextAreaResp.value = objXMLHTTP.ResponseText;
	return objXMLHTTP.ResponseXML;
}
