HomeDigital EditionSys-Con RadioSearch Web Services Cd
B2B Beginning WS Business Process Management Case Studies Content Management Distributing Computing e-Business Electronic Data Interchange Enterprise Industry Insight Integration Interviews Java & Web Services .NET Portal Product Reviews Scalability & Performance Security SOAP Source Code UDDI Wireless WS Standards WS Tips & Techniques WSDL WS Editorials XML

Web Services Made Easy with Ruby by Aravilli Srinivasa Rao
WSJ Vol 03 Issue 08 - pg.36



Listing 1:  SendEmail.rb

# SendEmail.rb
# Email Client
require 'soap/driver'

NAMESPACE 	= 'http://www.abysal.com/Abysal-webDTP'
URL 		= 'http://www.abysal.com/soap/abysal_webdtp'
SOAPACTION	= 'http://www.abysal.com/soap#abysal_program=soapmail'
HTTP_PROXY	=  nil

#create a SOAP Driver Object
driver =SOAP::Driver.new(nil, nil, NAMESPACE, URL, HTTP_PROXY, SOAPACTION)

# Add the SOAP Method "SendEmail" that takes 8 arguments
# From, FromAddress, To, ToAddress, Subject, MsgBody, Acknowledgement, Priority

driver.addMethod('SendEmail','From','FromAddress', To', 'ToAddress', 'Subject',
'MsgBody', 'Acknowledgement', 'Priority' )

# call the SOAP Service

result = driver.SendEmail( 'srinivas','aravilli@yahoo.com', 'Gail Schultz',
'gail@sys-con.com','SOAP programming using Ruby',
'Ruby SOAP Client and testing the email web service Listed in Xmethods',
'1', '1' )

Listing 2: ConversionServer.rb

# ConversionServer.rb
# Temperature conversion services from  Celsius to Fahrenheit

require "soap/standaloneServer"

class Temparature_Conversion_Server  < SOAP::StandaloneServer

def methodDef
     		  addMethod(self, 'convert_to_Fahrenheit', 'degrees' )
end

def convert_to_Fahrenheit( degrees )
		temp = (9*degrees + 160)/5
		 return temp
end

end  #class end

server   =  Temperature_Conversion_Server.new('ConversionServer',
'urn:ruby:conversionservice', 'localhost',8080)

puts    "Now SOAP Server is starting"

server.start

Listing 3:  ConversionClient.rb

# ConversionClient.rb
# Temperature conversion client
require "soap/driver"

driver   =  SOAP::Driver.new(nil,nil,'urn:ruby:conversion	service,'http://localhost:8080/')

driver.addMethod('convert_to_Fahrenheit','degrees')

puts driver.convert_to_Fahrenheit(27.3)