[Xml-compile] newbie question regarding headers and envelopes

Mark Overmeer mark at overmeer.net
Thu Jul 16 07:42:22 GMT 2009


* Nicholas 'Techno-Viking' Wehr (nwehr at divxcorp.com) [090715 23:00]:
> attached is the php library

This uses a hack:

  private function _addCredentialsInHeader() {
     $authCred = new Credentials($this->_providerName,$this->_providerPassword);
     $authCredEnc = new SoapVar($authCred, SOAP_ENC_OBJECT,null
       ,$myuri,"wsp:Credentials");
     $provCred = new ProviderCredentials($authCredEnc);
     $provCredEnc = new SoapVar($provCred, SOAP_ENC_OBJECT,null
       ,$myuri,"wsp:ProviderCredentials");
     $header = new SoapHeader($myuri,
        "ProviderCredentials", $provCredEnc, false);
     $this->_client->__setSoapHeaders($header);
  }

  /**
   * Credentials Class Definition
   * @package User_Domain_Mgt_API_and_Samples
  */
  class Credentials {
        function __construct($ProviderName, $Password){
                $this->ProviderName = $ProviderName;
                $this->Password = $Password;
        }
  }

  /**
   * ProviderCredentials Class Definition
   * @package User_Domain_Mgt_API_and_Samples
  */
  class ProviderCredentials {
          function __construct($Credentials){
                  $this->Credentials = $Credentials;
        }
  }

Although I cannot find the spot where they define the wsp namespace.

Two days ago, Allan showed an example on this same list, how to work
with wssecurity in the header.  The example accidentally had been removed
from the distribution (will be added for the next release).  See
http://cpansearch.perl.org/src/MARKOV/XML-Compile-SOAP-0.78/examples/wssecurity/security.pm

In that example, Allan uses real schema's to produce a validated header.
>From your examples, I think that there is no real schema.  Still the last
paragraph holds:

  my ($result, $trace) = $call->(
    header => { $UsernameToken_element => $UsernameToken_value },
    # rest of arguments
 );  

The SOAP "header" type contains an "any", which means that XML::Compile
accepts    $type => $node   pairs in the HASH.  Without schema, you
can still produce the $node yourself
   my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
   my $node = $doc->createElement('wsp:something' => $value);
   my $type = pack_type $wsp_namespace, $element_name;

   my ($result, $trace) = $call->(
      header => { $type => $node }, # body arguments
    );  

To get the $wsp_namespace declaration with the "wsp" prefix, do:
   $wsdl->prefixes(wsp => $wsp_namespace);

Something like that.
-- 
success,
               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