2

このコードを実行しようとすると:

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>

だから私の<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 要素の接頭辞をサーバーの要件に合わせて変更しました。喜び!

4

1 に答える 1

3

RPC エンドポイントが XML を正しく解析しないのは残念です。Client()修正する 1 つの方法は、送信前にエンベロープを編集するプラグインを に追加することです。MessagePluginを使用すると、送信前にメッセージ テキストを変更できますsuds.sax.document.Document

from suds.plugin import MessagePlugin
class EnvelopeFixer(MessagePlugin):
    def sending(self, context):
        # context is the envelope text
        context.envelope = context.envelope.upper()
        return context

client = Client(..., plugins=[EnvelopeFixer()])
于 2011-01-06T14:17:55.783 に答える