Fixing outgoing message in suds SOAP request
<p>My suds request produces invalid message once calling soap WS.<br>
There are two things to do that i've spend hours on with no success:</p>

<ul>
<li>Add a namespace and prefix to one of complex obejcts (<code>securityObject</code>)</li>
<li>Add an attribute to another complex object (<code>Document</code>)</li>
</ul>

<p>My client:</p>

<pre><code>Suds ( https://fedorahosted.org/suds/ )  version: 0.6

Service ( MyService ) tns="http://path/to/tns"
  Prefixes (4)
      ns0 = "http://path/to/v3/"
      ns1 = "http://path/to/tns"
      ns2 = "http://www.path/to/file.001.xsd"
      ns3 = "http://www.path/to/file.002.xsd"
   Ports (1):
      (MyServiceSOAP)
         Methods (1):
            processAction(ns2:Document Document, ns0:securityObject securityObject PriorityType priority)
         Types (233):
            ns0:securityObject
            PriorityType
            ns3:Document
            ns2:Document
            ns3:AccountIdentification4Choice
            …
</code></pre>

<p><strong>1st</strong> method argument:  </p>

<p>Because <code>ns2:Document Document</code> is quite big and complex and I already <strong>have</strong> valid XML i will pass this as a <code>processAction</code> parameter in following form:</p>

<pre><code>from suds.sax.text import Raw
_doc.open('file.xml').read()
doc = Raw(_doc) # ready to pass 
</code></pre>

<p>This is how this doc looks like:
<code>&lt;Document xmlns="http://www.path/to/file.001.xsd"&gt;...&lt;/Document&gt;</code></p>

<p><strong>2nd</strong> method argument:  </p>

<p>Is security object:</p>

<pre><code>s_o = client.factory.create('{http://path/to/v3/}securityObject')
s_o.name = token_data.Name
s_o.user = token_data.Tenant
s_o.timestamp = token_data.Time.isoformat()
s_o.pass = token_data.Passwd
</code></pre>

<p>Let's send:</p>

<pre><code>try:
    process_data = client.service.processAction(s_o, doc, prio.NORMAL)
except suds.WebFault as e:
    print e
</code></pre>

<p>Outgoing (invalid) message:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"    # in client its "http://path/to/v3/"
                   xmlns:ns1="http://path/to/tns"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
                   # missing xmlns:v3="http://path/to/v3/" here!
    &lt;SOAP-ENV:Header/&gt;
    &lt;ns0:Body&gt;
        &lt;ns1:payment&gt;
            &lt;securityObject&gt;    # wrong! shall be &lt;v3:securityObject&gt; 
                &lt;user&gt;1&lt;/user&gt;
                &lt;name&gt;MyName&lt;/name&gt;
                &lt;timestamp&gt;2016-06-22T11:40:58.115000+02:00&lt;/timestamp&gt;
                &lt;pass&gt;Password&lt;/pass&gt;
            &lt;/securityObject&gt;
            &lt;Document&gt;                                             # wrong, missing attribute here, xmlns= 
                &lt;Document xmlns="http://www.path/to/file.001.xsd"&gt; # comes from orginal xml, can be trimmed
</code></pre>

<p>Message that will success requires two fixes:</p>

<ol>
<li><p>adding a namspace and prefix for  to look like below:</p>

<pre><code>xmlns:v3="http://path/to/v3/"  # this to be added in Envelope
&lt;v3:securityObject&gt;
    ...
&lt;/v3:securityObject&gt;
</code></pre></li>
<li><p>Adding an attribute to <code>ns2:Document</code> object, so it will look like:<br>
<code>&lt;Document xmlns="http://www.path/to/file.001.xsd"&gt;</code><br>
(This will require stripping  tag from orginal message that i create. I can do that but it seems not quite elegant.)
<em>Ideally</em> would it be to map the content of my XML into <code>ns2:Document</code> object with one single method.</p></li>
</ol>

<p>Here is how suds handles those objects:</p>

<pre><code>(Content){
   tag = "Document"
   value = "&lt;Document xmlns="http://www.path/to/file.001.xsd"&gt;
                &lt;CfInitn&gt;
                    &lt;GrpHdr&gt;
                    ...

(Content){
   tag = "securityObject"
   value = 
      (securityObject){
         user= 1
         name = "MyName"
         timestamp = "2016-06-22T12:51:29.820000+02:00"
         pass= "Password"
      }
</code></pre>

<p>Any help much apreciated, thanks!</p>