如何使用SOAPpy调用IBM IMM方法?

时间:2011-05-18 18:18:08

标签: python soap soappy

我正在尝试使用SOAPpy来调用IBM IMM(集成管理模块)的各种SOAP方法。不幸的是,我对SOAP很陌生,根本无法弄明白。

我没有任何类型的WSDL,所以我不得不求助于观看我的浏览器在发出各种请求时所做的事情。

所做的实际调用如下:

POST /wsman HTTP/1.1
Host: 192.168.0.166
Connection: keep-alive
Referer: http://192.168.0.166/
Content-Length: 857
Origin: http://192.168.0.166
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Ubuntu/10.10 Chromium/11.0.696.65 Chrome/11.0.696.65 Safari/534.24
Content-Type: text/xml
session_id: 54891711-7ccc-44ce-a903-48a91598b492
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: session_id=none


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">
  <SOAP-ENV:Header>
    <wsa:To>http://192.168.0.166/wsman</wsa:To>
    <wsa:ReplyTo>
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
    </wsa:ReplyTo>
    <wsman:ResourceURI>http://www.ibm.com/iBMC/sp/Tasks</wsman:ResourceURI>
    <wsa:Action>http://www.ibm.com/iBMC/sp/Tasks/GetKVMStatus</wsa:Action>
    <wsa:MessageID>dt:1305665818978</wsa:MessageID>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <GetKVMStatus xmlns="http://www.ibm.com/iBMC/sp/Tasks" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"></GetKVMStatus>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

和回复:

HTTP/1.1 200 OK
Content-Type: application/soap+xml;charset=UTF-8
Content-Length: 884
Date: Tue, 17 May 2011 20:56:13 GMT
Server: lighttpd/1.4.13

<?xml version="1.0"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" 
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:wxf="http://schemas.xmlsoap.org/ws/2004/09/transfer">
    <s:Header>
        <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
        <wsa:Action>http://www.ibm.com/iBMC/sp/Tasks/GetKVMStatusResponse</wsa:Action>
        <wsa:RelatesTo>dt:1305665818978</wsa:RelatesTo>
        <wsa:From><wsa:Address>http://192.168.0.166/wsman</wsa:Address></wsa:From>
        <wsa:MessageID>uuid:db591e0e-36dd-459f-9cec-68a19a79318e</wsa:MessageID>
    </s:Header>
    <s:Body>
        <GetKVMStatusResponse>
        <ActiveSessions>0</ActiveSessions>
        <MaxSessions>4</MaxSessions>
        <Encrypted>0</Encrypted>
        <HasLicense>1</HasLicense>
        <HasPrivilege>1</HasPrivilege>
        <DisableHighSpeed>0</DisableHighSpeed>
        </GetKVMStatusResponse>
    </s:Body>
</s:Envelope>

我正在尝试使用SOAPpy正确生成此请求,但我根本无法获取任何内容,而且我不知道该做什么或更改以发出此请求。这是我到目前为止所尝试的内容:

>>> sess = imm.ImmWeb()
Session ID: 8b3af28d-a746-4fc5-af02-b4560f85cac1
>>> server = SOAPpy.SOAPProxy('http://imm/wsman',namespace='http://www.ibm.com/iBMC/sp/Tasks')
>>> server.transport.cookies['session_id'] = '3f19329f-468b-4c86-b6e7-2197b1ed62aa'
>>> server.invoke('http://www.ibm.com/iBMC/sp/Tasks/GetKVMStatus', {})
*** Outgoing HTTP headers **********************************************
POST /wsman HTTP/1.0
Host: imm
User-agent: SOAPpy 0.12.4 (http://pywebsvcs.sf.net)
Content-type: text/xml; charset=UTF-8
Content-length: 484
SOAPAction: "http://www.ibm.com/iBMC/sp/Tasks/GetKVMStatus"
************************************************************************
*** 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:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
>
<SOAP-ENV:Body>
<ns1:http://www.ibm.com/iBMC/sp/Tasks/GetKVMStatus xmlns:ns1="http://www.ibm.com/iBMC/sp/Tasks" SOAP-ENC:root="1">
<v1>
</v1>
</ns1:http://www.ibm.com/iBMC/sp/Tasks/GetKVMStatus>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
************************************************************************
«««traceback»»»
SOAPpy.Errors.HTTPError: <HTTPError 400 Bad Request>

1 个答案:

答案 0 :(得分:0)

使用远程服务器上的WSDL文件来指定方法(函数)及其相应的参数和数据类型会好得多。

此外,您将有机会确切知道要建立的SOAP连接的名称空间,编码和格式。

尝试使用:

SERVER=SOAPpy.WSDL.Proxy('http://remote.server.url/service.wsdl')

直接使用SOAPpy.Proxy,必须将正确的参数添加到您正在与之交谈的服务器中。