Perl-SOAP::Lite请求未在Axis2上使用正确的值设置xmlns:SOAP

Perl-SOAP::Lite请求未在Axis2上使用正确的值设置xmlns:SOAP,perl,soap,axis2,xml-namespaces,soaplite,Perl,Soap,Axis2,Xml Namespaces,Soaplite,我刚刚使用SOAP::Lite在Perl中创建了一个webservice客户端 我设法很容易地调用Web服务的一个方法,但由于一些未知的原因,它有时有效,有时无效 以下是我的perl客户端代码: my $client = SOAP::Lite->uri("http://loa.webservice") ->service("http://localhost:8888/LogAnalyzerWS/services/DataReceiver

我刚刚使用SOAP::Lite在Perl中创建了一个webservice客户端

我设法很容易地调用Web服务的一个方法,但由于一些未知的原因,它有时有效,有时无效

以下是我的perl客户端代码:

my $client = SOAP::Lite->uri("http://loa.webservice")
                        ->service("http://localhost:8888/LogAnalyzerWS/services/DataReceiver?wsdl");
my $res;
do {
    sleep(2);
    print ("ok \n");
    $res = $client->sendData($data);
}while(!defined $res);

print $res, "\n";
如果结果未定义,我尝试添加while循环来重新发送数据,但它不起作用

在对SOAP::Lite跟踪日志文件进行一些分析之后,我发现在请求期间,一个参数发生了更改

以下是正确的xml soap请求:

<?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"     xmlns:ax21="http://metier.loa/xsd" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns="http://webservice.loa" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Body>
            <ns:sendData>
                <element xsi:type="xs:base64Binary">PD94bWwgdmVyc2lvbj0</element>
            </ns:sendData>
        </soap:Body>
    </soap:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ax21="http://metier.loa/xsd" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns="http://webservice.loa" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <ns:sendData>
            <element xsi:type="xs:base64Binary">PD94bWwgdmVyc2lvbj0</element>
        </ns:sendData>
    </soap:Body>
</soap:Envelope>
对于有故障的一个,它是:

"http://schemas.xmlsoap.org/soap/envelope/"
"http://schemas.xmlsoap.org/wsdl/soap/"

你知道为什么SOAP::Lite会自己更改这个参数吗?

这个问题来自SOAP::Lite处理名称空间的方式。 看见Axis 2正在生成一个wsdl,然后由SOAP::Lite解析,并且SOAP::Lite::Serializer设置的哈希中的xmlns:SOAP值被wsdl解析错误地修改

要解决此问题,请在代码的一开始(在SOAP::Lite中设置wsdl之前)使用此选项:


也可以使用方法envprefix:

$client->envprefix('SOAP-ENV');
此代码适用于我:

use SOAP::Lite +trace => [ qw(debug) ]; # to get all logging without transport messages

my $service = SOAP::Lite->service('https://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx?WSDL');
$service->soapversion('1.1');    
$service->readable(1);
$service->envprefix('SOAP-ENV');
$service->bodyattr({ xmlns => 'http://web.cbr.ru/' });

my $result = $service->GetCursOnDate('2021-02-05T00:00:00');
$SOAP::Constants::PREFIX_ENV = 'SOAP-ENV';
$client->envprefix('SOAP-ENV');
use SOAP::Lite +trace => [ qw(debug) ]; # to get all logging without transport messages

my $service = SOAP::Lite->service('https://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx?WSDL');
$service->soapversion('1.1');    
$service->readable(1);
$service->envprefix('SOAP-ENV');
$service->bodyattr({ xmlns => 'http://web.cbr.ru/' });

my $result = $service->GetCursOnDate('2021-02-05T00:00:00');