开发者

invalid SUDS envelope

When I try to execute this code:

mmurl = 'http://server/_mmwebext/mmwebext.dll?WSDL?开发者_JAVA百科server=localhost'
mmclient = Client(mmurl, plugins=[EnvelopeFixer()])
loginResult = mmclient.service[1].Login(u'localhost', u'user', u'pass')

the following envelope is created:

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

which returns:

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

but if i change it in soapUI to

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

it returns successfully

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

So my question is can i force suds to create the body tag as <SOAP-ENV:Body> instead of <ns1:Body> or is

I tried this to see if I could change the XML sent over the wire and used wireshark to sniff the traffic and it turned out that it did not change the message being sent. the sending method is being called for sure since I see the print-out in the console

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

I changed EnvelopeFixer to use marshalled instead of sending and that seems to have done the trick

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

So now I have changed the prefix of the body element to comply with what the server requires. JOY!


It's unfortunate that the RPC endpoint does not parse XML correctly. One way to fix would be to add a plugin to your Client() that edits the envelope before sending. A MessagePlugin gives you the chance to modify the suds.sax.document.Document or the message text before sending.

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()])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜