我使用perl soap :: lite来构建一个Web服务客户端.
该实现适用于简单的方法,例如,需要一个标量参数.
EG,以下工作正常.
该实现适用于简单的方法,例如,需要一个标量参数.
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>
解决方法
更新和解决.
看起来像使用proxy / uri方法创建SOAP :: Lite对象(而不是简单地引用WSDL“服务”)如果要传递复杂数据,则必须使用字符串
因此,对于简单请求,代码现在看起来如下:
看起来像使用proxy / uri方法创建SOAP :: Lite对象(而不是简单地引用WSDL“服务”)如果要传递复杂数据,则必须使用字符串
因此,对于简单请求,代码现在看起来如下:
my $base="https://XXXXX/GDBIncidentWebService/Config?wsdl&style=rpc"; my $uri="urn:GDBIncidentWebServiceVi" my $ticketID='20054106'; my $lite = SOAP::Lite -> proxy($base) -> uri($uri); my $res = $lite -> readIncident(SOAP::Data->('ticketID' => $ticketID)) -> result; print Dumper($res);