2011-11-08 23 views
1

我有一個問題,使用Perl傳遞一個字符串參數。下面的代碼肥皂精簡傳遞字符串參數

#!/usr/bin/perl -w 
use SOAP::Lite; 
my $service = SOAP::Lite->service('http://localhost:8080/greeting?wsdl'); 
print $service->greetClient('perl wooooo'), "\n"; 

結果

問候!有一個愉快的一天......

類似的Python代碼

from suds.client import Client 
client = Client('http://localhost:8080/greeting?wsdl') 
print client.service.greetClient('python wooooo') 

作品完美

問候蟒蛇WOOOOO!有一個愉快的一天......

我試圖設置不同的編碼

print $service->encoding('utf-8')->greetClient("perl wooooo"), "\n"; 

具有相同的結果。

一個SOAP監視器顯示有在Perl

<greetClient xsi:nil="true" xsi:type="tns:greetClient" /> 

的情況下,沒有爲arg0這是目前在Python

<ns0:greetClient> 
    <arg0>python wooooo</arg0> 
</ns0:greetClient> 

的情況下,可以採取什麼問題嗎?

爲什麼使用Perl與Python相比實現SOAP客戶端如此複雜?

編輯: SOLUTION

最後下面的解決方案正在

#!/usr/bin/perl -w 
use strict; 
use warnings; 
use XML::Compile::SOAP11; 
use XML::Compile::WSDL11; 
use XML::Compile::Transport::SOAPHTTP; 

my $soap = XML::Compile::WSDL11->new('c:/temp/greeting.wsdl'); 
my $call = $soap->compileClient('greetClient'); 
print $call->(arg0 => 'perl wooooo'){'greetClientResponse'}{'return'}, "\n"; 

回答

1

SOAP::Lite可以僵硬不好。您可能會給XML::Compile::SOAP一試:

use strict; 
use warnings; 
use XML::Compile::SOAP11; 
use XML::Compile::WSDL11; 
use XML::Compile::Transport::SOAPHTTP; 

my $soap = XML::Compile::WSDL11->new(
    'http://localhost:8080/greeting?wsdl', 
    schema_dirs => [ 
     'c:/soft/Perl/site/lib/XML/Compile/SOAP11/xsd' 
     'c:/soft/Perl/site/lib/XML/Compile/XOP/xsd' 
     'c:/soft/Perl/site/lib/XML/Compile/xsd' 
    ] 
); 
$soap->compileCalls; 
my ($response, $trace) = $soap->call('greetClient', arg0 => 'perl wooooo'); 
$trace->printResponse; 

$response將通過XML::Simple轉換爲hashref呼叫響應,這可能是你所需要的。 $trace對象可以方便地查看原始XML響應的外觀。

+0

感謝您的回答。我不是Perl專家。我在這裏找到了SOAP :: WSDL http://search.cpan.org/~mkutter/SOAP-WSDL-2.00.10/。我該如何安裝它? ppm不顯示在列表中? –

+0

我正在使用Windows和Perl Build.PL不工作,因爲它尋找gcc和其他東西。理想情況下,我想像我對SOAP:Lite使用ppm一樣安裝包。 –

+0

對不起,只是藉此機會發佈'SOAP :: Lite'。也許'SOAP :: WSDL'不適用於ActivePerl。你看到'XML :: Compile :: SOAP'嗎?如果有的話,我會更新我的答案。 –

1

不幸的是,我看不到你的WSDL。

但是對於SOAP :: Lite,我沒有看到你既沒有設置proxy(端點)也沒有設置uri

你也可能不得不改變on_action的行爲。默認情況下,SOAP::Lite想要使用'#'連接。

所以沿着這些線可能會起作用。

$service->proxy($uri_of_my_end_point); 
$service->uri($schema_namespace); 
$service->on_action(sub { 
    my ($uri, $method) = @_; 
    my $slash = $uri =~ m{/$} ? '' : '/'; 
    return qq{"$uri$slash$method"}; 
});