0

我正在尝试从 Perl 脚本调用 .NET SOAP Web 服务,如下所示。

#!/usr/bin/perl -w
use strict;
use SOAP::Lite 'trace', 'debug';
use Authen::NTLM;
use Data::Dumper;

my $user = '\\username';
my $pass = 'password';
my $host = 'host.example.com:80';

# enable NTLMv2 in Authen::NTLM
ntlmv2(1);


my $soap = SOAP::Lite
    -> uri('http://application.dept.example.com')
    -> proxy('http://host.example.com/app/services/request.asmx', keep_alive => 1, credentials => [$host, '', $user, $pass])
    -> on_action(sub { join '/', 'http://application.dept.example.com', $_[1] })# needed for .NET
    -> readable(1)
    ;

my $som = $soap->GetData(
    SOAP::Data->name(ID => 1234)
);
die $som->faultstring() if defined $som->fault();
my @result = $som->dataof('//GetResponse/GetResult');

foreach my $data (@result) {
    my $item = $data->attr;
    print Dumper($item);
}

但是,当我执行这个脚本时,我得到了这个输出。你会注意到我没有得到任何结果。

SOAP::Transport::HTTP::Client::send_receive: POST http://host.example.com/app/services/request.asmx HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 542
Content-Type: text/xml; charset=utf-8
SOAPAction: http://application.dept.example.com/GetData

<?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>
    <GetData xmlns="http://application.dept.example.com">
      <ID xsi:type="xsd:int">1234</materialID>
    </GetData>
  </soap:Body>
</soap:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Sat, 25 Aug 2012 14:43:05 GMT
Server: Microsoft-IIS/7.5
Content-Length: 367
Content-Type: text/xml; charset=utf-8
Client-Date: Sat, 25 Aug 2012 14:43:03 GMT
Client-Peer: 165.216.6.189:80
Client-Response-Num: 3
Persistent-Auth: true
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetResponse xmlns="http://application.dept.example.com/">
<GetResult />
</GetResponse>
</soap:Body>
</soap:Envelope>

$VAR1 = {};

我已经确认这项服务确实有效——所以问题出在我的脚本上。我对使用 Web 服务非常陌生,因此将不胜感激任何指导。

4

1 回答 1

0

如果查看返回的数据,所引用的节点//GetResponse/GetResult是一个空元素

<GetResponse xmlns="http://application.dept.example.com/">
  <GetResult />
</GetResponse>

所以你的程序正确地找到了元素并且什么也不显示

于 2012-08-25T17:53:57.777 回答