Murthy's blog

pageicon Monday Jul 02, 2007

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.

Comments:

its cool..good to see that webservice is very easy to implement with Ruby support. NICE ONE!!!!

Posted by Manidhar Puttagunta on July 17, 2007 at 02:42 AM IST #

Yeah it is proven that ruby is making scripting sensation...

Posted by Narayana on August 04, 2007 at 11:09 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

« September 2008
SunMonTueWedThuFriSat
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today

Feeds

Search this blog

Links

Weblog menu

Today's referrers

Today's Page Hits: 2