How can I get the soap envelope,and how can I change the values before sending to server.
ex: Soap envelope
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ws="http://www.altoromutual.com/bank/ws/">
<soap:Header/>
<soap:Body>
<ws:TransferBalance>
<!--Optional:-->
<ws:transDetails>
<ws:transferDate>2013-01-01T00:00:00</ws:transferDate>
<!--Optional:-->
<ws:debitAccount>1001160141</ws:debitAccount>
<!--Optional:-->
<ws:creditAccount>1001160140</ws:creditAccount>
<ws:transferAmount>2.0</ws:transferAmount>
</ws:transDetails>
</ws:TransferBalance>
I want to hold this envelope and change the values before sending to server.How can I do it with suds
Thanks
If I understood the question correctly, you don't necessarily need to use suds to modify the envelope. Instead you can save the request as a template, use your favorite templating engine to change any values you need to change, and pass the whole request to the suds call using the __inject
parameter.
Here's a simple example:
import suds
from mako.template import Template
WSDL = 'https://example.com/someservice?wsdl'
client = suds.client.Client(WSDL)
template = Template(filename='template.xml')
request = template.render(debitaccount='someaccount', creditaccount='anotheraccount')
response = client.service.some_call(__inject={'msg':request})
And the template
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ws="http://www.altoromutual.com/bank/ws/">
<soap:Header/>
<soap:Body>
<ws:TransferBalance>
<!--Optional:-->
<ws:transDetails>
<ws:transferDate>2013-01-01T00:00:00</ws:transferDate>
<!--Optional:-->
<ws:debitAccount>${debitaccount}</ws:debitAccount>
<!--Optional:-->
<ws:creditAccount>${creditaccount}</ws:creditAccount>
<ws:transferAmount>2.0</ws:transferAmount>
</ws:transDetails>
</ws:TransferBalance>
</soap:Body>
</soap:Envelope>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.