I can see that this generates methods for each defined operation, and I
use them thusly:
ws.WSGetResults(:maxRecords => 1, …)
The method and parameters are translated to the appropriate XML in the
SOAP message body. However, some operations require a ‘User’ and
‘Password’ to be in the message header. I’ve looked through the
documentation and mailing lists with no luck. How can one achieve this?
ws =
SOAP::WSDLDriverFactory.new(‘http://foo.com/foo.wsdl’).create_rpc_driver
ws.generate_explicit_type = true
r = ws.WSHeartbeat({}) # Works because it doesn’t require authentication
r = g.WSGetXmlResults(:recordId => 123, :recordLimit => 200) # Doesn’t
work
---- Example SOAP request, according to vendor ----
This email may contain confidential material.
If you were not an intended recipient,
Please notify the sender and delete all copies.
We may monitor email to and from our network.
I’m not sure if it can be done dynamically, but you can create a
ClientSimpleHeader which hooks into the inbound and outbound stream.
I’ve only hooked into the outbound and it looked something like the code
below.
The code is untested and extrapolated from my case to yours, so take the
general idea and see where it gets you.
And if you didn’t know, driver.wiredump_dev is your friend.
class CustomSimpleHeader < SOAP::Header::SimpleHandler
# encapsulate outbound only headers, this is set once and never
# touched again.
#
def initialize(itemname,namespace,childdata)
super(XSD::QName.new(namespace,name))
case childdate
# other classes if you want
# Or do something with XML::Mappging
when Hash
xml = StringIO.new
childdata.each_pair do |key,value|
xml.puts("<#{key}>#{value}</#{key}>")
end
@item = xml.string
else
@item = childdata.to_s
end
end
def on_simple_outbound
@item if @item
end
def on_simple_inbound
end
end
---- possible soaptest.rb -----
require ‘customer_header’