在我的一个应用程序中,我在GAE python上使用SUDS WSDL(SOAP)Web服务。
我的 Py Code :
url = 'http://203.215.51.43/Gateway/Execute?WSDL'
client = Client(url)
print client
所以它在服务器控制台
打印Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913
Service ( GatewayService ) tns="urn:fks:jcaps:gateway"
Prefixes (2)
ns0 = "http://fks.com/gtwy"
ns1 = "urn:fks:jcaps:gateway:JavaException"
Ports (1):
(Execute)
Methods (1):
redeem(xs:string SessionId, xs:string TerminalId, xs:string StoreCod
e, xs:string CashMemoNo, xs:string CashMemoDate, xs:double InvoiceAmount, xs:str
ing TimeStamp, xs:string CashierId, xs:string MerchantId, ns0:SPCReqDtls SPCReqD
tls, ns0:VoucherReqDtls[] VoucherReqDtls, ns0:CardReqDtls CardReqDtls, )
Types (1):
ns1:JavaExceptionType
实际上我可以在兑换方法中传递字符串,双类型值,但不能传递数组/列表类型,
result = client.service.redeem(SessionId=result['SessionId'], StoreCode='4739', TerminalId='T1081', TimeStamp='01-01-2011 01:01:00.000')
但我无法通过 VoucherReqDtls 数组
此VoucherReqDtls的 WSDL的XML 代码如下所示,
<!--Zero or more repetitions:-->
<gtwy:VoucherReqDtls>
<gtwy:VoucherType>GV</gtwy:VoucherType>
<!--1 or more repetitions:-->
<gtwy:VoucherReq>
<gtwy:VoucherNo>344234242</gtwy:VoucherNo>
</gtwy:VoucherReq>
<gtwy:VoucherReq>
<gtwy:VoucherNo>675685858</gtwy:VoucherNo>
</gtwy:VoucherReq>
</gtwy:VoucherReqDtls>
那么如何在兑换方法中传递 VoucherReqDtls 数组/列表,此处VoucherType为 GV 且计数为 VoucherNo < / strong>可能不止一个。
答案 0 :(得分:5)
我认为问题在于,如果您直观地检查WSDL,则redeem方法需要一个复杂类型的GatwayReq
,可以使用以下代码创建:
>>> it = client.factory.create('ns0:GatewayReq')
>>> it
(GatewayReq){
SessionId = None
TerminalId = None
StoreCode = None
CashMemoNo = None
CashMemoDate = None
InvoiceAmount = None
TimeStamp = None
CashierId = None
MerchantId = None
SPCReqDtls =
(SPCReqDtls){
SPCNo = None
SPCAmt = None
}
VoucherReqDtls[] = <empty>
CardReqDtls =
(CardReqDtls){
CardType = None
CardReq =
(CardReq){
CardNo = None
TransAmt = None
}
}
}
您可以像使用任何对象属性一样将元素添加到GatewayReq对象,即
>>> it.SessionId = 'blahablhabalh'
>>> it
(GatewayReq){
SessionId = "blahablhabalh"
# the rest removed for readability
然后你会像这样调用兑换方法:
>>>> client.service.redeem(it)
修改强>
您可以使用以下语法创建所需类型:
entry1 = client.factory.create('ns0:GatewayReq.ns0:VoucherReqDtls')
>>> entry1
(VoucherReqDtls){
VoucherType = None
VoucherReq[] = <empty>
}
这使用该机制来访问此处suds docs - FACTORY
中指定的顶级类型然后您可以将其添加到主请求对象中,如下所示:
>>> entry1.VoucherType = 'GV'
>>> entry1.VoucherReq.append([12,34,56])
>>> entry1
(VoucherReqDtls){
VoucherType = "GV"
VoucherReq[] =
12,
34,
56,
}
>>> entry1.VoucherReq.append(23)
>>> entry1
(VoucherReqDtls){
VoucherType = "GV"
VoucherReq[] =
12,
34,
56,
23,
}
>>> it.VoucherReqDtls.append(entry1)
>>> it
(GatewayReq){
SessionId = None
TerminalId = None
StoreCode = None
CashMemoNo = None
CashMemoDate = None
InvoiceAmount = None
TimeStamp = None
CashierId = None
MerchantId = None
SPCReqDtls =
(SPCReqDtls){
SPCNo = None
SPCAmt = None
}
VoucherReqDtls[] =
(VoucherReqDtls){
VoucherType = "GV"
VoucherReq[] =
12,
34,
56,
23,
},
CardReqDtls =
(CardReqDtls){
CardType = None
CardReq =
(CardReq){
CardNo = None
TransAmt = None
}
}
}
这个创建xml如下所示,它可以算出所需的语法:
<SOAP-ENV:Header/>
<ns0:Body>
<ns1:GatewayReq>
<ns1:SessionId>
<ns1:SessionId/>
<ns1:TerminalId/>
<ns1:StoreCode/>
<ns1:CashMemoNo/>
<ns1:CashMemoDate/>
<ns1:TimeStamp/>
<ns1:CashierId/>
<ns1:VoucherReqDtls>
<ns1:VoucherType>GV</ns1:VoucherType>
<ns1:VoucherReq>12</ns1:VoucherReq>
<ns1:VoucherReq>34</ns1:VoucherReq>
<ns1:VoucherReq>56</ns1:VoucherReq>
<ns1:VoucherReq>23</ns1:VoucherReq>
</ns1:VoucherReqDtls>
<ns1:VoucherReqDtls>
<ns1:VoucherType>GV</ns1:VoucherType>
<ns1:VoucherReq>12</ns1:VoucherReq>
<ns1:VoucherReq>34</ns1:VoucherReq>
<ns1:VoucherReq>56</ns1:VoucherReq>
<ns1:VoucherReq>23</ns1:VoucherReq>
</ns1:VoucherReqDtls>
</ns1:SessionId>
<ns1:TerminalId/>
<ns1:StoreCode/>
<ns1:CashMemoNo/>
<ns1:CashMemoDate/>
<ns1:TimeStamp/>
<ns1:CashierId/>
</ns1:GatewayReq>
</ns0:Body>
</SOAP-ENV:Envelope>
或者至少我认为应该如何运作
希望有所帮助