Soap Server in Ruby with Wsdl

How do I use WSDL and implement a SOAP server in Ruby?

I don't have an answer for you, but it sounds like you need a code generator like wsdl2ruby available in the SOAP4R gem.

Here is a recent fork/update to SOAP4R: https://github.com/mumboe/soap4r

And there are a couple of examples of using SOAP4R to generate web service clients:

http://www.winstonyw.com/2008/09/02/howto-use-ruby-soap4r/

http://mrfrosti.com/tag/wsdl2ruby/

I haven't easily found any examples of generating server-side code, but wsdl2ruby seems to have a switch to perform that function.

Good luck.

Is it possible to generate a Ruby SOAP web service from a WSDL file?

I created my own mocking framework based on Savon, Sinatra and Mocha. It's available at https://github.com/kieranmaine/soap_mocker.

The usage is as follows. Instantiate the mock service by passing in the WSDL url, specifying the service and port (within the WSDL) to use and also the path and port to run the mock service under:

service = SoapMocker::MockServiceContainer.new 
"http://www.webservicex.net/uklocation.asmx?WSDL",
"UKLocation",
"UKLocationSoap",
"/mock/UkLocationSoapService",
{:port => 1066}

This will setup the mock service on the following URL:

http://localhost:1066/mock/UKLocationSoapService.

You then need to set up the mock responses:

# Set up responses for valid requests
service.mock_operation "GetUKLocationByPostCode",
{:GetUKLocationByPostCode => {:PostCode => "SW1A 0AA"}},
{:GetUKLocationByPostCodeResponse => {:GetUKLocationByPostCodeResult => "House Of Commons, London, SW1A 0AA, United Kingdom"}}

# Example of accessing mock object directly.
service.io_mock.stubs(:call_op)
.with("GetUKLocationByPostCode", regexp_matches(/AL1 4JW/))
.returns({:GetUKLocationByPostCodeResponse => {:GetUKLocationByPostCodeResult => "TESTING"}})

And finally start up the mock web service:

service.run

What's the best way to use SOAP with Ruby?

We used the built in soap/wsdlDriver class, which is actually SOAP4R.
It's dog slow, but really simple. The SOAP4R that you get from gems/etc is just an updated version of the same thing.

Example code:

require 'soap/wsdlDriver'

client = SOAP::WSDLDriverFactory.new( 'http://example.com/service.wsdl' ).create_rpc_driver
result = client.doStuff();

That's about it

consume soap service with ruby and savon

This is a problem with the way Savon handles Namespaces. See this answer Why is "wsdl" namespace interjected into action name when using savon for ruby soap communication?

You can resolve this by specifically calling soap.input and passing it an array, the first element is the method and the second is a hash containing the namespace(s)

require 'rubygems'
require 'savon'

client = Savon::Client.new "http://www.webservicex.net/stockquote.asmx?WSDL"
client.get_quote do |soap|
soap.input = [
"GetQuote",
{ "xmlns" => "http://www.webserviceX.NET/" }
]
soap.body = {:symbol => "AAPL"}
end


Related Topics



Leave a reply



Submit