我正在尝试将元素的多个实例传递给具有以下wsdl的web servile
<complexType name="OAMCommand">
<sequence>
<element name="m-strName" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<element name="m-argVector" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
这是我在客户端的python中的代码
oamCmdStruct = SOAPpy.structType()
oamCmdStruct._addItem('m-strName','set-log-level')
oamCmdStruct._addItem('m-argVector', logLevel)
oamCmdStruct._addItem('m-argVector', loggerName)
self.serverConnection.executeCommand({'in-cmd':oamCmdStruct}
以下是我从SOAPpy获得的输出被Web服务拒绝,它为2 m-argVector元素创建了一个数组。
<xsd:in-cmd>
<m-strName xsi:type="xsd:string">set-log-level</m-strName>
<m-argVector SOAP-ENC:arrayType="xsd:string[2]" xsi:type="SOAP-ENC:Array">
<item>WARN_LOG_LEVEL</item>
<item>netborder</item>
</m-argVector>
</xsd:in-cmd>
以下是另一个客户端发送的输出。没有数组,只有两个具有相同名称的元素。
<SoapOAM:executeCommand>
<in-cmd>
<m-strName>set-log-level</m-strName>
<m-argVector>ERROR_LOG_LEVEL</m-argVector>
<m-argVector>netborder.media</m-argVector>
</in-cmd>
</SoapOAM:executeCommand>
如何修改我的SOAPpy代码以生成如上所示的xml输出?
编辑: 我在python
中尝试了以下代码 oamCmdStruct = SOAPpy.structType( data = {"m-strName":"set-log-level",
"m-argVector": logLevel,
"m-argVector": loggerName})
但这就是SOAPpy的XML输出看起来像
<xsd:in-cmd>
<m-strName xsi:type="xsd:string">set-log-level</m-strName>
<m-argVector xsi:type="xsd:string">loggerName</m-argVector>
</xsd:in-cmd>
logLevel的值被loggerName覆盖而不是创建2个条目......
答案 0 :(得分:0)
在尝试了几个不同的库(suds,soaplib)之后,我终于挖到了SOAPpy代码。
为了从SOAP请求中删除数组,我修改了SOAPpy库的 SOAPBuilder 类中的 dump_list()函数。
# COMMENT: We dont want arrays in SOAP-XML so I commented out the following lines
# if typed:
# self.out.append(
# '<%s %sarrayType="%s[%d]" %stype="%sArray"%s%s%s%s%s%s>\n' %
# (tag, ens, t, len(data), ins, ens, ndecl, edecl, idecl,
# self.genroot(ns_map), id, a))
#if typed:
# try: elemsname = obj._elemsname
# except: elemsname = "item"
#else:
elemsname = tag
for i in data:
self.dump(i, elemsname, not same_type, ns_map)
#if typed: self.out.append('</%s>\n' % tag)
此更改为我的SOAP XML请求提供了以下输出。
<SOAP-ENV:Body>
<ns1:executeCommand xmlns:ns1="urn:SoapOAM">
<xsd:in-cmd>
<m-strName xsi:type="xsd:string">set-log-level</m-strName>
<m-argVector>ERROR_LOG_LEVEL</m-argVector>
<m-argVector>netborder</m-argVector>
</xsd:in-cmd>
</ns1:executeCommand>
</SOAP-ENV:Body>