尝试使用jQuery调用SOAP服务时,在浏览器控制台中显示500个内部服务器错误,但是当我使用SOAP UI调用具有相同有效负载的相同服务时,效果很好。
从服务器返回以下XML错误响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Error reading XMLStreamReader.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
使用下面的jQuery代码来调用SOAP服务: `
$(document).ready(function () {
var soapMessage =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.wss.phoenix.com/">\
<soapenv:Header/>\
<soapenv:Body>\
<ser:getConsumerDetails>\
<SCNO>VN02095028440</SCNO>\
<ACCOUNTNO/>\
<DISCOMCODE/>\
<REQUESTFOR>SCNOACCDETAILS</REQUESTFOR>\
</ser:getConsumerDetails>\
</soapenv:Body>\
</soapenv:Envelope>';
$.ajax({
url: "http://IP:PORT/wss/services/ConsumerDiscomDetails?wsdl",
type: "POST",
dataType: "xml",
contentType: "text/xml; charset=\"utf-8\"",
crossDomain:true,
headers: {
SOAPAction: ""
},
data: soapMessage,
success: function(soapResponse){
console.log("soapResponse");
//DO SOMETHING
}
});
});
`