Ruby SOAP client communication with Microsoft .NET webservice

K

Kishore

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"
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"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<stopGenerate xmlns="http://instrument1.orbit-lab.org/OrbitWS/">
<request_id>string</request_id>
</stopGenerate>
</soap:Body>
</soap:Envelope>

However, our SOAP request looks like:

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:stopGenerate
xmlns:n1="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
 
K

Kero

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<stopGenerate xmlns="http://instrument1.orbit-lab.org/OrbitWS/">
<request_id>string</request_id>
</stopGenerate>
</soap:Body>
</soap:Envelope>

However, our SOAP request looks like:

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:stopGenerate
xmlns:n1="http://instrument1.orbit-lab.org/OrbitWS/">
</n1:stopGenerate>
</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.
 
K

Kishore

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"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Generate xmlns="http://instrument1/OrbitWS/">
<request_id>string</request_id>
<names>
<string>string</string>
<string>string</string>
</names>
<values>
<string>string</string>
<string>string</string>
</values>
</Generate>
</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"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:Generate xmlns:n1="http://instrument1.orbit-lab.org/OrbitWS/">
<n1:request_id>1</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
 
T

tsumeruby

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
 
K

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"]))

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.
 
K

Kishore

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 soap4r

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

2. 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.

3. 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
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top