我正在使用 perl soap::lite 来构建 Web 服务客户端。该实现适用于简单的方法,例如需要单个标量参数。EG,以下工作正常。
#!/usr/bin/perl
use warnings;
use SOAP::Lite +trace=>debug;
use strict;
use Data::Dumper;
$SOAP::Constants::PREFIX_ENV = 'SOAP-ENV';
my $base="https://XXXX:60001/GDBIncidentWebService/Config?wsdl&style=rpc";
my $user="XXXX";
my $pwd="XXXX";
my $lite = SOAP::Lite -> readable(1)
-> service($base) ;
my @res=$lite->readIncident("123456");
print Dumper(\@res);
exit;
sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $user => $pwd ; }
我需要调用一个方法,该方法需要一组更复杂的参数(几个标量加上一个键值对数组)。我想我应该使用 SOAP::Data 模块来正确序列化我的数据,但无法让它工作。即使是“简单”的方法(如上面的方法)似乎也不起作用。EG(仅显示从上面脚本更改的行):
my $arg= SOAP::Data->new()->type('xs:string')-> value("20054106");
my @res=$lite->readIncident($arg);
产量:
String value expected instead of SOAP::Data reference
关于如何解决这个问题的任何想法?非常感谢 !这里的参考是我的脚本中调用的方法的 wsdl
<wsdl:operation name="readIncident">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal" namespace="urn:GDBIncidentWebServiceVi" parts="ticketID "/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="urn:GDBIncidentWebServiceVi"/>
</wsdl:output>
</wsdl:operation>
完整的 WSDL 如下所示 - 分成 3 个文件。主 WSDL 文件:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="GDBIncidentWebServiceWsd" targetNamespace="urn:GDBIncidentWebServiceWsd" xmlns:bns0="urn:GDBIncidentWebServiceWsd/Config/rpc" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:import location="./bindings/Config_rpc.wsdl" namespace="urn:GDBIncidentWebServiceWsd/Config/rpc"/>
<wsdl:service name="GDBIncidentWebService">
<wsdl:port name="ConfigPort_Rpc" binding="bns0:ConfigBinding">
<soap:address location="http://xxxx/GDBIncidentWebService/Config?style=rpc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
绑定文件(提取)
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://www.w3.org/2001/XMLSchema" xmlns:ns0="urn:com.dbag.gde.gdb.types" targetNamespace="urn:GDBIncidentWebServiceWsd/GDBIncidentWebServiceVi/rpc" xmlns:tns="urn:GDBIncidentWebServiceWsd/GDBIncidentWebServiceVi/rpc" xmlns:ns2="urn:java/lang">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:com.dbag.gde.gdb.types" xmlns:tns="urn:com.dbag.gde.gdb.types" elementFormDefault="qualified">
<xs:complexType name="KeyValuePair">
<xs:sequence>
<xs:element name="key" type="xs:string" nillable="true" minOccurs="0"/>
<xs:element name="value" type="xs:string" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfKeyValuePair">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="KeyValuePair" type="tns:KeyValuePair" nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:java/lang" xmlns:tns="urn:java/lang" elementFormDefault="qualified">
<xs:complexType name="ArrayOfString">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="String" type="xs:string" nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="createInsourcingIncidentIn">
<wsdl:part name="externalKey" type="ns1:string"/>
<wsdl:part name="title" type="ns1:string"/>
<wsdl:part name="description" type="ns1:string"/>
<wsdl:part name="impact" type="ns1:string"/>
<wsdl:part name="urgency" type="ns1:string"/>
<wsdl:part name="contact" type="ns1:string"/>
<wsdl:part name="creatorGroup" type="ns1:string"/>
<wsdl:part name="category1" type="ns1:string"/>
<wsdl:part name="category2" type="ns1:string"/>
<wsdl:part name="category3" type="ns1:string"/>
<wsdl:part name="extReference" type="ns0:ArrayOfKeyValuePair"/>
<wsdl:part name="attachments" type="ns0:ArrayOfAttachment"/>
<wsdl:part name="additionalFields" type="ns0:ArrayOfKeyValuePair"/>
<wsdl:part name="assignmentGroup" type="ns1:string"/>
<wsdl:part name="assignmentSubGroup" type="ns1:string"/>
<wsdl:part name="productId" type="ns1:string"/>
<wsdl:part name="productName" type="ns1:string"/>
<wsdl:part name="service" type="ns1:string"/>
<wsdl:part name="customer" type="ns1:string"/>
</wsdl:message>
<wsdl:portType name="GDBIncidentWebServiceVi_Rpc">
<wsdl:operation name="createInsourcingIncident">
<wsdl:input message="tns:createInsourcingIncidentIn"/>
<wsdl:output message="tns:createInsourcingIncidentOut"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
操作定义
<wsdl:operation name="createInsourcingIncident">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal" namespace="urn:GDBIncidentWebServiceVi" parts="externalKey title description impact urgency contact creatorGroup category1 category2 category3 extReference attachments additionalFields assignmentGroup assignmentSubGroup productId productName service customer "/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="urn:GDBIncidentWebServiceVi"/>
</wsdl:output>
</wsdl:operation>