Me gustaría llamar a un SOAP WebService directamente desde Javascript. He estado buscando por todos lados, pero todavía no puedo tener algo funcionando. Supuse que debía construir el enveloppe SOAP (ver a continuación). También uso jQuery.Cómo llamar a SOAP WS desde Javascript/jQuery
En primer lugar, ¿me aseguraría de poder llamar a un servicio web SOAP ubicado en otro lugar? es decir, no hay ninguna limitación, como la limitación de dominio cruzado.
Además, no estoy seguro de cuál es la URL correcta que necesito usar, el servicio SOAP se expone usando Ladon, para fines de depuración he comprobado que la WS funciona bien con soapUI, y aquí están las URL que puedo encontrar:
- URL WSDL: //
http://192.168.1.5/ws/MyWS/soap/description
de mi comprensión no puede ser éste - servicio criterios de valoración:
http://192.168.1.5/ws/MyWS/soap
- SOAPAction:
http://192.168.1.5/ws/MyWS/soap/myOperation
Creo que debería usar punto final o SOAPAction pero no funcionó. Puedo perder algo aquí o el Javascript posterior es tan defectuoso que no puedo estar seguro.
Ahora aquí es mi real JS hacer la llamada (hay algunas preguntas dentro de los comentarios):
<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<head>
<script type="text/javascript" src="ressources/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
// inspired by http://openlandscape.net/2009/09/25/call-soap-xm-web-services-with-jquery-ajax/
var soapServiceURL = 'http://192.168.1.5/ws/MyWS/soap/myOperation; // not sure what to put here from a LADON point of view
function callSOAPWS(myParameter)
{
var soapMessage =
'<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:LDetector"> \
<soapenv:Header/> \
<soapenv:Body> \
<urn:myOperation soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> \
<myParameter xsi:type="xsd:string">' + myParameter + '</myParameter > \
</urn:myOperation > \
</soapenv:Body> \
</soapenv:Envelope>';
alert("Check SOAP: [" + soapMessage + "]");
jQuery.ajax({
url: soapServiceURL,
type: "POST",
dataType: "xml",
data: soapMessage,
contentType: "text/xml; charset=\"utf-8\"",
//processData: false, // what is it for? may be should be true when using 'complete:' ?
//timeout: 5000,
// below I first try to have only 'complete:' then I tried to have 'success:' + 'error:', then the 3. Nothing seems to be ok. I do not find which one i should use.
complete: myCallback,
success: function(response){
document.getElementById('debug').innerHTML = document.getElementById('debug').innerHTML + '\n' + 'success!' + '\n';
alert("success!!!");
},
error: function(XMLHttpRequest,textStatus, errorThrown){
document.getElementById('debug').innerHTML = document.getElementById('debug').innerHTML + '\n' + 'error : ' + textStatus + '\n';
alert("error : " + textStatus);
}
});
alert('if we reach this line, is it a fail?!');
return false;
}
function myCallback(xmlHttpRequest, status)
{
jQuery(xmlHttpRequest.responseXML)
.find('detected')
.each(function()
{
var result = jQuery(this).find('result').text();
document.getElementById('debug').innerHTML = document.getElementById('debug').innerHTML + '\n' + result + '\n';
alert('ok : [' + result + ']');
});
}
// https://stackoverflow.com/questions/11916780/changing-getjson-to-jsonp?rq=1
jQuery(document).ready(function() {
callSOAPWS('this is a test');
});
</script>
<body>
<div id="debug" style="background-color:#EEEEEE; height:250px; width:600px; overflow:auto;"> </div>
</body>
</html>
mejores deseos
EDIT: sin dejar de tratar de buscar una respuesta, tengo reveló que =>Simplest SOAP example donde Prestaul dice "Esto no se puede hacer con JavaScript directo a menos que el servicio web esté en el mismo dominio que su página". Entonces, ¿tal vez estoy tratando de hacer algo imposible? ¿Es esta la razón por la que no puede funcionar?
gracias, así que era un error pensar que el uso de jabón con un cliente completo JS era un trabajo alrededor. Y sí, he probado el código que puse arriba, funciona cuando se usa desde el mismo servidor. Por cierto, también necesitaré que otros servidores puedan hacerlo ... voy a echar un vistazo a la forma en que sugieres. – user1340802