Waleed
Waleed

Reputation: 554

Soap Client in Perl with authentication for wsdl web service

I am trying to make SOAP client in perl for JAX-WS web service with authentication. I am able to communicate with a service without authentication. But when I try to communicate with the actual web Serivce ( who has authentication ) I get authorization error or soap xml unformated error.

Upvotes: 1

Views: 5822

Answers (1)

Raheel
Raheel

Reputation: 5163

Try this code

my $user="testUser";
my $password="testPassword";

my $service_url='https://api.example.com/services/soap.wsdl';

my $client = SOAP::Lite->service($service_url); 

$client->on_fault(
 sub { # SOAP fault handler
     my $soap = shift;
        my $res = shift;
        # Map faults to exceptions
        if(ref($res) eq '') {
            die($res);
        } else {
            die($res->faultstring);
        }
        return new SOAP::SOM;
 }
);


my @headers = (
    SOAP::Header->name('username')->value($user),

    SOAP::Header->name('password')->value($password),

);

# make the call
my $result = $client->getVersion(@headers);

print $result . "\n\n";

Upvotes: 2

Related Questions