I’m getting really tired of this:
SOAP – used to stand for Simple Object Access Protocol. Apparently it does’t any more but who cares?
In essence, create a complex object, marshal it into XML and send it down the wire.
This means you can do stuff like:
myObject = SoapObject.new myObject.person = “James Smitt” myObject.addresses = “1313 Luck Street” myObject.addresses = “667 Beastie Neighbour” myObject.employer = “Big Bang Burger Corp.”
Then, you can send it down the wire. The receiver of the object has everything nicely laid out for them and they can interrogate the object to get the fields back etc. All done for you by the SOAP framework. This is really easy. You just generate the object wrapper from the WSDL, and this is why there are version numbers in WSDL so you get the right object back.
Oh no, virtually every person I’ve had to deal with recently uses SOAP to send an XML string.
Why is this a bad idea?
First, the string has to be escaped so it won’t mess up the SOAP message.
Second, it has to be parsed at the remote end, which may not work because some dimwit put an ampersand somewhere (it’s data – they’re everywhere).
Third, you have to think about the XML object, maybe use stuff like XPath.
Fourth, while you can return an object (if you are the server) that has useful stuff like error messages or resultant ID’s in it, you probably won’t – just another XML document that again has to be parsed and so on.
This drives me nuts, it’s a lot more work to use, it is’t an API. If you want to send XML just use an HTTP post … why complicate it??
1. Create a complex object that wraps your data requirements, it can be hierachical, have arrays of things in, all sorts.
2. Fire your IDE of choice at this object and generate the WSDL
3. Use the technology like it was supposed to be used.
XML is witless and difficult to use on its own, as a means of marshalling complex objects it’s fine – but get the framework to do it; it’s been debugged and worked with by thousands of people.
Effectively, rolling your own XML description is reinventing the wheel every time. Let the framework do it.
It’s also easier to test your complex object and put validation in around values of fields, rather than trying to parse an incomplete XML document and just throwing some meaningless exception.