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

Support for Bare parameter style #125

Closed Melnorme1984 closed 6 years ago

Melnorme1984 commented 6 years ago

I'd like to use your script with a server that uses the Bare parameter style. That means the parameter is the only element inside the request XML body, instead of being under a root element with the same name as the SoapAction. The only way to do this now seems be to write the entire request envelope myself using the data option...

doedje commented 6 years ago

I did some reading about BARE vs WRAPPED parameters but as far as I understand the actual soap requests are exactly the same....

Melnorme1984 commented 6 years ago

They're not. I described the difference in my original post. This is how I have to do it now:

var xml = ['<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">',
            '<S:Body>',
            '<ns2:baseNetworkName xmlns:ns2="network">',
            network + ".net",
            '</ns2:baseNetworkName>',
            '</S:Body>',
            '</S:Envelope>'];

$.soap({
            "url": anatURL,
            "SOAPAction": '"getXref"',
            "data": xml.join("")

            "success": function (soapResponse) {
                ...
            }
        });

There's no container XML element inside the Body that contains the parameter element. The parameter element itself (baseNetworkName) is the container.

doedje commented 6 years ago

It should be enough to do just (without the repeating the Envelope and Body tag all the time):

$.soap({
            "url": anatURL,
            "SOAPAction": '"getXref"',
            "data": '<ns2:baseNetworkName xmlns:ns2="network">' + network + ".net" + '</ns2:baseNetworkName>'

            "success": function (soapResponse) {
                ...
            }
        });

that is about as bare as I can make it... ;)

Melnorme1984 commented 6 years ago

Well that's better, but it would be nice if there was native support that allowed you to use method, namespaceQualifier and so on.

doedje commented 6 years ago

I'll look into that, are you planning to do requests with multiple parameters?

doedje commented 6 years ago

I currentlty have made a change to the script that allows to do this:

$.soap({
  url: anatURL,
  method: "baseNetworkName",
  SOAPAction: "getXref",
  data: "test.net",
  namespaceQualifier: "ns2",
  namespaceURL: "network",

  success: function(soapResponse) {
    ...
  }
});

Which results in this SOAP Request being send:

<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>
    <ns2:baseNetworkName xmlns:ns2="network">test.net</ns2:baseNetworkName>
  </soap:Body>
</soap:Envelope>

But as soon as you might want to send more than one parameter, this is not going to help you.

Melnorme1984 commented 6 years ago

Great, thanks. It's not possible to have more than one parameter with this method. That's sort of the point!

That said it would be nicer if there was an additional option to explicitly select the desired parameter style, so that you could use getXref as the method rather than baseNetworkName. I take it what you're planning is for the code to implicitly recognize that you want Bare parameter style if you have just one parameter and SOAPAction differs from method.

doedje commented 6 years ago

Normal behavior for the script is like this:

method is:

(from https://github.com/doedje/jquery.soap/blob/master/doc/options.md#method)

The code does implicitly recognize the bare parameter style when the data is a string but does not contain a < aka is not an XML String.

The SOAPRequest from my previous post could also be created with this call:

$.soap({
  url: anatURL,
  method: "getXref",
  namespaceQualifier: "ns2",
  namespaceURL: "network",
  elementName: "baseNetworkName",
  data: "test.net"
});

Download the 1.7.2 version of $.soap and you're of to the races....