Forum: Ruby Error calling a SOAP service from within a Rails controller

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.
860dc779f0007a35bdcd12b5fc9eb589?d=identicon&s=25 Dean Holdren (Guest)
on 2006-01-26 21:38
(Received via mailing list)
The following works fine as a standalone ruby program:
**********************************************************************************************
t = Time.now
starter = Time.local(t.year,t.mon, t.day) + (24 *3600)
ender = starter + 7 * 24 *3600
lat = 40.352039
lon = -74.191961

require 'soap/wsdlDriver'

params = {:maxt => false, :mint => false, :temp => true, :dew => false,
  :pop12 => false, :qpf => false, :sky => false, :snow => false,
  :wspd => false, :wdir => false, :wx => false, :waveh => false,
  :icons => false, :rh => false, :appt => true}

wsdl = "http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/...
drv = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
drv.wiredump_dev = STDOUT if $DEBUG
dwml = drv.NDFDgen(lat, lon, 'time-series', starter, ender, params)
puts dwml
require 'xsd/mapping'
data = XSD::Mapping.xml2obj(dwml).data
**********************************************************************************************
However, when I try to call the same from within a ruby controller, I
get:

SOAP::HTTPStreamError (502: Bad Gateway):
    c:/ruby-1.8.4/lib/ruby/1.8/soap/streamHandler.rb:200:in `send_post'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/streamHandler.rb:109:in `send'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/proxy.rb:170:in `route'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/proxy.rb:141:in `call'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/driver.rb:178:in `call'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/driver.rb:232:in `nDFDgen'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/wsdlDriver.rb:117:in `NDFDgen'

The code in my controller is:
**********************************************************************************************
       def get_weather
                lat = params[:lat]
                lon = params[:lon]

                t = Time.now
                starter = Time.local(t.year,t.mon, t.day) + (24 *3600)
                ender = starter + 7 * 24 *3600

                params = {:maxt => false, :mint => false, :temp =>
true, :dew => false,
                        :pop12 => false, :qpf => false, :sky => false,
:snow => false,
                        :wspd => false, :wdir => false, :wx => false,
:waveh => false,
                        :icons => false, :rh => false, :appt => true}

                wsdl =
"http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/...
                drv =
SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
                drv.wiredump_dev = STDOUT if $DEBUG
                dwml = drv.NDFDgen(lat, lon, 'time-series', starter,
ender, params)

                @data = XSD::Mapping.xml2obj(dwml).data

        end
**********************************************************************************************
0fd334c46e284c02d4622a8ac429b236?d=identicon&s=25 Anthony Elizondo (Guest)
on 2006-01-26 21:50
(Received via mailing list)
When you're playing with SOAP in Rails, I think you want to use
ActionWebService. See:
http://rails.rubyonrails.com/classes/ActionWebServ...

For Rails specific questions such as this, try the Rails mailing list,
at http://lists.rubyonrails.org/mailman/listinfo/rails or
http://www.ruby-forum.com/forum/3
860dc779f0007a35bdcd12b5fc9eb589?d=identicon&s=25 Dean Holdren (Guest)
on 2006-01-26 22:23
(Received via mailing list)
thanks, I've tried using ActionWebService::Client::SOAP, but I get the
same error (pretty much), here's the version of the method within my
Controller that used ActionWebService:

def get_weather
               lat = params[:lat]
               lon = params[:lon]
		t = Time.now
		starter = Time.local(t.year,t.mon, t.day) + (24 *3600)
		ender = starter + 7 * 24 *3600

		params = WeatherParametersType.new({:maxt => false, :mint => false,
:temp => true, :dew => false,
	  		:pop12 => false, :qpf => false, :sky => false, :snow => false,
	  		:wspd => false, :wdir => false, :wx => false, :waveh => false,
	  		:icons => false, :rh => false, :appt => true})

	  	soap_client = ActionWebService::Client::Soap.new(WeatherAPI,
"http://www.weather.gov/forecasts/xml/SOAP_server/n...)
	  	@dwml = soap_client.NDFDgen(lat, lon, 'time-series', starter, ender,
params)
	  	@data = @dwml
    end

and I'm using these classes I've defined:

class WeatherParametersType < ActionWebService::Struct
    member :maxt, :boolean
    member :mint, :boolean
    member :temp, :boolean
    member :dew, :boolean
    member :pop12, :boolean
    member :qpf, :boolean
    member :sky, :boolean
    member :snow, :boolean
    member :wspd, :boolean
    member :wdir, :boolean
    member :wx, :boolean
    member :waveh, :boolean
    member :icons, :boolean
    member :rh, :boolean
    member :appt, :boolean
end


class WeatherAPI < ActionWebService::API::Base
	api_method :NDFDgen, :expects => [[Float], [Float], [String], [Time],
[Time], [WeatherParametersType]], :returns => [String]
end

The error stack trace:

SOAP::HTTPStreamError (502: Bad Gateway):
    c:/ruby-1.8.4/lib/ruby/1.8/soap/streamHandler.rb:200:in `send_post'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/streamHandler.rb:109:in `send'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/proxy.rb:170:in `route'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/proxy.rb:141:in `call'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/driver.rb:178:in `call'
    c:/ruby-1.8.4/lib/ruby/1.8/soap/rpc/driver.rb:232:in `NDFDgen'
    c:/ruby-1.8.4/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0/lib/action_web_s
ervice/client/soap_client.rb:61:in `perform_invocation'
    c:/ruby-1.8.4/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0/lib/action_web_s
ervice/client/base.rb:15:in `method_missing'
860dc779f0007a35bdcd12b5fc9eb589?d=identicon&s=25 Dean Holdren (Guest)
on 2006-01-28 01:06
(Received via mailing list)
well it turns out I was passing bad parameters to the service. weird
response though...
This topic is locked and can not be replied to.