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 147 forks source link

Unable to support attributes and complex parameter types in SOAP request #14

Closed programmer117 closed 11 years ago

programmer117 commented 11 years ago

In the SOAP demo, the following SOAP request is generated:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><test>some text here...</test></soap:Body></soap:Envelope>

And in the demo, the params is literally defined as <test>some text here...</test>

However, I want to do something a little more complicated. This is the SOAP request that I want to automatically generate:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><a1:myMethod xmlns:a1="http://www.mySpecialNamespace.org/"><number>0</number><color xsi:type="a1:pastel">lavender</color><horizon xsi:type="a1:blues"><ocean>aquamarine</ocean><sky>turqoise</sky></horizon></a1:myMethod></soap:Body></soap:Envelope>

I think I could accomplish this if I made a lot of significant changes to the jquery.soap.js file, but it'd be much better if you could update the baseline of the code to include this functionality, or show me how I can already do this and call $.soap to accomplish this specific SOAP request, because I want to be able to easily update my code whenever the latest version of the jquery.soap.js file comes out.

Thank you so much in advance for your help!!

Thanks, programmer117

doedje commented 11 years ago

I agree that jquery.soap is missing a feature to include extra namespaces to the soap:Envelope. I've included this in the milestone 2.0.0 feature list. It will probably be called something like `envNamespaces' and look like:

envNamespaces: {
  xsi: 'http://www.w3.org/2001/XMLSchema-instance',
  another: 'http://anotherNamespace.com/'
}

I am in doubt weither jquery.soap should support the automatic generating of more complex XML as in your case.

Your XML:

<a1:myMethod xmlns:a1="http://www.mySpecialNamespace.org/">
  <number>0</number>
  <color xsi:type="a1:pastel">lavender</color>
  <horizon xsi:type="a1:blues">
    <ocean>aquamarine</ocean>
    <sky>turqoise</sky>
  </horizon>
</a1:myMethod>

JSON:

{
  myMethod: {
    number: 0,
    color: 'lavender', // how to include attributes here??
    horizon: { // and here?
      ocean: 'aquamarine',
      sky: 'turqoise'
    }
  }
}

maybe something like

color: {
  attributes: {
    'xsi:type': 'a1:pastel'
  },
  nodeValue: 'lavender'
}

Too bad xsi:type is not allowed due to the :. Something to find a workaround for... So this is something to be discussed and think thru. So for the time being:

programmer117 commented 11 years ago

Ah ok. So for now, since what I'm doing is a unique deviation from how jquery.soap is currently implemented, I should just specify my params as an XML string for the SOAP request exacly as I want it. At least I have started a discussion on this! I agree that it would be best if attributes could be specified in the params json!

And it's good to know that you've already been considering adding extra namespaces to the soap:Envelope!

Thank you for your help doedje! I really like this jquery.soap.js plugin!

Thanks, programmer117

doedje commented 11 years ago

Summerbreak is over... Time to recap...

As I think about it now it seems a bit silly to include code to be able to use JSON to create a XML structure that is beyond the capabilities of standard JSON, considering the fact that such a markup does already exist in the form of XML which is also supported by the plugin. So the case is this: for simple parameters you can use JSON, XML string of XML Object, whatever suits you best. For the more complex things, you'll have to use XML (and at the same time gain the advantage of ruling out any parse errors....)

I just think this makes much more sense...

anthony-redFox commented 11 years ago

Hello all, I propose remove support convector json to xml. You can convert json to xml using third party library and send soap request. For Example: http://goessner.net/download/prj/jsonxml/ https://code.google.com/p/x2js/

doedje commented 11 years ago

I added the additional namespace request to the TODO list. I'll close this issue just to keep a clean issues list..Thanx