How to add a unique headerhandler per service call?

47 views
Skip to first unread message

brian doll

unread,
May 1, 2008, 3:06:18 PM5/1/08
to soap4r
The Setup:
I'm currently using soap4r 1.5.8, ruby 1.8.6 on both Windows and
Linux, to communicate with web services served by Java (Apache Axis).

Right now, I have service calls working well, with our required custom
header, which includes various bits of information about the
requestor.

The service classes (one per wsdl) extend a base class that sets up
the driver with the appropriate information (endpoint, wsdl, etc.).
Since setting up the driver with a wsdl (local or over http) is
expensive, I'm building the service classes as singletons.

A service call, then, may look like this:
FooService.instance.getFoo("bar")

As you may have guessed, I'm appending a custom header on the driver
during the creation of the wsdl driver factory. Since the service
class is a singleton, this is done once, during the initial creation
of the (singleton) object.

The Problem:
The information that makes up our custom header, needs to be distinct
per service request. Each call to the web service should have its
very own header associated to it. I have no problem generating a
header with the unique information each time, but I can't figure out
how best to assure that my SOAP request uses my new header each time.

Many of us seem to be setting up the driver once, and reusing it for
successive service calls. Since the headerhandler is a property of
the driver, it would seem difficult to associate a specific header
with a specific service call.

I thought about opening up SOAP::WSDLDriverFactory (or my extension
of that class, actually) to allow a caller to "reset" the
headerhandler and add a new one in its place. The problem with this
is that, again, this is associated with the driver, and not the
service call. It would be possible then, that two concurrent requests
to the service class would attempt to send messages at the same time,
possibly resulting in the wrong header being associated to a service
call.

So, the short of it being:
Is there any way to associate a new header along with every new
service call to a soap wsdl driver?

Thanks very much for any assistance or thoughts on an approach...
b



brian doll

unread,
May 6, 2008, 8:16:22 PM5/6/08
to soap4r
I suppose it's possible that my use case is not common ;)

If anyone else needs to support unique headers per request (not per
driver), I've written about my (hackish) solution here:
http://emphaticsolutions.com/index.php/2008/05/06/soap-headers-per-request-in-ruby/

Bill Kocik

unread,
May 23, 2008, 11:40:49 AM5/23/08
to soap4r


On May 6, 8:16 pm, brian doll <brian.d...@gmail.com> wrote:
> I suppose it's possible that my use case is not common ;)

It's not that unique - I found this message because I have a need to
do almost exactly the same thing. I'm integrating with Google's
AdSense API, and each call requires that you pass your developer email
address and password, and most requests also require that you pass a
client_id (which is the part that changes with every request).

> If anyone else needs to support unique headers per request (not per
> driver), I've written about my (hackish) solution here:http://emphaticsolutions.com/index.php/2008/05/06/soap-headers-per-re...

Thanks for writing that up. I'm gonna give it a shot myself.

-Bill
Reply all
Reply to author
Forward
0 new messages