mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.9k stars 586 forks source link

[question] set namespace ns0 on soap-env element #550

Open ghost opened 7 years ago

ghost commented 7 years ago

I need the namespace to be on the element "soap-env" instead of the element "ns0:submit"

client = Client('wsdl') service = client.create_service( '{http://my-target-namespace-here}myBinding', 'http://my-endpoint.com/acceptance/') response = service.submit(string) print(response)

Need to get:

<soap-env:Envelope 
  xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope"  
  xmlns:ns0="http://my-target-namespace-here" >
  <soap-env:Body>
    <ns0:submit>
       <!-- payload -->
    </ns0:submit>
  </soap-env:Body>
</soap-env:Envelope>

Zeep generates:

<soap-env:Envelope xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope">
  <soap-env:Body>
    <ns0:submit xmlns:ns0="http://my-target-namespace-here">
       <!-- payload -->
    </ns0:submit>
  </soap-env:Body>
</soap-env:Envelope>

edit: The server can not work with the generated result. Bug on the server side i guess It is possible to work around the problem?

If i use the wsdl in SoapUI, it generates the first envelope example.

I can share the WSDL via a DM if necessary.

Best regards, Bob

mvantellingen commented 7 years ago

I used http://lxml.de/api/lxml.etree-module.html#cleanup_namespaces for this before but that introduced bugs where it removed namespaces which were actually used. So it needs to do some smart thing with the keep_ns_prefixed. Need to look at this some time later

ghost commented 7 years ago

Thx :-) Love your work btw Zeep is great

bvdloo commented 6 years ago

i deleted my other account :-)

loreTo87 commented 6 years ago

Thx :-) Love your work btw Zeep is great

Did you find another solution for your question?

apollo13 commented 5 years ago

@loreTo87 Afaik this would help as a workaround:

client.set_ns_prefix("ns0", "http://my-target-namespace-here")

since it sets the namespace globally (You'd of course need to know the namespace, but it doesn't look to bad).