How to Generate a Wsdl Using Ruby

How do I generate a WSDL using Ruby?

ActionWebService (previously in Rails core, now a gem) has tools to generate WSDL files. You can use the tools even if you're not running your service within Rails.

http://www.datanoise.com/articles/2008/7/2/actionwebservice-is-back

As for whether it will work with a .NET client, the answer is maybe. Many .NET clients seem to expect Microsoft's "extended" SOAP info, which .NET webservices provide by default. If the client is also able to consume a service without that extra stuff, then sure.

UPDATE #1

The above link no longer appears to work. There are however forks of ActionWebService that have popped up over on github. You can see a pretty good list of them here. Here are a couple of links to some key versions:

  • original datanoise version
  • clevertechru's port, works w/ Rails 3.1.* & Ruby 1.9

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

how to create a web service

Have you Googled how to build web services in Ruby? Here are a few links that come up, all addressing exactly what you want to do:

http://www.tutorialspoint.com/ruby/ruby_web_services.htm

http://www.ibm.com/developerworks/opensource/library/os-ws-rubyrails/index.html

http://searchsoa.techtarget.com/tip/Web-services-with-Ruby-on-Rails

How about you take a look at some of those links, and come back to us if you have further questions.

I do have one elaboration:

My partner builds the flash
application and he told me that the
flash application interacts through
WSDL file.

It sounds like your partner has an incomplete understanding of how Flash can access remote data services. Using a SOAP Web Service with a WSDL is one method, for sure, and here is some documentation on that.

A Flex / Flash application can also make standard HTTP calls, sometimes called REST Web Services. In many cases, REST Web Services will return an XML Document, but that is not required. Any data, including simple text data, can be returned from a REST Web Service.

What many people prefer to do is to use an AMF Gateway with RemoteObject. AMF is a binary format so you'll get much smaller file size transferred back and forth than the alternatives. It also provides for automatic object translation between your server side objects and client side objects. This can be a time saver in development because you don't have to parse data to turn it into something Flex can use easily. RubyAMF is one Ruby implementation of AMF.

How do I create a Ruby SOAP client without using a WSDL?

Savon does not require a WSDL document. Please take a look at the new documentation. If you know the SOAP endpoint and target namespace, you can execute a SOAP request like this:

client = Savon::Client.new
wsdl.endpoint = "http://example.com"
wsdl.namespace = "http://soap.example.com"
end

client.request :any_soap_action do
soap.body = { :do => "something" }
end


Related Topics



Leave a reply



Submit