ActionWebService and WSDL

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.

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’

  1. 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

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

Query for: <%= @yourquery %>

Found: <%= @result.estimatedTotalResultsCount %>

Query took about <%= @result.searchTime %> seconds

<% @result.resultElements.each do |rec| %>
Title: <%= rec[“title”] %>

Summary: <%= rec.snippet %>

Link: <a href=“<%= rec[“URL”] %>”><%= rec[“URL”] %>



<% 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 [email protected]