[Xml-compile] Custom SOAP11 header

Mark Overmeer mark at overmeer.net
Mon Nov 8 09:21:47 GMT 2010


* Kaare Rasmussen (kaare at jasonic.dk) [101108 09:49]:
> Hi
> 
> > I have just started XML::Compile::SOAP::FAQ, because your question
> > is quite common. This is the text for this subject:
> 
> Could you spell this out, please. How will this add a header field?

  ??? The example shows how to add these header fields:

   $op->addHeader(INPUT => "myprefix_$fieldname"
      => "{$my_ns}$fieldtype");

  ??? can I be more specific than this?

The "{$my_ns}$fieldtype" is the element which you want to have added
to the header.  The "myprefix_$fieldname" is the key you want the
caller to use to fill this header.

> > With C<soap11ClientWrapper()> and C<soap11HandlerWrapper()>
> 
> If I need to define these methods,  shaped after XML::Compile::SOAP::WSA, how 
> do I fit the header message into the chain?

Do you want to fill-in default values or information from other resources
than the client interface?  In that case you can add that here. However,
if you do not implement these wrappers, you can simply do

  my $call = $wsdl->compileClient('xyz');
  my $answer = $call->(@data, "myprefix_$fieldname" => $somevalue);

In your case, you need a little extra's. Your $somevalue is a node
with two childs: username, password. Which means that you have to
create a complex structure...

Four ways to tackle that

  1) create an element by hand. In XML::Compile, you can always pass
     a fully prepared XML::LibXML::Element or ::Attribute in stead of
     plain values. However: be careful with namespaces and there is no
     validation/formatting support.

     my $doc = XML::LibXML::Document->new('1.0', 'UTF-8);
     my $auth = $doc->createElementNS($ns, ...);
     my $user = $doc->createElementNS($ns, 'Username');
     $user->appendText($username);
     my $password = $doc->createElementNS($ns, 'Password');
     $password->appendText($password);
     $auth->appendChild($user);
     $auth->appendChild($password);

     my $answer = $call->(_doc => $doc, "myprefix_$fieldname" => $auth
       , @other_data);

 2) the logic of (1), but hidden in soap11ClientWrapper(), such that
    the call can simply be

     my $answer = $call->(user => $user, password => $pwd, @other_data);

    (or even the user and password passed to the extension layer
    some other way)

 3) have a nice schema defining the header element. Then

     my $doc  = XML::LibXML::Document->new('1.0', 'UTF-8);
     my $auth = $wsdl->writer("{$my_ns}$fieldtype")
          ->($doc, Username => $user, Password => $pwd);

     my $answer = $call->(_doc => $doc, "myprefix_$fieldname" => $auth);

 4) the creation of the $auth node like (3) in soap11ClientWrapper()
-- 
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