我個人發現我更喜歡用SOAP::Data::Builder
來構建SOAP :: Data,然後將它傳遞給SOAP :: Lite。
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use SOAP::Lite +trace => [ 'debug' ];
use SOAP::Data::Builder;
my $req1 = SOAP::Lite->new(
readable => 1,
autotype => 0,
proxy => 'https://example.com/mysoapuri',
);
my $sb = SOAP::Data::Builder->new;
$sb->autotype(0);
$sb->add_elem(
name => 'clientLibrary',
value => 'foo',
);
$sb->add_elem(
name => 'clientLibraryVersion',
value => 'bar',
);
$sb->add_elem(
name => 'clientEnvironment',
value => 'baz',
);
my $ret = $req1->requestMessage($sb->to_soap_data);
這會產生以下SOAP
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<requestMessage>
<clientLibrary>foo</clientLibrary>
<clientLibraryVersion>bar</clientLibraryVersion>
<clientEnvironment>baz</clientEnvironment>
</requestMessage>
</soap:Body>
</soap:Envelope>
注:我意識到,加入另一依賴可能不是在打牌...不幸的是我從來沒有真正想通了是怎麼回事,讓我數據權利。