Java Reference
In-Depth Information
Converter.add_method_with_soapaction(
"ConversionRate",
"http://www.webserviceX.net/ConversionRate",
"FromCurrency", "ToCurrency")
#send the SOAP messages to the console
Converter.wiredump_dev = STDERR
#call the operation and print result
puts Converter.ConversionRate("USD","CAD")
If you examine the WSDL for this service, you'll see that it accepts two strings indicating the
currencies to convert from and to. I won't show the entire SOAP messages, but the headers
are interesting:
POST /CurrencyConvertor.asmx HTTP/1.1
Accept: */*
Content-Type: text/xml; charset=utf-8
User-Agent: SOAP4R/1.5.5
Soapaction: \"http://www.webserviceX.NET/ConversionRate\"
Content-Length: 432
Host: www.webservicex.net
You can see here that the SOAP4R library is doing the heavy lifting for you, and it identifies
itself in the request as the user agent. This library is an implementation of SOAP 1.1 for Ruby.
Using Ruby in Eclipse
You can use Ruby from within Eclipse for a somewhat easier time of working with projects.
To do so, get the Ruby plug-in from http://rubyeclipse.sourceforge.net/ . Then you just need to
point to the Ruby interpreter executable so that Eclipse can use the version you want to run
your code. This is very similar to setting up multiple JDKs in Eclipse, so I won't dwell on the
details.
If you create a new project, choose the Ruby Project type. If this is your first one, you'll have
an error indicating that you need to tell Eclipse where to find Ruby; can remedy this by point-
ing to the ruby.exefile that is included with the download. You should see Eclipse add a num-
ber of libraries to its list when you add this file to the wizard, and you should be all set.
Now add a source folder. I'll call mine src. Eclipse should open the Ruby Perspective to assist
you. Type a “Hello, world” program to make sure you're set up. In your source folder, create
a file called Hello.rb. Then add the following code to it, which is a slightly more exciting an
example of Hello World than you used earlier:
Search WWH ::




Custom Search