首先是得到wsdl,用xmlspy产生出一个request,
然后用urllib2写soap的头,把request放在soap的body里。
from ATOM.core import atomurllib2
def post_request_to_csa(soap_request_xml, etok=None):
WebService_URL = "http://localhost/MyWebService/GetTimeService.asmx/GetDay"
hdr = {
'Content-Type': 'text/xml; charset=utf-8',
'Host': 'localhost',
'Content-Length': len(soap_request_xml),
'SOAPAction': 'http://localhost/MyWebService/GetTimeService.asmx/GetDay'
}
try:
urllib2_request_obj = atomurllib2.Request(WebService_URL, data=soap_request_xml, headers=hdr)
opener = atomurllib2.build_opener()
atomurllib2.install_opener(opener)
f = atomurllib2.urlopen(urllib2_request_obj)
if f.getcode()==200:
soap_response = f.read()
print soap_response
return soap_response
except Exception:
print "error"
if __name__ == '__main__':
print "start"
xml='''<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:GetDay xmlns:m="http://tempuri.org/"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'''
post_request_to_csa(xml)