[Rails] Calling a SOAP service from within a Rails controller

Dean Holdren
Thu, 26 Jan 2006 16:50:07 -0000

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/ndfdXML.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 in Weather_map#data

 502: Bad Gateway


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/ndfdXML.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
**********************************************************************************************