Murthy's blog
Webservices made simple using Ruby
Was fortunate to take a look at Ruby Scripting language, got this chance while looking into Scripting Service Engine (One stop solution to run any script file in Open-ESB though it is in it's early stages we kind of tried to achieve JSR223 support in Open-ESB space. Of course lot of effort is going in that area )
As a hard core fan of webservice could not stop myself to see how ruby supports webservices implementation. After struggling for sometime could implement a server and client application.
First let's see how to write a server implementation,
First we require soap library how do we load it...
require 'soap/rpc/standaloneServer'
Now define a class
class StockQuoteServer < SOAP::RPC::StandaloneServer
Add the method which you would like to implement
add_method(self,'getStockQuote','from')
What that method can consists...
def getStockQuote(from)
puts "getStockQuote Service Called....."
if from.eql?("SUNW")
price = 4.92
return price
end
end
You know what, we are done with Server implementation and now the question is how do you expose the service?
Here is the
answer
server = StockQuoteServer.new('hws','urn:hws','0.0.0.0',Port)
server.start
is it fair enough?
Oh
boy we are done with creating a webservice. Now you will ask me how do you invoke it? It
is even simple, can't believe it?
First bind the client to the endpoint exposed
@endpoint = "http://localhost:#{Port}/"
@client = SOAP::RPC::Driver.new(@endpoint, 'urn:hws')
@client.add_method("getStockQuote","from")
Invoke the client
@client.getStockQuote(index)
that's it and we are done now. So how do you feel about it, do you think it is fairly simple or you have a different feeling (I don't think so)
Find
server and client applications.
Posted at 06:19PM Jul 02, 2007 by pedapudinarayana in Personal | Comments[2]
Monday Jul 02, 2007
Posted by Manidhar Puttagunta on July 17, 2007 at 02:42 AM IST #
Posted by Narayana on August 04, 2007 at 11:09 AM IST #