2011-04-12 73 views
4

我需要使用Perl進行一些複雜的soap查詢,最好使用SOAP::Lite。我知道這項服務非常活躍,並且已經成功從另一端收回錯誤。這裏是我需要做的肥皂查詢:Perl和複雜的SOAP請求

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
    <GetCategories xmlns="http://webservices.uship.com"> 
     <token>string</token> 
    </GetCategories> 
</soap:Body> 
</soap:Envelope> 

我已經通過谷歌研究過這個無濟於事。

更新:到目前爲止使用的代碼

use SOAP::Lite; 
print SOAP::Lite 
-> uri('webservices.uship.com/uShipsvc.asmx?WSDL';) 
-> proxy('http:/webservices.uship.com') 
-> GetCategories('myToken') 
-> result; 

這將返回

500壞的主機名,500無法連接到:在SOAP2 80(主機名錯誤 '')。 pl line 2

+0

請發佈迄今爲止所提供的代碼,即使它無法正常工作。 – cjm 2011-04-12 15:59:17

+0

'code'use SOAP :: Lite; print SOAP :: Lite - > uri('http://webservices.uship.com/uShipsvc.asmx?WSDL') - > proxy('http:/webservices.uship。'' - > GetCategories('myToken') - > result;'code' – etmooneyha21 2011-04-12 16:58:26

+0

對不起,仍然習慣了stackoverflow,這會返回500個錯誤的主機名,500無法連接到:80(Bad hostname'')at soap2.pl第2行 – etmooneyha21 2011-04-12 16:59:11

回答

3

來自SOAP :: Lite的Getting Started Guide您的代碼應該如下所示:

#!perl -w 
use SOAP::Lite; 
print SOAP::Lite            
    uri('http://www.soaplite.com/Temperatures') 
    proxy('http://webservices.uship.com') 
    GetCategories('string') 
    result; 

在URI插頭爲返回的對象uri()

+0

'code'use SOAP :: Lite; 打印SOAP ::精簡版 - > URI( 'http://webservices.uship.com/uShipsvc.asmx?WSDL') - >代理(的 'http:/webservices.uship.com') - > GetCategories( 'myToken') - > result; 返回500無法連接到:80(Bad hostname'')at soap2.pl line 2 – etmooneyha21 2011-04-12 16:59:52

+1

您必須將Web服務的URL傳遞給'proxy()'。 – 2011-04-12 17:54:15

1

我有問題使SOAP調用,因爲我是說服務器是.NET,這顯然有通信問題,SOAP ::精簡版: http://msdn.microsoft.com/en-us/library/ms995764.aspx#soapliteperl_topic3

即使你的服務器也不是.NET,這是另一種方法,使您的通話(爲我的作品):

# proxy and uri strings should NOT have trialing slashes 
my $_uri = 'http://youruri.com/whatever'; 
my $_proxy = 'http://yourproxy.com/something.asmx'; 
my $methodName = 'GetCategories'; 
my @params = (
     SOAP::Data->name('token'=>'string'), 
); 

my $handle = SOAP::Lite 
    ->uri($_uri) 
    ->proxy($_proxy , timeout => 30, keep_alive => 1) 
    ->on_action(sub{ $_uri . "/" . $_[1] }); 
my $method = SOAP::Data 
    ->name($methodName) 
    ->attr({xmlns => $_uri . "/"}); 
my $rv = $handle->call($method=>@params); 
if($rv->fault()){ 
    print "SOAP Error ($methodName) :: " . $handle->transport()->status() . "\n\t" . $rv->faultcode() . ": " . $rv->faultstring(); 
} else { 
    print $rv->result(); 
} 

另外,看看你對其中一個答案的評論

codeuse SOAP :: Lite;打印SOAP :: Lite - > uri('webservices.uship.com/uShipsvc.asmx?WSDL';) - > proxy('http:/webservices.uship.com') - > GetCategories('myToken') - > 結果;

您可能會反向使用uri和代理。即,代理應該是你的.asmx(沒有「?WSDL」)。如果你想要你的WSDL,這是一個完全不同的連接方法,而不是使用uri + proxy。請參閱:http://guide.soaplite.com/#access%20with%20service%20description%20%28wsdl%29

0

考慮使用SOAP::Trace追查SOAP電話

執行您可以在您的lib /腳本這種使用聲明:

use SOAP::Lite +trace => [qw/ debug method fault /]; 

這可以幫助您調試SOAP電話。

1

你需要糾正你的URIs,http:/webservices.uship.com我得到500 No Host option provided at test-soap.pl line 7。將其更改爲:

use SOAP::Lite; 
print SOAP::Lite 
-> uri('http://webservices.uship.com/uShipsvc.asmx?WSDL') 
-> proxy('http://webservices.uship.com') 
-> GetCategories('myToken') 
-> result;