微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用带Perl的SOAP调用带参数的函数

我试图通过Perl使用SOAP访问Web服务,并且在调用需要参数的服务函数时遇到问题.决定SOAP调用的XSD说,

<xs:complexType name="getVersion"> 
<xs:sequence/> 
</xs:complexType> 
<xs:complexType name="getVersionResponse"> 
<xs:sequence> 
<xs:element minOccurs="0" name="return" type="xs:string"/> 
</xs:sequence> 
</xs:complexType>
...
<xs:complexType name="enumerateEntities"> 
<xs:sequence> 
<xs:element name="entityId" type="xs:int"/> 
<xs:element minOccurs="0" name="entityType" type="tns:entityType"/> 
</xs:sequence> 
</xs:complexType> 
<xs:complexType name="enumerateEntitiesResponse"> 
<xs:sequence> 
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:int"/> 
</xs:sequence> 
</xs:complexType>

根据服务的文档,这两个函数的签名是:

String getVersion ()
int[] enumerateEntities (int entityId,EntityType entityType)

我可以调用一个函数,它不需要输入参数,使用:

#!/usr/bin/perl

use SOAP::Lite;
my $uri = 'http://wsdl.mydomain.com/';
my $service = SOAP::Lite
 -> uri($uri)
 -> on_action(sub { sprintf '"Call by on_action: %s"',shift})
 -> proxy('http://192.168.1.100:8688/MyService/services/MyService.MyServicePort/');

$method = SOAP::Data->name("MyService")->attr({xmlns => $uri});
$getVersion = SOAP::Data->name("getVersion")->attr({xmlns=>$uri});#line 11
my $theResult = $service->getVersion;

unless ($theResult->fault){ print "Version: "; print $theResult->result;}
else {print $theResult->faultstring;}

…但是我通过更改第11行来调用带参数的函数的尝试(下面)是徒劳的.

...
@entityId = SOAP::Data->type('int')->name('entityId')->value(0);
@entityType = SOAP::Data->type('EntityType')->name('entityType')->value(NODE);
$enumerateEntities = SOAP::Data->name("enumerateEntities",@entityId,@entityType)->attr({xmlns=>$uri});
my $result2 = $service->enumerateEntities;
print $result2->result;

我做错了什么阻止我用参数调用服务的功能

编辑:
这是使用SOAP :: WSDL的更新示例代码

#!/usr/bin/perl

use SOAP::WSDL;
use Data::Dumper;

my $service = SOAP::WSDL->new(
   wsdl => 'http://192.168.1.100:8688/MyService/services/MyService.MyServicePort?wsdl',outputhash => 1
);

解决方法

使用 SOAP::WSDL来使用服务wsdl,它还可以为您提供和(可选)为纯perl数据结构进行编组.强烈推荐的模块.

类似于以下内容

use SOAP::WSDL;
use Data::Dumper;

my $soap = SOAP::WSDL->new(
  wsdl => 'http://server/pathtoservice?WSDL',outputhash => 1
);
my $res = $soap->call('method',{ foo => 1,bar =>2 });
die $res->faultstring if $res->fault;
print Dumper($res->result);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐