doedje / jquery.soap

This script uses $.ajax to send a SOAP:Envelope. It can take XML DOM, XML string or JSON as input and the response can be returned as either XML DOM, XML string or JSON too.
352 stars 148 forks source link

my soap method doesnt work #121

Closed ssantana closed 6 years ago

ssantana commented 6 years ago

Hi... Im trying to use jquery.soap to read my webservice but doesnt work. Please, could you verify whats wrong. My code is:

            var xml =
                ['<soap:Envelope  xmlns:soap="http://www.w3.org/2003/05/soap-envelope/">',
                    '<soap:Body>',
                        '<vrLogin>testenos</vrLogin>',
                        '<vrSenha>12345</vrSenha>',
                    '</soap:Body>',
                '</soap:Envelope>'];
            var ajaxReturn = $.soap({
                url: 'http://www.nosnaescola.com/NOSNAESCOLA_WEB/awws/Nosnaescola.awws',
                method: 'ws_valida_login',
                appendMethodToURL: false,
                SOAPAction: 'urn:Nosnaescola/ws_valida_login',
                withCredentials: false,
                data: xml.join(''),
                success: function (SOAPResponse) {
                    // do stuff with soapResponse
                    // if you want to have the response as JSON use soapResponse.toJSON();
                    // or soapResponse.toString() to get XML string
                    // or soapResponse.toXML() to get XML DOM
                    alert('sucesso');
                },
                error: function (SOAPResponse) {
                    // show error
                    alert('erro'+SOAPResponse.toXML());
                }
            });
AlexCln commented 6 years ago

What is your Error output ?

doedje commented 6 years ago

I guess your XML is not correct.... I miss some kind of ........request node in there..... Try replacing the data with:

data: {
  vrLogin: "testenos",
  vrSenha: "12345"
}

This way $.soap will take care of creating the right soapRequest for you.... Let me know your progress....

marcoins commented 6 years ago

I also have an implementation question, using this plugin my soap request looks like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <ws:PerfilUsuario xmlns:ws="http://ws.groove.com">
      <ws:iduser>1</ws:iduser>
      <ws:token>cG35P5zjk9U/aPv0+CplUw==</ws:token>
    </ws:PerfilUsuario>
  </soap:Body>
</soap:Envelope>

And what I need is to make that request looks like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.groove.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:PerfilUsuario>
         <iduser>1</iduser>
         <!--Optional:-->
         <token>cG35P5zjk9U/aPv0+CplUw==</token>
      </ws:PerfilUsuario>
   </soapenv:Body>
</soapenv:Envelope>

Any help?, Thanks in andvance. Greetings from Colombia

Update: Changing the tags from <soap> to <soapenv> works on SoapUI, how can I change them on the plugin?

doedje commented 6 years ago

I also miss a namespace specification in your example:

$.soap({
  url: "proxyPlus.php?url=http://www.nosnaescola.com/NOSNAESCOLA_WEB/awws/Nosnaescola.awws",
  method: "ws_valida_login",
  appendMethodToURL: false,
  SOAPAction: "urn:Nosnaescola/ws_valida_login",
  withCredentials: false,
  data: {
    vrLogin: "testenos",
    vrSenha: "12345"
  },
  namespaceQualifier: "ws", 
  namespaceURL: "url_to_namespace_declaration",
  enableLogging: true
});

creates an xml like:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <ws:ws_valida_login xmlns:ws="url_to_namespace_declaration">
      <ws:vrLogin>testenos</ws:vrLogin>
      <ws:vrSenha>12345</ws:vrSenha>
    </ws:ws_valida_login>
  </soap:Body>
</soap:Envelope>

If your server does not like the ws: namespace-prefix, you can also add noPrefix: true in the soap-call