There appears there is a problem on deserializing the header
value in the SimpleHeader.on_inbound if the header argument
is a simple type as String.
The error is :
Exception `NoMethodError' at /usr/lib/ruby/site_ruby/1.8/soap/header/simplehandl
er.rb:37 - undefined method `to_obj' for #<SOAP::SOAPString:0x104ac4c8>
In my scenario the SOAP4R client serializes it OK, but the server throws.
Consider the message :
<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:Header>
<PingHeader env:mustUnderstand="0"
xmlns="http://xmlsoap.org/Ping">Header Header</PingHeader>
</env:Header>
<env:Body>
<Ping xmlns="http://xmlsoap.org/Ping">Bla Bla</Ping>
</env:Body>
</env:Envelope>
The above message is produced by the following snippet using Handler:
class PingClientHeaderHandler < SOAP::Header::SimpleHandler
MyHeaderName = XSD::QName.new("http://xmlsoap.org/Ping", "PingHeader")
def initialize(pingHeader)
super(MyHeaderName)
@pingHeader = pingHeader
@mustunderstand = false
end
def on_simple_outbound
@pingHeader # --- note, not a Hash
end
def on_simple_inbound(my_header, mustunderstand)
end
end
obj = PingPort.new(endpoint_url)
obj.headerhandler << PingClientHeaderHandler.new('Header Header')
Then there is a server part :
class PingServerHeaderHandler < SOAP::Header::SimpleHandler
MyHeaderName = XSD::QName.new("http://xmlsoap.org/Ping", "PingHeader")
def self.create
new
end
def initialize()
super(MyHeaderName)
end
def on_simple_outbound
end
def on_simple_inbound(my_header, mu)
puts "The header #{my_header}"
Thread.current[:pingheader] = my_header
end
end
... that is associated with the server using
add_request_headerhandler(PingServerHeaderHandler )*
I added the quick workaround (check for respond_to?(:to_obj) ) in the
SimpleHandler.on_inbound that looks now like :
def on_inbound(header, mustunderstand)
#h = header.to_obj
h = header.respond_to?(:to_obj) ? header.to_obj : header.to_s
on_simple_inbound(h, mustunderstand)
end
but I'm not sure whether this would be the right place to do the change. It
may be useful to consider adding SOAP::SOAPString.to_obj to be more
specific.
Thanks
emil
*the examples in SOAP4R bundle use old method names - grep for
add_rpc_request_headerhandler in samples/soap/authheader/* - that
method appears to be replaced by add_request_headerhandler.