does soap have problems with structs?

J

jm

The following code (testsrv.rb and testclt.rb) generates

/usr/local/lib/ruby/1.8/soap/mapping/registry.rb:375:in `_obj2soap':
Cannot map to SOAP/OM. (SOAP::Mapping::MappingError)
from /usr/local/lib/ruby/1.8/soap/mapping/registry.rb:315:in
`obj2soap'
from /usr/local/lib/ruby/1.8/soap/mapping/mapping.rb:105:in
`_obj2soap'
from /usr/local/lib/ruby/1.8/soap/mapping/mapping.rb:36:in
`obj2soap'
from /usr/local/lib/ruby/1.8/soap/rpc/router.rb:109:in
`create_response'
from /usr/local/lib/ruby/1.8/soap/rpc/router.rb:135:in
`dispatch'
from /usr/local/lib/ruby/1.8/soap/rpc/router.rb:61:in `route'
from /usr/local/lib/ruby/1.8/soap/rpc/soaplet.rb:75:in `do_POST'
from
/usr/local/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in
`__send__'
... 12 levels...
from /usr/local/lib/ruby/1.8/soap/mapping/mapping.rb:81:in
`fault2exception'
from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:195:in `call'
from (eval):2:in `a_method'
from ./testclt.rb:17

yet if the Structs are replaced by Hashs this works. A local call works
in both cases. Is this a known problem with soap or is it something to
do with my code?

J.

-- in testsrv.rb
#!/usr/local/bin/ruby

require 'webrick'
require 'soap/rpc/soaplet'


class Testsrv
@@test_struct = Struct.new:)one,:two)
def a_method
@@test_struct.new("string",1)
end
end

t = Testsrv.new()
s = WEBrick::HTTPServer.new(
:port => 2000,
:Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG)
)

srv = SOAP::RPC::SOAPlet.new()
srv.add_servant(t, "urn:t")
s.mount("/soap", srv)
trap("INT"){s.shutdown}
s.start

-- in testclt.rb

#!/usr/local/bin/ruby

require 'soap/rpc/driver'

class Testclient < SOAP::RPC::Driver
@@server_default = "http://127.0.0.1:2000/soap/"
@@namespace_default = "urn:t"

def initialize(server=nil,namespace=nil)
super(server || @@server_default,
namespace || @@namespace_default)
add_method("a_method")
end
end

tc = Testclient.new()
p tc.a_method
 
N

NAKAMURA, Hiroshi

Hi,

Sorry for not responding long long time. I'm busy these days... (after
May last, the day www.ruby-lang.org cracked) I still cannot restore
the CVS repository of soap4r. I was unaware of your mail.

# all: please tell me if you haven't got any response from me.
yet if the Structs are replaced by Hashs this works. A local call works
in both cases. Is this a known problem with soap or is it something to
do with my code?
class Testsrv
@@test_struct = Struct.new:)one,:two)

Here you're creating anonymous Struct. Did you do it intentionally?
def a_method
@@test_struct.new("string",1)
end
end

But you'll see the same result with

@@test_struct = Struct.new("Foo", :eek:ne,:two)

It could be a bug of soap4r. I'll look into it.

Regards,
// NaHi
 
J

jm

Figured you must have been distracted by something more important - day
to day survival came to mind. The anonymous Struct was what I intented.
I've rewritten it to use Hashs so don't rush to fix it. It did seem a
bit of a hole in the soap implementation with Structs being recommended
for some situations in ruby, hence the email. Thanks for letting me
know you've seen it.

J.

On 02/07/2004, at 12:18 AM, NAKAMURA, Hiroshi wrote:

Hi,

Sorry for not responding long long time.  I'm busy these days... (after
May last, the day www.ruby-lang.org cracked)   I still cannot restore
the CVS repository of soap4r.   I was unaware of your mail.

# all: please tell me if you haven't got any response from me.
yet if the Structs are replaced by Hashs this works. A local call works
in both cases. Is this a known problem with soap or is it something to
do with my code?
class Testsrv
   @@test_struct = Struct.new:)one,:two)

Here you're creating anonymous Struct.  Did you do it intentionally?
   def a_method
     @@test_struct.new("string",1)
   end
end

But you'll see the same result with

   @@test_struct = Struct.new("Foo", :eek:ne,:two)

It could be a bug of soap4r.  I'll look into it.

Regards,
// NaHi
 
N

NAKAMURA, Hiroshi

Hi, jm,
Figured you must have been distracted by something more important - day
to day survival came to mind.

Thank you for your concern.
The anonymous Struct was what I intented.
I've rewritten it to use Hashs so don't rush to fix it. It did seem a
bit of a hole in the soap implementation with Structs being recommended
for some situations in ruby, hence the email.

I changed Ruby's Struct <-> SOAP Data Model mapping. Anonymous struct
is mapped to anyType SOAP struct as following.

<?xml version="1.0" encoding="us-ascii" ?>
<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:a_methodResponse xmlns:n1="urn:t"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:anyType">
<one xsi:type="xsd:string">string</one>
<two xsi:type="xsd:int">1</two>
</return>
</n1:a_methodResponse>
</env:Body>
</env:Envelope>

OK?

Regards,
// NaHi
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top