# Ruby Syntax and SOAP Web Service

**URL:** <https://www.ruby-forum.com/t/ruby-syntax-and-soap-web-service/106782>\
**Category:** Ruby\
**Created:** [June 14, 2007, 2:16am UTC](https://www.ruby-forum.com/t/ruby-syntax-and-soap-web-service/106782 "2007-06-14T02:16:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [June 14, 2007, 2:16am UTC](https://www.ruby-forum.com/t/ruby-syntax-and-soap-web-service/106782/1 "2007-06-14T02:16:01Z")

</div>

I need a good tutorial to show how to create a RUBY  
SOAP request when I have an example SOAP request file. The example in my  
book is next to useless. Also, how can I see that SOAP xml is being  
sent  
and the client response?

An example, I am attempting to call this service  
([http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP](http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP)).

What I need to know is which namespace to use for the request. Also, do  
I  
need to add anything to specify the Envelope namespaces.

Thanks

P.S.  
This is the example Soap request.

POST /uszip.asmx HTTP/1.1  
Host: [www.webservicex.net](http://www.webservicex.net)  
Content-Type: text/xml; charset=utf-8  
Content-Length: length  
SOAPAction: “[http://www.webserviceX.NET/GetInfoByZIP](http://www.webserviceX.NET/GetInfoByZIP)”

\<?xml version="1.0" encoding="utf-8"?\>

\<soap:Envelope xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”  
xmlns:xsd=“[http://www.w3.org/2001/XMLSchema](http://www.w3.org/2001/XMLSchema)”  
xmlns:soap=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”\>  
soap:Body  
  
string  
  
\</soap:Body\>  
\</soap:Envelope\>

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [June 14, 2007, 5:11am UTC](https://www.ruby-forum.com/t/ruby-syntax-and-soap-web-service/106782/2 "2007-06-14T05:11:19Z")

</div>

I never did find a decent tutorial on using SOAP in Ruby. However, I  
did find bits and pieces in blogs and list archives. There’s actually  
quite a bit of information in the SOAP4r trac (the Ruby SOAP code _is_  
SOAP4r):

[http://dev.ctor.org/soap4r](http://dev.ctor.org/soap4r)

The biggest “ah-hah” moment for me was figuring out that you don’t  
have generate a bunch of classes from WSDL in Ruby like in other  
languages… you can, but Ruby is dynamic enough that you can just  
create a driver instance from the WSDL and all the signatures in that  
WSDL become available as method calls on the driver [1]. Similarly,  
the SOAP response object is accessible as a nested hash of data or as  
pseudo-method calls.

Hope this helps some!

Ben

[1] Here’s how I created my driver:

soap\_driver = SOAP::WSDLDriverFactory.new(RAILS\_ROOT + ‘/config/  
somewebservice.wsdl’).create\_rpc\_driver

Then I can call every SOAP call listed in that wsdl just by calling  
the name on the driver:

response = soap\_driver.someWebService({ hash of params })

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [April 30, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/ruby-syntax-and-soap-web-service/106782/3 "2009-04-30T17:51:49Z")

</div>

So in your example would be:  
mH=Hash.new()  
mH[“USZip”]=“92210”

response = soap\_driver.someWebService(mH)

but this is not working…

Do you know why?

Thanks.

removed\_email\_address@domain.invalid wrote:

> I never did find a decent tutorial on using SOAP in Ruby. However, I  
> did find bits and pieces in blogs and list archives. There’s actually
