views:

326

answers:

1

I've created a driver from wsdl

When I invoke my request, I would like the header to contain an element, i.e, I want to see something like the following:

REPLACE_WITH_ACTUAL blah blah blah

However, looking around, everyone talks about subclassing SOAP::Header::SimpleHandler and then injecting an instance into the driver.headerhandler

However, if I do that, then I end up with a nested header, i.e, REPLACE_WITH_ACTUAL

So there must be a way to just add an element to the existing headerhandler so I can do something like

driver.headerhandler.AddElement("session", "123")

but I can't find any way to do that. I also tried things like

driver.headerhandler["session"]="123" and other such tricks, but I can't find any way to make this work.

Looking at driver.headerhandler.methods, I cannot see any obvious mechanism.

Would really appreciate a pointer to how to to this.

+1  A: 

Well, a colleague in my team solved the problem above after looking at some of the typical examples that I had previously found including the one at http://dev.ctor.org/soap4r/browser/trunk/sample/soapheader/authheader/client2.rb

Turns out that the trivial (sigh) solution is to replace

def on_simple_outbound
  if @sessionid
     { "sessionid" => @sessionid }
  end
end

with

def on_simple_outbound
  if @sessionid
     @sessionid
  end
end

Now, if you just name the header "session" (in the QName creation), you get the unnested header, exactly what I wanted.

I thought I'd paste my solution to my own problem on the assumption that others might be running into the same problem.