# Wsdl2ruby and SOAP problems

**URL:** <https://www.ruby-forum.com/t/wsdl2ruby-and-soap-problems/100871>\
**Category:** Ruby\
**Created:** [August 1, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/wsdl2ruby-and-soap-problems/100871 "2006-08-01T18:06:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emcconne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@emcconne](https://www.ruby-forum.com/u/emcconne)\
**Post date:** [August 1, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/wsdl2ruby-and-soap-problems/100871/1 "2006-08-01T18:06:06Z")

</div>

I am new to Ruby and am evaluating it for a project that would replace  
and extend existing Perl code. I am using wsdl2ruby to generate a  
client stub with associated classes for a web service. Most of the  
basic calls more fine but the more complex method calls that take  
parameter “anyType” do not work so well. It appears that the type is  
not getting set in the SOAP message generated by ruby. However, the  
perl code does allow me to set the type (manually by calling  
SOAP::Data → type using SOAP::Lite). Below is the relevant code and  
generated messages:

-----RELEVANT WSDL SECTION----

\<xsd:element name=“Create”\>  
xsd:complexType  
xsd:sequence  
\<xsd:element maxOccurs=“1” minOccurs=“1” name=“handle”  
type=“xsd:string” vma:auth=“Configure”/\>  
\<xsd:element maxOccurs=“1” minOccurs=“1” name=“name”  
type=“xsd:string”/\>  
\<xsd:element maxOccurs=“1” minOccurs=“1” name=“type”  
type=“xsd:string”/\>  
\<xsd:element maxOccurs=“1” minOccurs=“0” name=“initial”  
type=“xsd:anyType”/\>  
\</xsd:sequence\>  
\</xsd:complexType\>  
\</xsd:element

-----GENERATED CLASSES-----

# {urn:vma1}Create

class Create  
@@schema\_type = “Create”  
@@schema\_ns = “urn:vma1”  
@@schema\_qualified = “true”  
@@schema\_element = [[“handle”, “SOAP::SOAPString”], [“name”,  
“SOAP::SOAPString”], [“type”, “SOAP::SOAPString”], [“initial”,  
“anyType”]]

attr\_accessor :handle  
attr\_accessor :name  
attr\_accessor :type  
attr\_accessor :initial

def initialize(handle = nil, name = nil, type = nil, initial = nil)  
@handle = handle  
@name = name  
@type = type  
@initial = initial  
end  
end

----FROM DRIVER -----

class VmaPortType \< :🧼:RPC::Driver  
DefaultEndpointUrl = “[http://xxx.xxx.xxx:8080/](http://xxx.xxx.xxx:8080/)”  
MappingRegistry = :🧼:Mapping::Registry.new

Methods = [  
[ “”,  
“create”,  
[ [“in”, “parameters”, [“:🧼:SOAPElement”, “urn:vma1”,  
“Create”], true],  
[“out”, “parameters”, [“:🧼:SOAPElement”, “urn:vma1”,  
“CreateResponse”], true] ],  
{ :request\_style =\> :document, :request\_use =\> :literal,  
:response\_style =\> :document, :response\_use =\> :literal }  
]  
]  
def initialize(endpoint\_url = nil)  
endpoint\_url ||= DefaultEndpointUrl  
super(endpoint\_url, nil)  
self.mapping\_registry = MappingRegistry  
init\_methods  
end

private

def init\_methods  
Methods.each do |definitions|  
opt = definitions.last  
if opt[:request\_style] == :document  
add\_document\_operation(\*definitions)  
else  
add\_rpc\_operation(\*definitions)  
qname = definitions[0]  
name = definitions[2]  
if qname.name != name and qname.name.capitalize ==  
name.capitalize  
:🧼:Mapping.define\_singleton\_method(self, qname.name) do  
|\*arg|  
**send** (name, \*arg)  
end  
end  
end  
end  
end  
end

-----FROM CLIENT-----

require ‘vmaDriver.rb’  
endpoint\_url = ARGV.shift  
$KCODE = ‘UTF8’  
obj = VmaPortType.new(endpoint\_url)  
obj.generate\_explicit\_type = true

# run ruby with -d to see SOAP widumps.

obj.wiredump\_dev = STDERR

parameter=nil

vmlogin=Login.new(“emcconne”, “oh,bother”)  
puts obj.login(vmlogin)  
vmcenter=ResolvePath.new(“/vcenter/Testdrive\_Farm”)  
vmdomain=obj.resolvePath(vmcenter).returnval

vmpath=ResolvePath.new(“/host/192.168.0.2”)  
vmhost=obj.resolvePath(vmpath).returnval

vmcpuinfo=VirtualCPUInfo.new(2,“”)  
vmmeminfo=VirtualMemoryInfo.new(512,“”)  
vmhardware=VirtualHardware.new(vmcpuinfo,vmmeminfo,“”,“”,[],[],[])  
vmspec=VirtualMachineSpec.new(vmhost,“linux”,“”,vmhardware)  
vmcreate=Create.new(vmdomain,“rubyvm”,“VirtualMachine”,vmspec)  
puts obj.create(vmcreate)

----- GENERATED MESSAGE -----

\<?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  
  
vma-domain-00000000001  
rubyvm  
VirtualMachine  
  
vma-host-00000000002  
linux  
  
  
  
2  
  
  
  
512  
  
  
  
  
  
  
  
\</env:Body\>  
\</env:Envelope\>

-------WORKING PERL MESSAGE ------

\<?xml version="1.0" encoding="UTF-8"?\>\<soap:Envelope

xmlns:namesp1=“[http://namespaces.soaplite.com/perl](http://namespaces.soaplite.com/perl)”  
xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”  
xmlns:soapenc=“[http://schemas.xmlsoap.org/soap/encoding/](http://schemas.xmlsoap.org/soap/encoding/)”  
xmlns:xsd=“[http://www.w3.org/2001/XMLSchema](http://www.w3.org/2001/XMLSchema)”  
soap:encodingStyle=“[http://schemas.xmlsoap.org/soap/encoding/](http://schemas.xmlsoap.org/soap/encoding/)”  
xmlns:soap=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”\>  
soap:Body  
  
vma-domain-00000000001  
perlvm  
VirtualMachine  
  
vma-host-00000000002  
Linux  
  
  
1  
  
  
256  
  
  
  
  
\</soap:Body\>  
\</soap:Envelope\>

---

<div class="post-metadata">

**Author:** ![emcconne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@emcconne](https://www.ruby-forum.com/u/emcconne)\
**Post date:** [August 7, 2006, 12:12pm UTC](https://www.ruby-forum.com/t/wsdl2ruby-and-soap-problems/100871/2 "2006-08-07T12:12:18Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi,

emcconne wrote:

> I am new to Ruby and am evaluating it for a project that would replace  
> and extend existing Perl code. I am using wsdl2ruby to generate a  
> client stub with associated classes for a web service. Most of the  
> basic calls more fine but the more complex method calls that take  
> parameter “anyType” do not work so well. It appears that the type is  
> not getting set in the SOAP message generated by ruby. However, the  
> perl code does allow me to set the type (manually by calling  
> SOAP::Data -\> type using SOAP::Lite). Below is the relevant code and  
> generated messages:  
> [snip]

Unfortunately, Driver#generate\_explicit\_type = true does not work for  
literal service. I’ll look into how I can implement it.

No easy way for now.

req = SOAP::SOAPElement.new(XSD::QName.new(“urn:example.com”, “req”))  
value1 = SOAP::SOAPElement.new(“value1”, “1”)  
value1.extraattr[“xsi:type”] = “xsd:int”  
req.add(value1)  
driver.method\_call(req)

Regards,  
// NaHi  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2.1 (Cygwin)

iQEVAwUBRNcRYB9L2jg5EEGlAQJCPQf/VLmnYSeaXoUNfYq4fux4Xvb6YP87XdmJ  
q0A92ljYWbqW08RzmZ8dS/NFUuVjQJq0B8nsSceiRHsAglaSQdnC9s7K1Z5jup2j  
X3rmldq0HBqy7GyOdcIwAEUP0yFcpdMtF+X+HyrztL3yibI7DFMwmQGi/z2KDm+z  
xCEtLac8jofWKZPDSxsiv/SaBZVqJT933m/G6J5RbDw6r67Ny4KvX0LpGtzmJu9D  
JOnnEFrNYxqykXOrY2Nh9lkbC6aYe2/8NQKol0rVwwgkjXp1efNe5Ny7LQObwJ+W  
3PqI8/eQ9Axc9IcewB9i70g1wGBl5lhdCkEKntaK5icLwE8bPFv5Ew==  
=HBYT  
-----END PGP SIGNATURE-----
