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

**URL:** <https://www.ruby-forum.com/t/re-how-can-i-populate-header-values-in-soap-document/74597>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:49am UTC](https://www.ruby-forum.com/t/re-how-can-i-populate-header-values-in-soap-document/74597 "2006-11-07T10:49:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [November 7, 2006, 10:49am UTC](https://www.ruby-forum.com/t/re-how-can-i-populate-header-values-in-soap-document/74597/1 "2006-11-07T10:49:27Z")

</div>

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(XSD::QName.new(namespace, @@HEADER\_NAME))  
@user\_element = XSD::QName.new(namespace, ‘User’)  
@password\_element = XSD::QName.new(namespace, ‘Password’)  
@username, @password = username, password  
end

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

```

namespace  
# abbreviation, e.g. ‘ns1:UserJohnDoe\</ns1:User\>’  
{@user\_element =\> @username, @password\_element =\> @password}  
end  
end

# … As before …

ws.headerhandler \<\< AutheticationHeaderHandler.new(namespace, user,  
password)

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

Thanks again!

Brian H.
