[Xml-compile] Using XML::Compile::WSDL with a session ID

Mark Overmeer mark at overmeer.net
Tue Jul 21 07:16:39 GMT 2009


* John Smith (josm911 at gmail.com) [090721 03:06]:
> The problem is that, as I understand it, compileClient() is a "heavy"
> operation, and I'd rather not have to recompile the client every time
> I need to start a new session (they expire every ten min).

"compile()" is the expensive part of the message processing, but nothing
compared to the initiation of the schema's.  Still, it should be avoided
to compile often.  In my idea, every 10 minutes is not "often", so I
wouldn't care.

> If anyone has any ideas at all,
> 
> my $call = $wsdl->compileClient(
>     operation => 'FooBar',
>     endpoint => "https://foo.com/bar;sessionid=" . $session_id,
> );
> my ($answer, $trace) = $call->(foo => 'bar');

In the normal situation the endpoint will not change, because that
would mean that the connection has to be rebuilt.  This case is rather
unusual. SOAP has its header where you can add such a session-id.

1)
XML::Compile::Transport::SOAPHTTP reuses the same HTTP::Request object
all the time.  You can get your hands at this object after the first
call via the trace object:
  my $req = $trace->request;
  $req->uri($new_endpoint);   # every 10 minutes

2)
An other trick I can think of, is to pass a tied endpoint value,
connected to some object which stringifies to the actual value.
Quite straight-forward and clean, but not 100% sure that this
will work.

3)
A third option would be to compile with an explicit transporter. Either
   my $http = XML::Compile::Transport::SOAPHTTP->new(@options);
   my $send = $http->compileClient(address => $endpoint);
   my $ua   = $http->userAgent;
or
   my $ua   = LWP::UserAgent->new(...);
   my $http = XML::Compile::Transport::SOAPHTTP->new(user_agent => $ua);
   my $send = $http->compileClient(address => $endpoint);
and then
   my $call = $wsdl->compileClient
    ( operation => 'some-port-name'
    , transport => $send
    );
   my ($xmlout, $trace) = $call->($xmlin);

Via the $ua object, you have interfere in the sending process:
   $ua->add_handler(request_preprepare => ...);
   $ua->add_handler(request_prepare => ...);

Never tried it, but may work as well...

Let me hear what works for you.
-- 
Regards,

               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list