如何创建为arrayType中(用肥皂水)在Python WSDL? [英] How to create arrayType for WSDL in Python (using suds)?
问题描述
环境:
- 的Python V2.6.2
- 肥皂水v0.3.7
的WSDL(服务器)和我一起工作,有以下模式小节(我试着写清楚用纯文本) -
[小节#1] 的
searchRequest:(searchRequest){
userIdentification =(userIdentification){
用户名=
密码=
}
itineraryArr =(itineraryArray){
_arrayType =
_offset =
_id =
_href =
_arrayType =
}
...
...
[小节#2] 的
行程安排:(行程){
departurePoint =(的LocationPoint){
locationId =无
半径=无
}
arrivalPoint =(的LocationPoint){
locationId =无
半径=无
}
...
...
有与userIdentification(这是一个简单型)
没问题但是,itineraryArr是行程的数组,我不知道如何使用Python创建XML数组。
我试过几个的组合,例如:
itinerary0 = self.client.factory.create('行程')
itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray = [itinerary0]
searchRequest.itineraryArr = itineraryArray
但我所有的试验结果与同一服务器错误 -
服务器故障提出:不能使用类型的行程对象数组
(故障){
故障code =SOAP-ENV:服务器
faultstring =不能使用类型的行程对象数组
}
我在同样的情况下,与RPC / EN codeD风格WS和包含肥皂阵列的方法。打印请求(其中要求= client.factory.create('请求')
)给出:
(请求){
的requestId =无
选项=
(ArrayOfOption){
_arrayType =
_offset =
_id =
_href =
_arrayType =
}
}
由雅克给出的解决方案(1request.option.append(选项1)1)不起作用,因为它与一个错误信息 ArrayOfOption实例没有属性追加
结束。
由mcauth给出的解决方案是这样的:
=阵列client.factory.create('ArrayOfOption')
array.item = [选项,选项2,选项3,3选项,选项5,选项6]
request.option =阵列
它的工作原理如此如此,因为所产生的SOAP消息没有显示出 arrayType中
属性:
<选项的xsi:type =NS3:ArrayOfOption>
我发现最好的解决办法也是最简单:
request.option = [选项,选项2,选项3,3选项,选项5,选项6]
它具有良好的SOAP消息结尾:
<选项的xsi:type =NS0:ArrayOfOptionNS3:arrayType中=NS0:选项[6]>
如预期由服务器端WS。
Environment:
- Python v2.6.2
- suds v0.3.7
The WSDL (server) I work with, have the following schema sub-sections (I tried to write it clearly using plain text) -
[ sub-section #1 ]
searchRequest: (searchRequest){
userIdentification = (userIdentification){
username = ""
password = ""
}
itineraryArr = (itineraryArray){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
_arrayType = ""
}
...
...
[ sub-section #2 ]
itinerary: (itinerary){
departurePoint = (locationPoint){
locationId = None
radius = None
}
arrivalPoint = (locationPoint){
locationId = None
radius = None
}
...
...
There is no problem with 'userIdentification' (which is a "simple" type)
But, 'itineraryArr' is an array of 'itinerary', and I don't know how to use python to create XML array.
I tried few combinations, for example
itinerary0 = self.client.factory.create('itinerary')
itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray = [itinerary0]
searchRequest.itineraryArr = itineraryArray
But all my trials resulted with the same server error -
Server raised fault: 'Cannot use object of type itinerary as array'
(Fault){
faultcode = "SOAP-ENV:Server"
faultstring = "Cannot use object of type itinerary as array"
}
I'm in the same case, with a RPC/encoded style WS and a method that contains a soap array. a print request (where request = client.factory.create('Request')
) gives:
(Request){
requestid = None
option =
(ArrayOfOption){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
_arrayType = ""
}
}
The solution given by Jacques (1request.option.append(option1)1) does not work, as it ends with an error message ArrayOfOption instance has no attribute append
.
The solution given by mcauth looks like this:
array = client.factory.create('ArrayOfOption')
array.item = [option1, option2, option3, option4, option5, option6]
request.option=array
It works so so, as the resulting SOAP message shows no arrayType
attribute:
<option xsi:type="ns3:ArrayOfOption">
The best solution I found is also the simplest:
request.option = [option1, option2, option3, option4, option5, option6]
It ends with a good SOAP message:
<option xsi:type="ns0:ArrayOfOption" ns3:arrayType="ns0:Option[6]">
as expected by the server side WS.
这篇关于如何创建为arrayType中(用肥皂水)在Python WSDL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!