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

Namespace #126

Closed merco closed 5 years ago

merco commented 6 years ago

Using jquerysoap i can make this request:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <ns1:doLogin xmlns:ns1="http://packlistphoto.sygest.it">
      <ns1:DataDevice_ggmmaaaa>01012017</ns1:DataDevice_ggmmaaaa>
      <ns1:UserID>2035</ns1:UserID>
      <ns1:UserPWD>123321</ns1:UserPWD>
      <ns1:outXML></ns1:outXML>
      <ns1:eo></ns1:eo>
      <ns1:clientDaAggiornare></ns1:clientDaAggiornare>
    </ns1:doLogin>
  </soap:Body>
</soap:Envelope>

but it is not working.

How can i make this working request ?

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://packlistphoto.sygest.it/">
  <SOAP-ENV:Body>
    <ns1:doLogin>
      <ns1:DataDevice_ggmmaaaa>01012017</ns1:DataDevice_ggmmaaaa>
      <ns1:UserID>2035</ns1:UserID>
      <ns1:UserPWD>123321</ns1:UserPWD>
      <ns1:outXML></ns1:outXML>
      <ns1:eo></ns1:eo>
      <ns1:clientDaAggiornare></ns1:clientDaAggiornare>
    </ns1:doLogin>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
doedje commented 6 years ago

(I did put the soap in your message in code-blocks to improve readability.)

Since you did not put your $.soap call in your post, I am only guessing here. The only difference I see that could be a problem is the ns1 namespace declaration is in your Envelope node instead in the doLogin node. (the fact your namespace for the soap envelope is SOAP-ENV instead of $.soap's soap should not be a problem)

$.soap({
  url: "xml/fake-soap-response.xml?",
  method: "doLogin",
  envAttributes: {
    'xmlns:ns1': 'http://packlistphoto.sygest.it/'
  },
  data: { 
    DataDevice: '01012017',
    userID: 2035,
    UserPWD: '123321',
    outXML: '',
    eo: '',
    clientDaAggiornare: ''
  },
  namespaceQualifier: "ns1",
  enableLogging: true
});

Results in the following XML:

<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" xmlns:ns1="http://packlistphoto.sygest.it/">
  <soap:Body>
    <ns1:doLogin>
      <ns1:DataDevice>01012017</ns1:DataDevice>
      <ns1:userID>2035</ns1:userID>
      <ns1:UserPWD>123321</ns1:UserPWD>
      <ns1:outXML>
      </ns1:outXML>
      <ns1:eo>
      </ns1:eo>
      <ns1:clientDaAggiornare>
      </ns1:clientDaAggiornare>
    </ns1:doLogin>
  </soap:Body>
</soap:Envelope>

My guess is this should be okay..... Let me know!

kiwipetedev commented 6 years ago

I need to pass the following SOAP message to my web service:

<soapenv:Envelope
    xmlns:ns1="http://nz.co.budgetmanager.jaxws/"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <ns1:login>
            <user-id>aaa</user-id>
            <password>aaa</password>
        </ns1:login>
    </soapenv:Body>
</soapenv:Envelope>

In order to do this, I have to make the following call:

$.soap(
{
    url: "http://localhost:8080/bm-ws/budgetmanager?wsdl/",
    method: 'ns1:login',
    envAttributes:
    {
        "xmlns:ns1": "http://nz.co.budgetmanager.jaxws/"
    },
    data:
    {
        "user-id": $scope.username,
        "password": $scope.password
    },
    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
    },
    error: function (SOAPResponse) {
        // show error
    }
});

I tried setting the namespaceQualifier property to "ns1", but that put "ns1" in the name of the user-id and password attributes, which caused null values to be passed to my web service.

markusmo commented 5 years ago

it might seem strange... but i needed to do the same. so I used the same logic you did, and it worked... thanks