如何在 SOAPpy 中将列表参数作为多个链接命名元素而不是数组传递?

发布于 2024-08-23 08:11:15 字数 2029 浏览 6 评论 0原文

我正在尝试将一个元素的多个实例传递给具有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迎风吟唱 2024-08-30 08:11:15

在尝试了几个不同的库(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>

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.

# 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)

This change gives me the following output for my SOAP XML request.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文