minya has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to call a web service that requires authentication. My XML request looks like this:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:namesp1="http://xml.apache.org/xml-soap" xmln +s:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="htt +p://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schema +s.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSc +hema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encodin +g/"> <SOAP-ENV:Header> <AuthHeader xsi:type="namesp1:SOAPStruct"> <UserName xsi:type="xsd:string">username</UserName> <Password xsi:type="xsd:string">password</Password> </AuthHeader> </SOAP-ENV:Header> <SOAP-ENV:Body> <AddCUSIP xmlns="www.ABSNet.net:AddCUSIP"> <cusip xsi:type="xsd:string">testId</cusip> </AddCUSIP> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
This is almost perfect -- the only problem is the reference to SOAPStruct -- the web service doesn't know what it is. Is it possible to get rid of it somehow? I tried doing the following, but it did not help:
use SOAP::Lite maptype => {};
Thanks, Michael

Replies are listed 'Best First'.
Re: Using SOAP::Lite, is it possible to get rid of SOAPStruct from request header XML
by gellyfish (Monsignor) on Sep 06, 2005 at 19:02 UTC

    It is difficult to be more specific without seeing the code that generated this, but I would suggest setting autotype(0) on your SOAP::Lite object before calling the method in the first place.

    /J\

      Thanks so much -- setting autotype was what I needed. I have another question though.
      my $service = SOAP::Lite->new(uri => $soapaction, proxy => $endpoint); my $header = SOAP::Header->new(uri => 'www.ABSNet.net'); $header->name(AuthHeader => {'UserName' => $username, 'Password' => $p +assword}); $service->autotype(0); $service->on_action(sub { return $ACTION; }); my $response = $service->AddCUSIP(SOAP::Data->name("cusip" => $input), + $header);
      Right now UserName, Password and cusip tags are not prepended with appropriate tags, so to make it work I can manually add "namesp2:" prefixes like this:
      $header->name(AuthHeader => {'namesp1:UserName' => $username, 'namesp1 +:Password' => $password}); my $response = $service->AddCUSIP(SOAP::Data->name("namesp2:cusip" => +$input), $header);
      But my feeling is that there has to be a better way. Thanks...

        You might want to spell out the header explicitly like:

        $service->autotype(0); my $header = SOAP::Header->name(AuthHeader => \SOAP::Header->value( SOAP::Header->name(Username => $username)- +>prefix('mypref'), SOAP::Header->name(Password => $password)- +>prefix('mypref'), ) )->uri('www.ABSnet.net')->prefix('mypref');
        THis appears to create the ehader in the correct form for you.

        /J\