Ruby/Network/SOAP
Материал из Wiki.crossplatform.ru
Using a WSDL File to Make SOAP Calls Easier
require "soap/wsdlDriver" wsdl = "http://yourserver.net/quotes.wsdl" driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver puts "Stock price: %.2f" % driver.getQuote("TR")
Writing a SOAP Client
require "soap/rpc/driver" driver = SOAP::RPC::Driver.new( "http://webservices.codingtheweb.ru/bin/qotd", "urn:xmethods-qotd") driver.add_method("getQuote") puts driver.getQuote
Writing a SOAP Server
require "soap/rpc/standaloneServer" class MyServer < SOAP::RPC::StandaloneServer def initialize(*args) super add_method(self, "sayhelloto", "username") end def sayhelloto(username) "Hello, #{username}." end end server = MyServer.new("CoolServer","urn:mySoapServer","localhost",8888) trap("INT") { server.shutdown } server.start # Call your service require "soap/rpc/driver" driver = SOAP::RPC::Driver.new("http://localhost:8888/", "urn:mySoapServer") driver.add_method("sayhelloto", "username") driver.sayhelloto("aaa")