如何在 SOAPpy 中将列表参数作为多个链接命名元素而不是数组传递?
我正在尝试将一个元素的多个实例传递给具有以下 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 个条目...
I am trying to pass multiple instances of an element to a web servile that has the following wsdl
<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>
This is my code in python for the client
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}
Here is the output I get from SOAPpy that gets rejected by the web service, it creates an array for the 2 m-argVector elements.
<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>
Here is the output that another client sends that works. No array, just two elements that have the same name.
<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>
How can I modify my SOAPpy code to generate the xml output like the one above ?
EDIT:
I tried the following code in python
oamCmdStruct = SOAPpy.structType( data = {"m-strName":"set-log-level",
"m-argVector": logLevel,
"m-argVector": loggerName})
But this is what the XML output from SOAPpy looked like
<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>
The value for logLevel gets overwritten by loggerName instead of creating 2 entries...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在尝试了几个不同的库(suds、soaplib)之后,我终于深入研究了 SOAPpy 代码。
为了从 SOAP 请求中删除数组,我修改了 SOAPpy 库的 SOAPBuilder 类中的 dump_list() 函数。
此更改为我的 SOAP XML 请求提供了以下输出。
After trying a few different librairies (suds, soaplib), I finally dug into the SOAPpy code.
In order to remove the arrays from my SOAP requests, I modified the dump_list() function in the SOAPBuilder class of the SOAPpy library.
This change gives me the following output for my SOAP XML request.