How do I add an attribute to a SOAP header with Savon?

1.4k views Asked by At

I need to add this attribute (xmlns:wsa="http://www.w3.org/2005/08/addressing") to the soap header, like this:

<env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
</env:Header>

How do I do this, using Savon?

3

There are 3 answers

2
Magne On BEST ANSWER

I was actually able to make another workaround to the problem in my case, since my endpoint would accept this:

<env:Header>
  <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">value</wsa:Action>
</env:Header>

Investigating the original question, here's the response from the Savon creator:

"hey magne,

looking at the code which creates the header and body tags, it doesn't seem possible to add any attributes/namespaces without monkey-patching right now:

https://github.com/rubiii/savon/blob/v0.9.7/lib/savon/soap/xml.rb#L151

if you still need this feature, please open a ticket and i'll see what i can do: https://github.com/rubiii/savon/issues

i'm currently very involved in taking a new approach to improve the library, so i'm not sure when i'll be able to solve your problem. but ... i hacked together a small monkey-patch that should help until this feature is implemented:

https://gist.github.com/1698636

cheers, daniel"


1
Steffen Roller On

You can add your own namespace to the request like this:

resp = client.request :soap_action do
    soap.namespace['xmlns:wsa'] = 'http://www.w3.org/2005/08/addressing'
end
1
chuck son On

foo = client.request do soap.header['xmlns:wsa'] = 'http://www.w3.org/2005/08/addressing' end