Perl:无法将xml数据发布到Web服务

时间:2013-06-19 07:28:23

标签: web-services perl soap

Web服务接受xml数据并再次以xml形式返回值。我试图将xml数据发布到Web服务,没有任何成功,我需要使用Perl来做。以下是我尝试的代码:

use SOAP::Lite ;
my $URL = "http://webservice.com:7011/webServices/HealthService.jws?WSDL=";
my $xml_data = '<Request>HealthCheck</Request>' ;
my $result = SOAP::Lite -> service($xml_data);
print $result ;

我尝试了另一种代理方法:

use SOAP::Lite +trace => 'debug';
my $URI = 'webServices/HealthService' ;
my $URL = "http://webservice.com:7011/webServices/HealthService.jws?WSDL=" ;
my $test = SOAP::Lite -> uri($URI) 
                      -> proxy($URL) ;
my $xml_data = '<Request>HealthCheck</Request>' ;
my $result = $test -> healthRequest($xml_data);
print $result ;

然而,这会引发以下错误:

Can't locate class method "http://webservice.com:7011/healthRequest" via package "SOAP::Lite\" at 7.pl line 4. BEGIN failed--compilation aborted at 7.pl line 4.

webservice只提供一种方法HealthRequest。我不确定为什么要在SOAP:Lite中找出类方法。我对这两种方法都有同样的错误。

使用Perl还有其他方法可以实现吗?

2 个答案:

答案 0 :(得分:0)

尝试这样的事情,我没有测试过,所以只测试一下,看看会发生什么,至少你不应该得到PM错误。

 use strict;
 use SOAP::Lite;
 my $xml_data = '<Request>HealthCheck</Request>' ;
 my $soap = SOAP::Lite       
     ->uri("webServices/HealthService")
     ->proxy("http://webservice.com:7011/webServices/HealthService.jws?WSDL=");
     print $soap->service($xml_data),"\n";

答案 1 :(得分:0)

如果您想自己创建XML而不是将该任务委托给SOAP::Lite,则需要让SOAP::Lite知道您在做什么:

$soap = SOAP::Lite->ns( $URI )->proxy( $URL );
$soap->HealthCheck( SOAP::Data->type( xml => $xml_data ) );

但我怀疑,这将与您的XML一起使用。

如果您的请求确实没有可变参数,则可能有效:

$soap = SOAP::Lite->ns( $URI )->proxy( $URL );
$soap->HealthCheck;

PS:您确定您的Web服务是SOAP服务吗?