View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Mark Overmeer > XML-Compile-SOAP-2.38 > XML::Compile::Transport



Annotate this POD


Open  2
View/Report Bugs
Module Version: 2.38   Source   Latest Release: XML-Compile-SOAP-3.24


XML::Compile::Transport - base class for XML transporters


   is a XML::Compile::SOAP::Extension

 XML::Compile::Transport is extended by


 use XML::Compile::Transport::SOAPHTTP;
 my $trans  = XML::Compile::Transport::SOAPHTTP->new(...);
 my $call   = $trans->compileClient(...);

 my ($xmlout, $trace) = $call->($xmlin);
 my $xmlout = $call->($xmlin);   # when no trace needed


This module defines the exchange of (XML) messages. The module does not known how to parse or compose XML, but only worries about the transport aspects.

On the moment, there are two transporter implementations:


implements an synchronous message exchange; the library waits for an answer before it returns to the user application. The information is exchanged using HTTP with SOAP encapsulation (SOAP also defines a transport protocol over HTTP without encapsulation)


This requires the installation of an additional module. The user provides a callback to handle responses. Many queries can be spawned in parallel.

See documentation in the base class.


See documentation in the base class.


See documentation in the base class.

 -Option --Default
  address  'http://localhost'
  charset  'utf-8'
address => URI|ARRAY-of-URI

One or more URI which represents the servers.

charset => STRING


See documentation in the base class.

$obj->wsdl11Init(WSDL, ARGS)
XML::Compile::Transport->wsdl11Init(WSDL, ARGS)

See "WSDL11" in XML::Compile::SOAP::Extension


See documentation in the base class.

$obj->soap11ClientWrapper(OPERATION, CALL, ARGS)

See "SOAP11" in XML::Compile::SOAP::Extension

$obj->soap11HandlerWrapper(OPERATION, CALLBACK, ARGS)

See "SOAP11" in XML::Compile::SOAP::Extension

$obj->soap11OperationInit(OPERATION, ARGS)
XML::Compile::Transport->soap11OperationInit(OPERATION, ARGS)

See "SOAP11" in XML::Compile::SOAP::Extension



Get a server address to contact. If multiple addresses were specified, than one is chosen at random.


Returns a list of all server contact addresses (URIs)


Returns the charset to be used when sending,



Compile a client handler. Returned is a subroutine which is called with a text represenation of the XML request, or an XML::LibXML tree. In SCALAR context, an XML::LibXML parsed tree of the answer message is returned. In LIST context, that answer is followed by a HASH which contains trace information.

 -Option    --Default
  hook        <undef>
  kind        'request-response'
  xml_format  0
hook => CODE

See section "Use of the transport hook" in DETAILS. When defined, the hook will be called, in stead of transmitting the message. The hook will gets three parameters passed in: the textual representation of the XML message to be transmitted, the trace HASH with all values collected so far, and the transporter object. The trace HASH will have a massive amount of additional information added as well.

You may add information to the trace. You have to return a textual representation of the XML answer, or undef to indicate that the message was totally unacceptable.

kind => STRING

Kind of communication, as defined by WSDL.

xml_format => 0|1|2

[2.26] See XML::LibXML::Document subroutine toString. With '1', you will get beautified output.


Use of the transport hook

A transport hook can be used to follow the process of creating a message to its furthest extend: it will be called with the data as used by the actual protocol, but will not connect to the internet. Within the transport hook routine, you have to simulate the remote server's activities.

There are two reasons to use a hook:


You want to fake a server, to produce a test environment.


You may need to modify the request or answer messages outside the reach of XML::Compile::SOAP, because something is wrong in either your WSDL of XML::Compile message processing.

XML and Header Modifications

Some servers require special extensions, which do not follow any standard (or logic). But even those features can be tricked, although it requires quite some programming skills.

The transport_hook routine is called with a $trace hash, one of whose entries is the UserAgent which was set up for the data transfer. You can modify the outgoing message XML body and headers, carry out the data exchange using the UserAgent, and then examine the returned Reponse for content and headers using methods similar to the following:

 sub transport_hook($$)
 {   my ($request, $trace) = @_;
     my $content = $request->content;

     # ... modify content if you need
     my $new_content = encode "utf-8", $anything;
     $request->header(Content_Length => length $new_content);
     $request->header(Content_Type => 'text/plain; charset="utf-8");

     # ... update the headers
     $request->header(Name => "value");

     # sent the request myself
     my $ua = $trace->{user_agent};
     my $response = $ua->request($request);

     # ... check the response headers

     # ... use the response content
     my $received = $response->decoded_content || $response->content;


You should be aware that if you change the size or length of the content you MUST update the Content-Length header value, as demonstrated above.

Transport hook for debugging

The transport hook is a perfect means for producing automated tests. Also, the XML::Compile::SOAP module tests use it extensively. It works like this (for the SOAPHTTP simluation):

 use Test::More;

 sub fake_server($$)
 {  my ($request, $trace) = @_;
    my $content = $request->decoded_content;
    is($content, <<__EXPECTED_CONTENT);

    HTTP::Response->new(200, 'Constant'
      , [ 'Content-Type' => 'text/xml' ]
      , <<__ANSWER

Then, the fake server is initiated in one of the follow ways:

  my $transport = XML::Compile::Transport::SOAPHTTP->new(...);
  my $http = $transport->compileClient(hook => \&fake_server, ...);
  $wsdl->compileClient('GetLastTracePrice', transporter => $http);


  my $soap = XML::Compile::SOAP11::Client->new(...);
  my $call = $soap->compileClient(encode => ..., decode => ...,
      transport_hook => \&fake_server);


  my $wsdl = XML::Compile::WSDL11->new(...);
      transport_hook => \&fake_server);


See documentation in the base class.

Helpers ^


Declare an transporter type.


This module is part of XML-Compile-SOAP distribution version 2.38, built on August 22, 2013. Website:

Other distributions in this suite: XML::Compile, XML::Compile::SOAP, XML::Compile::SOAP12, XML::Compile::SOAP::Daemon, XML::Compile::SOAP::WSA, XML::Compile::C14N, XML::Compile::WSS, XML::Compile::WSS::Signature, XML::Compile::Tester, XML::Compile::Cache, XML::Compile::Dumper, XML::Compile::RPC, XML::Rewrite and XML::LibXML::Simple.

Please post questions or ideas to the mailinglist at . For live contact with other developers, visit the #xml-compile channel on


Copyrights 2007-2013 by [Mark Overmeer]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See

syntax highlighting: