我需要发送一个看起来完全像这样的SOAP envelope
......
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:realops.com:amp:workflow" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:dst="DST_JC_Sandbox">
<soapenv:Header>
<urn:grid-name>GRID01</urn:grid-name>
<oas:Security>
<!--Optional:-->
<oas:UsernameToken>
<oas:Username>Network</oas:Username>
<oas:Password>password</oas:Password>
</oas:UsernameToken>
</oas:Security>
</soapenv:Header>
<soapenv:Body>
<dst:TrySoap-Request>
<dst:strInput1>abc</dst:strInput1>
<dst:strInput2>abc123</dst:strInput2>
</dst:TrySoap-Request>
</soapenv:Body>
</soapenv:Envelope>
我正在使用Python suds
。但是,我还没有围绕如何控制标题。因为我还在尝试发现如何将成功的SOAP调用发送到我的内部测试主机(它确实响应soapUI),所以我只得到了一些黑客攻击。
from suds.client import *
from suds.transport.http import HttpAuthenticated
from suds.wsse import *
from suds.xsd.sxbasic import Import
from suds.sax.element import Element
def main():
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
url = 'http://10.1.1.1:8080/path/name/wsdl?grid-name=GRID01'
client = Client(url, faults=False)
tag_name1 = ('urn', url)
urn = Element('grid-name', ns=tag_name1).setText('GRID01')
client.set_options(soapheaders=urn)
print client.service.TrySoap('abc','123')
这会产生像这样的SOAP信封......
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="Sandbox" xmlns:urn="http://10.1.1.1:8080/path/name/wsdl?grid-name=GRID01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<urn:grid-name>GRID01</urn:grid-name>
</SOAP-ENV:Header>
<ns0:Body>
<ns1:TrySoap-Request>
<ns1:strInput1>abc</ns1:strInput1>
<ns1:strInput2>xyz</ns1:strInput2>
</ns1:TrySoap-Request>
</ns0:Body>
</SOAP-ENV:Envelope>
我理解其工作原理的程度仅仅是我发送的信封看起来与我发布的第一个样本完全一样。此请求不起作用,服务器响应,&#34; DEBUG:suds.client:http失败:&#34;
我知道我的python generated header doesn't match
。
问题:
urn
元素?或者有更好的方法吗?xmlns:urn="urn:realops.com:amp:workflow"
?conversion tool
我可以在其中提供格式化的信封并让它吐出Python构成该信封所需的代码?答案 0 :(得分:0)
一位同事为我提供了这个测试呼叫的解决方案......
from suds.client import Client
from suds.wsse import *
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
url = 'http://10.1.1.1:8080/file/path/wsdl?grid-name=GRID01'
client = Client(url)
security = Security()
token = UsernameToken('JoeBob','password')
security.tokens.append(token)
client.set_options(wsse=security)
gridns = ('tns','urn:realops.com:amp:workflow')
grid = Element('grid-name',ns=gridns).setText('GRID01')
client.set_options(soapheaders=grid)
result = client.service.TrySoap('abc','123')
print result
这产生了这个信封。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:tns="urn:realops.com:amp:workflow" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="Sandbox" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<wsse:Security mustUnderstand="true">
<wsse:UsernameToken>
<wsse:Username>JoeBob</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<tns:grid-name>GRID01</tns:grid-name>
</SOAP-ENV:Header>
<ns0:Body>
<ns1:TrySoap-Request>
<ns1:strInput1>abc</ns1:strInput1>
<ns1:strInput2>123</ns1:strInput2>
</ns1:TrySoap-Request>
</ns0:Body>
</SOAP-ENV:Envelope>
这有效,但我想了解为什么好一点。我对标签的重要性感到困惑:变量格式。我也不太了解如何通过Element调用更改名称空间。