Wsdl2ruby and SOAP problems

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 < ::soap::RPC::Driver
DefaultEndpointUrl = “http://xxx.xxx.xxx:8080/
MappingRegistry = ::soap::Mapping::Registry.new

Methods = [
[ “”,
“create”,
[ [“in”, “parameters”, [“::soap::SOAPElement”, “urn:vma1”,
“Create”], true],
[“out”, “parameters”, [“::soap::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
::soap::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
xmlns:env=“http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi=“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
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xmlns:soapenc=“http://schemas.xmlsoap.org/soap/encoding/
xmlns:xsd=“http://www.w3.org/2001/XMLSchema
soap:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/
xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/”>
soap:Body

vma-domain-00000000001
perlvm
VirtualMachine

vma-host-00000000002
Linux


1


256




</soap:Body>
</soap:Envelope>

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