wsdl2js
Overview
wsdl2js is a Python script that generates JavaScript code to wrap an API defined in a
WSDL. The generated JavaScript
uses SOAP objects that are only available to trusted JavaScript in Mozilla or Firefox.
I have used wsdl2js to access the Google Web Search API in JavaScript as a proof of concept.
History
wsdl2js was originally developed as a subproject of
Google Dominoes,
one of my first Firefox extensions.
I wanted to have programmatic access to the Google Search API from Firefox, so
generating the appropriate JavaScript to access the API defined in
GoogleSearch.wsdl seemed like a good solution.
When I surfed the net looking for an existing wsdl2js converter, I ran into a bunch of dead ends.
There were a number of articles that showed how to use SOAP from Mozilla, and many used
Google's
Search API as an example, but no one had produced the JavaScript to support the complete API.
My guess was that no one did this because it was too tedious -- the objects used in the APIs have
a many fields, and it is not much fun to write the code that extracts them from the SOAP XML.
I decided that the best solution was to write a script to produce the JavaScript from the WSDL
automatically. (Analogous tools already existed for Java and .NET.)
Files
wsdl2js.py, version 0.9
is the Python script that I wrote to generate
the JavaScript code to access the API defined in a WSDL. It has only been tested with
GoogleSearch.wsdl.
GoogleSearch.js
is the JavaScript generated by wsdl2js, along with some additional wrapper code that I added
to make the API a bit easier to use. Note that you will have to obtain a license key from
http://www.google.com/apis/ before you
can use this API.
Usage
To produce the JavaScript from the WSDL, specify the WSDL file with -f
and the output file with -o
.
python wsdl2js.py -f GoogleSearch.wsdl -o GoogleSearch.js
To experiment with GoogleSearch.js, I recommend using
Chickenfoot. Once you have your
Google license key, paste the
code into the Chickenfoot editor, override the getGoogleLicenseKey()
function,
and then add the following line of code:
getGoogleSpellingSuggestion("aple")
If you see apple
appear in Chickenfoot's Output pane, then you know that it's working!
Notes
If I haven't already made this abundantly clear, I have no idea whether wsdl2js will work on any WSDLs
besides Google's. In fact, I would be pretty surprised if it did because I know that the wsdl2java
codebase is rather large, so I doubt that my 500 lines of badly-written Python handle all of the
intricacies of WSDL, of which I know very little about, honestly. If I were to trying to produce
a comprehensive solution to the wsdl2js problem, I would probably write something that uses wsdl2java
and then translates the generated Java code to JavaScript.
An interesting postscript to this story...
Sadly, no one ever really ended up using Google Dominoes.
I had originally planned to incorporate
Ryan Jazayeri's work on Google URLs,
but I never got around to it. I remember that over a year after creating Dominoes, I got an email from
someone saying that they had installed it, and that it was "a jaw-dropping idea + implementation."
This was quite a compliment, but it also made me laugh, reminding me of the following quote:
"The makers of Bowflex have been ordered to pay a $1 million penalty because some people were injured
while using the machine.
The company was shocked, and said, "You mean, somebody actually used their
Bowflex?!" - Conan O'Brien
© 2004-2005 Michael Bolin