# Ruby SOAP client communication with Microsoft .NET webservic

**URL:** <https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916>\
**Category:** Ruby\
**Created:** [December 10, 2005, 1:45am UTC](https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916 "2005-12-10T01:45:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![keyshawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@keyshawn](https://www.ruby-forum.com/u/keyshawn)\
**Post date:** [December 10, 2005, 1:45am UTC](https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916/1 "2005-12-10T01:45:59Z")

</div>

Hi:

I am trying to interface a SOAP client written in Ruby with a .NET  
webservice. However, I am unable to get the client to construct the  
correct SOAP request for methods with one string argument. My ruby  
client file has the following code:

require ‘soap/wsdlDriver’  
require ‘cgi’

WSDL\_URL = “[http://instrument1/orbitws/orbitinterferencews.asmx?WSDL](http://instrument1/orbitws/orbitinterferencews.asmx?WSDL)”  
soap\_client = SOAP::WSDLDriverFactory.new(WSDL\_URL).create\_rpc\_driver

# Log SOAP request and response

soap\_client.wiredump\_file\_base = “soap-log.txt”

# Call reset method.

result = soap\_client.resetIntWS(nil)  
puts result.inspect

# Call stopGenerate method.

result = soap\_client.stopGenerate(‘1’)  
puts result.inspect

The first method call works but the second one fails to construct the  
SOAP request with the single argument. We tried using double quotes as  
well but that did not work either.

The SOAP request we want should like like:

\<?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=“[XML Schema](http://www.w3.org/2001/XMLSchema)”  
xmlns:soap=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”\>  
soap:Body  
  
\<request\_id\>string\</request\_id\>  
  
\</soap:Body\>  
\</soap:Envelope\>

However, our SOAP request looks like:

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

\<env:Envelope xmlns:xsd=“[XML Schema](http://www.w3.org/2001/XMLSchema)”  
xmlns:env=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”  
xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
env:Body  
\<n1:stopGenerate  
xmlns:n1=“[http://instrument1.orbit-lab.org/OrbitWS/](http://instrument1.orbit-lab.org/OrbitWS/)”\>  
\</n1:stopGenerate\>  
\</env:Body\>  
\</env:Envelope\>

Note that the “\<request\_id\>string\</request\_id\>” is missing. Can you  
please tell me why this is happening. I am using ruby v1.8.4 on a  
debian linux 2.6.11-1-686-smp.

Thanks,  
Kishore

---

<div class="post-metadata">

**Author:** ![keyshawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@keyshawn](https://www.ruby-forum.com/u/keyshawn)\
**Post date:** [December 10, 2005, 9:14am UTC](https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916/2 "2005-12-10T09:14:26Z")

</div>

> \</env:Body\>  
> \</env:Envelope\>

How would the call to stopGenerate know that ‘1’ is a request id?

I have had success with using Structs.

Request = Struct.new(:request\_id)  
soap.stopGenerate(Request.new(‘1’))

Hth,  
Kero.

---

<div class="post-metadata">

**Author:** ![keyshawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@keyshawn](https://www.ruby-forum.com/u/keyshawn)\
**Post date:** [December 10, 2005, 7:36pm UTC](https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916/3 "2005-12-10T19:36:17Z")

</div>

Hi Kero:

Thanks a lot. That worked out. Would you know how to pass an array of  
strings as argument? I am trying to the following:

Request = Struct.new(:request\_id, :names, :values)  
result = soap\_client.stopGenerate(Request.new(“1”, [“POWER”, “FREQ”],  
[“-15”, “5.18GHz”]))  
puts result.inspect

This should generate the following SOAP request:

\<?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  
  
\<request\_id\>string\</request\_id\>  
  
string  
string  
  
  
string  
string  
  
  
\</soap:Body\>  
\</soap:Envelope\>

However, it creates the following:

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

\<env:Envelope xmlns:xsd=“[http://www.w3.org/2001/XMLSchema](http://www.w3.org/2001/XMLSchema)”  
xmlns:env=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”  
xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
env:Body  
\<n1:Generate xmlns:n1=“[http://instrument1.orbit-lab.org/OrbitWS/](http://instrument1.orbit-lab.org/OrbitWS/)”\>  
n1:request\_id1\</n1:request\_id\>  
n1:names  
n1:string\</n1:string\>  
\</n1:names\>  
n1:values  
n1:string\</n1:string\>  
\</n1:values\>  
\</n1:Generate\>  
\</env:Body\>  
\</env:Envelope\>

Thanks,  
Kishore

---

<div class="post-metadata">

**Author:** ![keyshawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@keyshawn](https://www.ruby-forum.com/u/keyshawn)\
**Post date:** [December 12, 2005, 9:28am UTC](https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916/4 "2005-12-12T09:28:10Z")

</div>

> Thanks a lot. That worked out. Would you know how to pass an array of  
> strings as argument? I am trying to the following:
> 
> Request = Struct.new(:request\_id, :names, :values)  
> result = soap\_client.stopGenerate(Request.new(“1”, [“POWER”, “FREQ”],  
> ["-15", “5.18GHz”]))

I have something like  
Request = Struct.new(…)  
Names = Struct.new(…)  
Request.new(1, Names.new([“power”, “freq”], Values.new([…])

i.e. the arrays wrapped in their own structs.

However, I needed different soap requests; I got to it after a  
_detailed_  
look (yuck) at the wsdl, I suppose yours might look different. YMMV.

And here my experience ends. I got working what I needed, then stopped  
looking.

Bye,  
Kero.

---

<div class="post-metadata">

**Author:** ![keyshawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@keyshawn](https://www.ruby-forum.com/u/keyshawn)\
**Post date:** [December 10, 2005, 11:32pm UTC](https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916/5 "2005-12-10T23:32:30Z")

</div>

On Sunday 11 December 2005 03:32 am, Kishore wrote:

When using SOAP4R with .NET web services, you must use the  
ASPDotNetHander.

@my\_client.default\_encodingstyle =  
SOAP::EncodingStyle::ASPDotNetHandler::Namespace

Tsume

---

<div class="post-metadata">

**Author:** ![keyshawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@keyshawn](https://www.ruby-forum.com/u/keyshawn)\
**Post date:** [December 21, 2005, 7:44pm UTC](https://www.ruby-forum.com/t/ruby-soap-client-communication-with-microsoft-net-webservic/49916/6 "2005-12-21T19:44:55Z")

</div>

Hi Kero:

Thanks for getting back to me. I got it to work after reading through  
some of nahi’s emails (thanks to him). The steps I followed were as  
follows:

1. Download soap4r from SVN.  
svn co [http://dev.ctor.org/svn/soap4r/trunk/bin](http://dev.ctor.org/svn/soap4r/trunk/bin) soap4r

This will result in two files being downloaded - wsdl2ruby.rb and  
xsd2ruby.rb. The one I used was the wsdl2ruby.rb.

1. Generate sample SOAP client file

ruby wsdl2ruby.rb --wsdl http://location\_of\_WSDL --type client

This will result in the creation of three files - default.rb,  
defaultDriver.rb and WSClient.rb. The sample client file is  
WSClient.rb. Inside this file, I found all the remote methods and “nil”  
arguments being passed to them. For e.g., I had a remote method defined  
as follows in my web-service:

string observe (string req\_id, string[] names, string[] values);

The second and third argument for this file were vectors of strings.

In the ruby client file, this method was exposed as follows:

obj = WSSoap.new(nil)

parameters = nil  
puts obj.observe(parameters)

So, even though my remote method should have three arguments, here  
there is only one. According to nahi’s email, I needed to construct a  
hash table and pass that as the single argument.

1. Pass actual arguments.  
name = [‘CENTER’, ‘SPAN’, ‘SCALE’, ‘YREF’, ‘INTERVAL’]  
val = [‘5.18 GHz’, ‘2.95 MHz’, ‘4.00’, ‘-68.70’, ‘30000’]  
parameters = {  
‘req\_id’ =\> ‘1’,  
‘names’ =\> {:string =\> name},  
‘values’ =\> {:string =\> val}  
}  
result = obj.observe(parameters)  
puts result.inspect

Hope that helps,  
Kishore
