Java Reference
In-Depth Information
Creating a Ruby Client for a .NET Service
Problem
You have a web service written in .NET that you want to consume from a Ruby application.
Solution
Require the
soap/rpc/driver
library, and then use the
SOAP::RPC::Driver
class to referen-
ce the WSDL and the
SOAP::EncodingStyle::ASPDotNetHandler
class to invoke the ser-
vice.
Discussion
First, make sure that Ruby is installed. You can download the latest version available at
http://www.ruby-lang.org/en/downloads/
.
On Windows, you can download the “one-click in-
staller,” which includes a number of additional libraries and is the easiest way to get started.
The installer will install a program called ScITE, which is a lightweight code assistant/high-
lighter. To test your installation, create a new file in Notepad or ScITE, with the following
text:
puts "Hello, World"
Save the file as Hello.rb. Now open a console and type
ruby Hello.rb
to run your program
in the interpreter, and you should see the venerable output. Now you'll use Ruby to create
a SOAP client at
http://www.WebServiceX.net
.
The service itself, shown in
Example 12-14
,
simply converts the monetary exchange rates between two countries.
Example12-14.Ruby client for .NET currency conversion service
require 'soap/rpc/driver'
#create a connection to the service
Converter = SOAP::RPC::Driver.new(
"http://www.webservicex.net/CurrencyConvertor.asmx",
"http://www.webserviceX.net/")
#set the encoding style
Converter.default_encodingstyle =
SOAP::EncodingStyle::ASPDotNetHandler::Namespace
#add the SOAP Action HTTP header