當我嘗試執行此代碼:創建無效SUDS信封
mmurl = 'http://server/_mmwebext/mmwebext.dll?WSDL?server=localhost'
mmclient = Client(mmurl, plugins=[EnvelopeFixer()])
loginResult = mmclient.service[1].Login(u'localhost', u'user', u'pass')
以下信封:
<SOAP-ENV:Envelope xmlns:ns0="http://menandmice.com/webservices/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:Login>
<ns0:server>localhost</ns0:server>
<ns0:loginName>user</ns0:loginName>
<ns0:password>pass</ns0:password>
</ns0:Login>
</ns1:Body>
</SOAP-ENV:Envelope>
返回:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Invalid command.</faultstring>
<detail>
<mmfaultdetails>
<message>Invalid command.</message>
<errorcode>5001</errorcode>
</mmfaultdetails>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
,但如果我改變它在soapUI至
<SOAP-ENV:Envelope xmlns:ns0="http://menandmice.com/webservices/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns0:Login>
<ns0:server>localhost</ns0:server>
<ns0:loginName>user</ns0:loginName>
<ns0:password>pass</ns0:password>
</ns0:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
它成功返回
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<LoginResponse xmlns="http://menandmice.com/webservices/">
<session>UEk6A0UC5bRJ92MqeLiU</session>
</LoginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
所以我的問題是我可以迫使泡沫創造body標籤作爲<SOAP-ENV:Body>
代替<ns1:Body>
或者是
我嘗試這樣做,看看是否我可以改變發送過來的XML線和使用wireshark嗅探流量,事實證明,它並沒有改變發送的消息。發送方法被稱爲是肯定的,因爲我看到打印出來的控制檯
class EnvelopeFixer(MessagePlugin):
def sending(self, context):
# context is the envelope text
print type(context)
context.envelope = context.envelope.upper()
print context.envelope
return context
我改變EnvelopeFixer使用編組,而不是發送,這似乎已經完成了招
class EnvelopeFixer(MessagePlugin):
def marshalled(self, context):
root = context.envelope.getRoot()
envelope = root.getChild("Envelope")
envelope.getChildren()[1].setPrefix("SOAP-ENV")
print envelope.getChildren()[1]
return context
所以現在我已經更改了body元素的前綴以符合服務器的要求。喜悅!
嗨davideagle,我用你的文章來修改我自己的標題。但是我將suds設置爲suds.client的調試模式,我發現雖然上下文根據我的需要而改變。但是泡沫仍在發送之前的內容。你可以幫我嗎? – 2014-01-24 07:39:00
在運行setup.py build和setup.py之前,您是否刪除了以前的egg文件? – davideagle 2014-01-24 13:59:57
爲什麼我需要這樣做?我使用的是'virtualenv',然後是'pip安裝泡沫' – 2014-01-25 06:12:42