SOAPpy中的复杂类型问题

4 投票
1 回答
2194 浏览
提问于 2025-04-16 17:04

我正在尝试从HP服务器自动化中访问我在WSDL中定义的一个函数,我可以获取服务器等信息,但无法通过SOAPpy获取任何需要服务器引用的内容。

import SOAPpy
from SOAPpy import WSDL
from SOAPpy import structType

SOAPpy.Config.debug=1
server = WSDL.Proxy('ServerService.wsdl')

serverRef = structType(name='self', typed=0)
serverRef._addItem('id',SOAPpy.longType(19250001))

print server.getCustAttr(serverRef,key='HPSW_ED_win32_diskspace',useScope=False)

The SOAP envelope generated from this code looks like this:
*** Outgoing SOAP ******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsd2="http://www.w3.org/2000/10/XMLSchema"
  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<ns1:getCustAttr xmlns:ns1="http://server.opsware.com" SOAP-ENC:root="1">
<xsd:self>
<id xsi:type="xsd2:long">19250001</id>
</xsd:self>
<useScope xsi:type="xsd:boolean">False</useScope>
<key xsi:type="xsd:string">HPSW_ED_win32_diskspace</key>
</ns1:getCustAttr>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

它应该像这样(在SOAPUI中运行成功):

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://server.opsware.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getCustAttr soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
           <self xsi:type="ser:ServerRef">
              <id xsi:type="xsd:long">19250001</id>
           </self>
         <key xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">HPSW_ED_win32_diskspace</key>
         <useScope xsi:type="xsd:boolean">False</useScope>
      </ser:getCustAttr>
   </soapenv:Body>
</soapenv:Envelope>

我认为问题在于没有设置xsi:type="ser:ServerRef",但我不太确定如何在SOAPpy中做到这一点...

1 个回答

4

SOAP有两种不同的风格,分别是RPC字面量和文档字面量。看起来提到的那个SOAP服务器只支持RPC风格。

我在使用soappy和suds的时候遇到了这个问题。经过一些测试和基准测试,我找到了问题所在。ASP.NET和soappy之间,你需要用Python生成一个RPC信封,而不是文档字面量风格的信封。

只有ZSI(Zolera SOAP基础设施)可以和ASP.NET以及复杂类型一起使用。

这个命令会为你生成客户端代理:

wsdl2py http://terraservice.net/TerraService.asmx?WSDL

然后你可以在你的代码中导入生成的模块,并使用这些网络方法。

撰写回答