Discussion:
SOAP::Lite - getting WSDL using basic authentication
(too old to reply)
J. Gleixner
2008-02-12 21:03:50 UTC
Permalink
I'm trying to find "the" method, using SOAP::Lite or SOAP::Schema,
to get a WSDL that requires HTTP authentication.

The only way I've been able to get a WSDL that requires basic
authentication is by over-riding the SOAP::Schema::access method:

e.g.

use SOAP::Lite;

my $login = 'mylogin';
my $pw = 'mypassword';

my $service = SOAP::Lite
-> service( 'http://some.server.com/some/protected/path/my.wsdl' );
#$service->some_method();

# over-ride method to handle authentication
sub SOAP::Schema::access
{
my $self = shift->new;
my $url = shift || $self->schema_url || Carp::croak 'Nothing to
access. URL is not specified';

my $req = HTTP::Request->new(GET => $url);

# this is why it's over-ridden
$req->authorization_basic($login, $pw);

my $resp = $self->useragent->request($req);
$resp->is_success ? $resp->content : die "Service description '$url'
can't be loaded: ", $resp->status_line, "\n";
}

# and get_basic_credentials for the service calls,
# if they require authentication
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return $login => $pw;
}



In the Changelog for SOAP::Lite it shows:

0.65-beta2 Mon Oct 25 2004
[...]
+ Added SOAP::Schema->useragent - which returns the LWP::UserAgent
instance that will be used when accessing WSDLs via the
SOAP::Lite->service call. This is helpful when access to a WSDL
requires authentication, etc.

Using S::S->useragent() and the additional LWP methods for
authentication, I can GET the WDSL, however I don't see how that
can be used in SOAP::Schema and by SOAP::Lite without over-riding
the access method. Over-riding it does work, but I'm looking for
how it should be done.
John
2008-02-13 15:25:53 UTC
Permalink
Post by J. Gleixner
I'm trying to find "the" method, using SOAP::Lite or SOAP::Schema,
to get a WSDL that requires HTTP authentication.
The only way I've been able to get a WSDL that requires basic
e.g.
use SOAP::Lite;
my $login = 'mylogin';
my $pw = 'mypassword';
my $service = SOAP::Lite
-> service( 'http://some.server.com/some/protected/path/my.wsdl' );
#$service->some_method();
# over-ride method to handle authentication
sub SOAP::Schema::access
{
my $self = shift->new;
my $url = shift || $self->schema_url || Carp::croak 'Nothing to access.
URL is not specified';
my $req = HTTP::Request->new(GET => $url);
# this is why it's over-ridden
$req->authorization_basic($login, $pw);
my $resp = $self->useragent->request($req);
$resp->is_success ? $resp->content : die "Service description '$url'
can't be loaded: ", $resp->status_line, "\n";
}
# and get_basic_credentials for the service calls,
# if they require authentication
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return $login => $pw;
}
0.65-beta2 Mon Oct 25 2004
[...]
+ Added SOAP::Schema->useragent - which returns the LWP::UserAgent
instance that will be used when accessing WSDLs via the
SOAP::Lite->service call. This is helpful when access to a WSDL
requires authentication, etc.
Using S::S->useragent() and the additional LWP methods for
authentication, I can GET the WDSL, however I don't see how that
can be used in SOAP::Schema and by SOAP::Lite without over-riding
the access method. Over-riding it does work, but I'm looking for
how it should be done.
Hi
I appreciate that WDSL and SOAP are not the same thing, but the following
may help.
I've cut and pasted from our site.
Regards
John



sub new {
# constructor always called new
my $type=shift;
my $self={};
$self->{USERNAME}='hallo';
$self->{PASSWORD}='goodbye';
$self->{NAMESPACE}='http://webservices.example.com';
$self->{ENDPOINT}='https://example.com/B2BGateway/service/XMLSelect';
return bless $self,$type
}

# ------------------------------------------------------------------------------------------

sub connect_Server {
my $self=shift; # grab the 'self' pointer to this object
use Compress::Zlib;
use SOAP::Lite +trace => 'debug';
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{return $self->{USERNAME} => $self->{PASSWORD}}
return
}

# ------------------------------------------------------------------------------------------
Loading...