Before I start I’d like to thank the SOAP4R Group for giving me a helping hand.
So we’ve got to access a SOAP interface from Ruby. Ruby’s built in library is OK but updating the library (which is an old version of the SOAP4R library) will give you some bug fixes and more features as you’d expect.
You can download the Gem from here: Link That page contains a few links to more help on SOAP4R.
From ground up following this guide (I wont rewrite mark Thomas’ guide it’s pretty concise) I chose the “Generate classes from WSDL”. It’s just a bit more convenient and you can see which methods you can run.
So you’ll hopefully end up with file such as
- DefaultClient.rb
- default.rb
- defaultDriver.rb
- defaultMappingRegistry.rb
You’ll need 2 more files. I’ve called them main.rb & soapAuthentication.rb. Extracting the Authentication header extension out to it’s own file:
require 'soap/header/simplehandler'
class SoapAuthHeader < SOAP::Header::SimpleHandler
NAMESPACE = 'http://namespace'
DIGEST = 'digest'
ENCODING = 'none'
SIGNATURE = 'signature'
def initialize()
super(XSD::QName.new(NAMESPACE, 'Trust'))
end
def on_simple_outbound
{
"Encoding" => ENCODING,
"Digest" => DIGEST,
"Signature" => SIGNATURE
}
end
end
The above code adds Encoding, Digest and a Signature to the header when sending the SOAP envelopes. So for example on outbound it now adds:
<env:Header>
<n1:Trust xmlns:n1="http://questionmark.com/QMWISE/" env:mustUnderstand="0">
<n1:Signature>9354A730B02651997F02ED97BEA3B439</n1:Signature>
<n1:Digest>8C6504C136A975BBFC420499B4444BC3</n1:Digest>
<n1:Encoding>none</n1:Encoding>
</n1:Trust>
</env:Header>
Within main.rb I’ve got
require ‘defaultDriver.rb’
require ‘soapAuthentication.rb’
## Create SOAP Driver
wsdl = “your WSDL location”
obj = DefaultSOAP.new()
obj.wiredump_dev = STDERR if $DEBUG #add some debugging to the command line
trust = SoapAuthHeader.new #create a new authentication header
obj.headerhandler << trust #adds the header to outbound envolopes
If you’ve found this useful (or wrong) leave me a comment.