tags:

views:

305

answers:

3

I'm struggling to get SOAP working in perl.

In PHP it works perfectly, and without any trouble. And now I'm trying to do the same thing in Perl.

The functional PHP is:

$client = new SoapClient("http://thirdpartyurl.com/api.aspx?WSDL");
$info = $client->GetSomeInfo(array('username' => 'myusername', 'password' => 'mypassword'));

Which works great, but I just can't get it working in perl. I tried SOAP::Lite, but didn't make any progress. And I'm now trying SOAP::WSDL:

use SOAP::WSDL;
my $wsdl = SOAP::WSDL->new(wsdl => 'http://thirdpartyurl.com/api.aspx?WSDL');
my $info = $wsdl->call('GetSomeInfo', 'username', 'myusername', 'password', 'mypassword');

Which just doesn't work. I looked at the raw requests, and the perl version isn't even sending the user/pass parameters through. What am I doing wrong?

A: 

When I want to do SOAP, I reach for XML::Compile.

brian d foy
A: 

I've had pretty good luck with SOAP::Lite in my applications. The username/password combo, is that supposed to be authenticating at the HTTP layer or the SOAP layer? Or just regular soap parameters?

Aquatoad
+1  A: 

For what it's worth, I achieved authentication, and managed to get parameters sent by using the following:

use SOAP::Lite;
my $service = SOAP::Lite->proxy($service_url)->uri($service_url);

sub SOAP::Transport::HTTP::Client::get_basic_credentials {
    return 'myusername' => 'mypassword';
}

my $result = $service->insert(
    SOAP::Data->name(
        'data' => \SOAP::Data->value(
            SOAP::Data->name(
                'item' => \SOAP::Data->value(
                    SOAP::Data->name('key' => 'name'),
                    SOAP::Data->name('value' => 'new_campaign_x')
                )
            )
        )
    )->type('Map')
);

Is there a better way to achieve the same results? I realise overwriting 'get_basic_credentials' is a bit hacky.

aidan