You should enable the ajax in your soap service
uncomment [System.Web.Script.Services.ScriptService]
in your soap.
jquery ajax SOAP service failing to get response
-
05-06-2023 - |
Question
I'm hoping someone can shed some light on this. I'm new to using SOAP services and struggling to see why I cannot get a response within my ajax call.
The request and response work perfectly in SOAPui, just not in ajax in browser. I'm also unsure how to check response valid is true.
Additionally, its worth pointing out that if I change
contentType: "application/soap+xml; charset=utf-8", to contentType: "text/xml",
it always gives an error.
SOAP RESPONSE
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<vcr:ValidResponse xmlns:vcr="http://url/central-register">
<vcr:valid>true</vcr:valid>
</vcr:ValidResponse>
</soapenv:Body>
</soapenv:Envelope>
AJAX
<script type="text/javascript">
var soapMessage = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cen="http://url/central-register">'+
'<soap:Header/>'+
'<soap:Body>'+
'<cen:ValidRequest>'+
'<cen:personIdentity>'+
'<cen:Id>32342</cen:Id>'+
'<cen:surname>SMITH</cen:surname>'+
'<cen:dateOfBirth>1943-02-14</cen:dateOfBirth>'+
'</cen:personIdentity>'+
'<cen:Credentials>'+
'<cen:Username>CGWSV02</cen:Username>'+
'<cen:Password>February2014</cen:Password>'+
'</cen:Credentials>'+
'</cen:ValidRequest>'+
'</soap:Body>'+
'</soap:Envelope>';
function CallService()
{
$.ajax({
url: "https://www.url-to-soap-service/",
type: "POST",
dataType: "xml",
contentType: "application/soap+xml; charset=utf-8",
data: soapMessage,
success: OnSuccess,
error: OnError
});
return false;
}
function OnSuccess(data, status)
{
alert(data);
}
function OnError(request, status, error)
{
alert('error');
}
$(document).ready(function() {
jQuery.support.cors = true;
});
</script>
<form method="post" action="">
<input type="submit" value="SUBMIT" onclick="CallService(); return false;" />
</form>
No correct solution
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow