12/02/2010 Development / java script

Para base de estudos!!!

var xmlHttp;
function webService(){
this.codCliente = '100';
this.token;
this.urlWebService = 'http://www.endereco.com.br/WebService.asmx';
this.soapRequest = '<?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>' +
'<TRANSFER_SetData xmlns="http://www.namespace.com.br">' +
'<data>' + this.codCliente + '</data>' +
'</TRANSFER_SetData>' +
'</soap:Body>' +
'</soap:Envelope>';
};

webService.prototype.setCliente = function(codCliente) {
this.codCliente = codCliente;
};

webService.prototype.SoapCall = function() {
xmlHttp =
new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open(
"post", this.urlWebService, true);
xmlHttp.setRequestHeader(
"Content-Type", "text/xml; charset=utf-8");
xmlHttp.setRequestHeader(
"SOAPAction", http://www.namespace.com.br/TRANSFER_SetData);
xmlHttp.onreadystatechange =
this.doUpdate;
xmlHttp.send(
this.soapRequest);
return false;
};

webService.prototype.doUpdate = function() {
//debugger;
if (xmlHttp.readyState == 4) {
var responseXMLResult = xmlHttp.responseXML;
this.token = responseXMLResult.lastChild.nodeTypedValue;
resposta.innerText =
this.token;
}
};

var ws = new webService();
ws.SoapCall();