Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Soap::Lite Authentication

by Anonymous Monk
on May 16, 2006 at 20:50 UTC ( [id://549890]=perlquestion: print w/replies, xml ) Need Help??

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

The soap service that I'm trying to connect to has implemented a username and password layer:
<soap:Header> <AuthenticationHeader xmlns=""> <username>string</username> <password>string</password> </AuthenticationHeader> </soap:Header>
I've got working c# (shudder) code:
DataSet ds = new DataSet(); theGeoData.AuthenticationHeader auth = new theGeoData.Authenticati +onHeader(); theGeoData.GetData theAd = new theGeoData.GetData(); auth.username = "user"; auth.password = "pass"; theAdds.AuthenticationHeaderValue = auth; ds = theAdds.GetIt();
But my perl code won't authenticate, in fact I get nothing back. I've tried passing the user:pass in the url, and I've tried it with the Transport sub. My code is below. I keep getting the error "Can't call method "GetData" on an undefined value"
sub SOAP::Transport::HTTP::Client::get_basic_credentials { return 'username' => 'user'; return 'password' => 'pass'; }
-> service('http://user:pass@server/GetData.asmx?WSDL');
My soap code:
eval { $service = SOAP::Lite -> service('http://server/GetData.asmx?WSDL'); }; #|| ($_); # $@ will have the error message, perldoc -f eval $service -> GetData(); my $som = $service -> call || &soapGetBad();

Replies are listed 'Best First'.
Re: Soap::Lite Authentication
by Thelonius (Priest) on May 17, 2006 at 01:30 UTC
    The most important thing here is that you're not checking $@. Using eval and then throwing away $@ means you've lost the most important clue as to what's going on!

    It looks like the service is not using basic authentication, but Soap Header authentication.

    I think the code is going to look something like this:

    use SOAP::Lite; use strict; my $service = SOAP::Lite -> service('http://server/GetData.asmx?WSDL'); my $AuthHeader = SOAP::Header->new( name =>'AuthenticationHeader', attr => { xmlns => "" }, value => {username => 'user', password => 'pass' }, ); my $result = $service->GetIt($AuthHeader);
    Without seeing the WSDL, I can't be sure--not that I'm a SOAP expert.
      Hi, If i want to pass both Header and body to an webservice how do i do that.

        Odd question since that is what all the SOAP:: modules are there to do, pass both header and body ... a proper SOAP request, so you don't have to reinvent any wheels. Use SOAP::Simple or its daddy XML::Compile

Re: Soap::Lite Authentication
by borisz (Canon) on May 16, 2006 at 22:41 UTC
    sub SOAP::Transport::HTTP::Client::get_basic_credentials { return username => 'password'; }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://549890]
Approved by wazoox
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-07-23 09:51 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.