2012-08-25 102 views
0

我試圖從Perl腳本中調用.NET SOAP Web服務,如下所示。在Perl中使用.NET Web服務使用NTLM身份驗證

#!/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 = {}; 

我確定這個服務的確的確工作 - 所以問題出在我的腳本上。我對使用網絡服務非常陌生,所以任何指導將不勝感激。

回答

0

如果你看一下返回的數據,通過//GetResponse/GetResult提到的節點是一個空元素

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

使你的程序是正確找到的元素,並顯示沒有

相關問題