Here is an excerpt from a Perl Module that SOAP Messages are dispatched to. What you see in the code below is a loop that grabs the SOAP Headers found in a request, and iteratively adds them as SOAP Headers in a response.
The dataof method returns a SOAP::Data object, which of course is problematic in that if we were to add a SOAP::Data element to the response, it would be serialized into the message's Body. Therefore, we bless the object as a SOAP::Header, and presto - it now is serialized properly into the messages Header block.
sub getCatalog {
my $self = shift;
my $envelope = pop;
my $req_hdr = $envelope->match(SOAP::SOM::header)->dataof;
my @res_hdrs;
foreach my $h ( $req_hdr->value ) {
foreach my $name (keys %$h) {
push( @res_hdrs, bless $envelope->match(SOAP::SOM::header."/$name")->dataof, "SOAP::Header" );
}
}
return @res_hdrs, SOAP::Data->name('foo' => 'bar');
}
Comments