Domanda

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>

Nessuna soluzione corretta

Altri suggerimenti

You should enable the ajax in your soap service uncomment [System.Web.Script.Services.ScriptService] in your soap.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top