Re: How can I populate header values in SOAP document?

I was able to get the namespace abbreviations right by returning a hash
from on_simple_outbound instead of a string, letting the API handle the
conversion to XML.

A handler to add authentication parameters to the SOAP header.

class AutheticationHeaderHandler < SOAP::Header::SimpleHandler
@@HEADER_NAME = ‘WSAuthHeader’
def initialize(namespace, username, password)
super(, @@HEADER_NAME))
@user_element =, ‘User’)
@password_element =, ‘Password’)
@username, @password = username, password

 def on_simple_outbound
   # Seems to result in the creation of elements with the proper

# abbreviation, e.g. ‘ns1:UserJohnDoe</ns1:User>’
{@user_element => @username, @password_element => @password}

… As before …

ws.headerhandler <<, user,

Of course, this could be generalized to handle an arbitrary set of child
data, as in your example below.

Thanks again!

Brian H.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs