Forum: Ruby on Rails ActionWebService and WSDL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3a74f1acfc85544f8fb107a6141dcd8f?d=identicon&s=25 Paul Tremblett (ptremblett)
on 2005-12-21 13:11
The suggested approach for developing a web service using
ActionWebService appears to be start by defining the API you want and
then you can generate WSDL. I want to start from WSDL. I've tried
wsdl2ruby but the Ruby code it generates does not appear to play well
with Rails. Is there a way I can get what I want? I'm new at this so if
the answer is a forehead slapper, I'll be happy.
Dd72ba9de6187137e032280b36169980?d=identicon&s=25 Kevin Marshall (falicon)
on 2006-04-11 21:12
Paul Tremblett wrote:
> The suggested approach for developing a web service using
> ActionWebService appears to be start by defining the API you want and
> then you can generate WSDL. I want to start from WSDL. I've tried
> wsdl2ruby but the Ruby code it generates does not appear to play well
> with Rails. Is there a way I can get what I want? I'm new at this so if
> the answer is a forehead slapper, I'll be happy.

ActionWebService is primarily for hosting/serving up web services
(servers)...it sounds like you are more interested in building a client
for some one else's web service (using a provided WSDL file)...for that
I would suggest you try SOAP4R ... here's some quick steps:

1. make sure to update your configuration to include the wsdl driver
(you can simply put this in your config/environment.rb file):

require 'soap/wsdlDriver'

2. Create a controller with an action that actually talks to the
webservice (this code conects to Google using their WSDL file) -
(app/controllers/code_controller.rb):

class CodeController < ApplicationController
  def googletest
    yourkey = 'YOUR GOOGLE DEVELOPER KEY'            # Your Google dev
key
    @yourquery = 'YOUR SEARCH TEXT'                       # Search value
    XSD::Charset.encoding = 'UTF8'                      # Set encoding
    wsdlfile = "http://api.google.com/GoogleSearch.wsdl"    # WSDL
location

    # Create driver and set up methods
    driver = SOAP::WSDLDriverFactory.new(wsdlfile).create_rpc_driver

    # make our SOAP request
    @result = driver.doGoogleSearch(yourkey, @yourquery, 0, 3, false,
'', false, '', '', '')
  end
end

3. Create your related view to display your results
(app/views/code/googletest.rhtml):

Query for: <%= @yourquery %><br>
Found: <%= @result.estimatedTotalResultsCount %><br>
Query took about <%= @result.searchTime %> seconds<br>
<% @result.resultElements.each do |rec| %>
  <b>Title:</b> <%= rec["title"] %><br>
  <b>Summary:</b> <%= rec.snippet %><br>
  <b>Link:</b> <a href="<%= rec["URL"] %>"><%= rec["URL"] %></a>
  <br><br>
<% end %>

That should be it! Hopefully that helps you out...oh and just for a
shameless plug, this all came directly from a PDF document I'm putting
together for O'Reilly that will cover Web Services with Ruby on
Rails...it breaks this example down in more detail as to why we do what
we do (and also shows you how to build clients for REST, XML-RPC, and
SOAP without WSDL...plus I cover ActionWebService and how to use it to
serve/host REST, XML-RPC, and SOAP services)...should be out in a few
weeks for everyone to check out!

p.s. if you need/want more specifics on any of the above steps please
feel free to email me directly at info@falicon.com
This topic is locked and can not be replied to.