# Calling a SOAP service from within a Rails controller

**URL:** <https://www.ruby-forum.com/t/calling-a-soap-service-from-within-a-rails-controller/97696>\
**Category:** Rails\
**Created:** [January 26, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/calling-a-soap-service-from-within-a-rails-controller/97696 "2006-01-26T17:51:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![deanhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@deanhiller](https://www.ruby-forum.com/u/deanhiller)\
**Post date:** [January 26, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/calling-a-soap-service-from-within-a-rails-controller/97696/1 "2006-01-26T17:51:45Z")

</div>

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](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](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

```

* * *

---

<div class="post-metadata">

**Author:** ![deanhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@deanhiller](https://www.ruby-forum.com/u/deanhiller)\
**Post date:** [January 26, 2006, 8:55pm UTC](https://www.ruby-forum.com/t/calling-a-soap-service-from-within-a-rails-controller/97696/2 "2006-01-26T20:55:48Z")

</div>

On Jan 26, 2006, at 10:49 AM, Dean H. wrote:

> SOAP::HTTPStreamError in Weather\_map#data
> 
> 502: Bad Gateway

Did you try grabbing this file with a web browser, wget, curl, open-  
uri, etc.? Sounds like there could be a problem with the remote server.

Also, it looks like you’re going to be downloading the WSDL every  
time your controller runs. I’d download the WSDL and put it  
somewhere in your app so that you aren’t having to wait for that file  
every time.

–  
~akk

> **[Adam Keys is typing](https://therealadam.com)**
>
> Developer and engineering manager at large

---

<div class="post-metadata">

**Author:** ![deanhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@deanhiller](https://www.ruby-forum.com/u/deanhiller)\
**Post date:** [January 26, 2006, 9:35pm UTC](https://www.ruby-forum.com/t/calling-a-soap-service-from-within-a-rails-controller/97696/3 "2006-01-26T21:35:17Z")

</div>

On 1/26/06, Adam K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jan 26, 2006, at 10:49 AM, Dean H. wrote:
> 
> > SOAP::HTTPStreamError in Weather\_map#data
> > 
> > 502: Bad Gateway
> 
> Did you try grabbing this file with a web browser, wget, curl, open-  
> uri, etc.? Sounds like there could be a problem with the remote server.

Yes I did, works fine within both a web browser, or as I stated  
before, within a standalone ruby program.

The error occurs within the SOAP call, only when a rails controller is  
the client.

> Also, it looks like you’re going to be downloading the WSDL every  
> time your controller runs. I’d download the WSDL and put it  
> somewhere in your app so that you aren’t having to wait for that file  
> every time.

OK, thanks, I will do that. but I’m more concerned with the error with  
SOAP call, here is the stack trace:

SOAP::HTTPStreamError in Weather\_map#data  
502: Bad Gateway  
RAILS\_ROOT: ./script/…/config/…

Application Trace | Framework Trace | Full Trace  
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’

---

<div class="post-metadata">

**Author:** ![deanhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@deanhiller](https://www.ruby-forum.com/u/deanhiller)\
**Post date:** [January 28, 2006, 1:06am UTC](https://www.ruby-forum.com/t/calling-a-soap-service-from-within-a-rails-controller/97696/4 "2006-01-28T01:06:58Z")

</div>

well it turns out I was passing bad parameters to the service. weird  
response though…
