0
votes

So I ran my post method for SOAP in Postman and received 200, the response headers had text/xml; charset=utf-8 for Content type. My Headers in Postman excluding the default values are

ClientID 700, SOAPAction urn, Content-Type text/xml

url = www.xyz.com.svc

The SOAP raw XML used to run in Postman.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
        <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.xsd" xmlns:wsu="http://docs.oa.xsd">
            <wsse:UsernameToken wsu:Id="UsernameToken-1234">
                <wsse:Username>E</wsse:Username>
                <wsse:Password Type="http://docs.o-username-token-profile-1.0#PasswordText">abcd</wsse:Password>
                <wsse:Nonce EncodingType="http://docs.o.security-1.0#Base64Binary">happy</wsse:Nonce>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
<ConfirmAppointment xmlns="urn:CompanyNameServices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--string occurs:0,1-->
<PatID xsi:nil="false">A1</PatID>
<!--string occurs:0,1-->
<PIDType xsi:nil="false">B</PIDType>
<!--string occurs:0,1-->
<MyCID xsi:nil="false">1</MyCID>
<!--string occurs:0,1-->
<MIDType xsi:nil="false">External</MyIDType>
<!--string occurs:0,1-->
<AppCID xsi:nil="false">1</AppCID>
</ConfirmAppointment>
    </soapenv:Body>
</soapenv:Envelope>

I am trying to run this using Python requests.post, here is my code.

soap_body = '''

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
        <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.xsd" xmlns:wsu="http://docs.oa.xsd">
            <wsse:UsernameToken wsu:Id="UsernameToken-1234">
                <wsse:Username>E</wsse:Username>
                <wsse:Password Type="http://docs.o-username-token-profile-1.0#PasswordText">abcd</wsse:Password>
                <wsse:Nonce EncodingType="http://docs.o.security-1.0#Base64Binary">happy</wsse:Nonce>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
<ConfirmAppointment xmlns="urn:CompanyNameServices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--string occurs:0,1-->
<PatID xsi:nil="false">A1</PatID>
<!--string occurs:0,1-->
<PIDType xsi:nil="false">B</PIDType>
<!--string occurs:0,1-->
<MyCID xsi:nil="false">1</MyCID>
<!--string occurs:0,1-->
<MIDType xsi:nil="false">External</MyIDType>
<!--string occurs:0,1-->
<AppCID xsi:nil="false">1</AppCID>
</ConfirmAppointment>
    </soapenv:Body>
</soapenv:Envelope>'''

headers = {
'ClientID': '700',
'SOAPAction': 'urn',
'Content-Type': 'text/xml'
}

response = requests.post(url=url, data=soap_body, headers=headers)
print(response)

My output: <Response [500]>

If I add <?xml version="1.0" encoding="UTF-8"?> to the beginning of my body, my output: <Response [400]>

What am I doing wrong here?

1
Is there a response body when you receive the 500? It may explain the issue. Also try SoapUI. - Mike67
it's for work but it just gives me links that are blocked. b'<s:Envxmlns:s="schemas.xmlsoap.org/soap/envelope" xmlns:u="docs.oasis-open.org/wss/2004/01/… s:mustUnderstand="1" xmlns:o="docs.open.org/wss/2004/01/… u:Id="_0"><Created>2020-09</Created><Expires>2020-09</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><s:Fault><faultc:a="urn:com:Interconnect.2">a</faultcode>">An application error occurred. Details are logged in the Interconnect trace logs - JT Saiyan
The urls are namespaces, not actual web sites. Are you using HTTPS in postman and python? - Mike67
can you clarify what you mean by https? If you are not talking about the url then I haven't a clue, since it's my first time using soap. - JT Saiyan

1 Answers

0
votes

Here are 2 sample SOAP requests. See if they work for you.

import requests

url = "https://httpbin.org/post"

headers = {"content-type" : "application/soap+xml"}
body = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="https://httpbin.org/post">
   <soapenv:Header/>
   <soapenv:Body/>
</soapenv:Envelope>
""".strip()

response = requests.post(url, data = body, headers = headers)
print(response.content.decode("utf-8") +'\n')

###########################################

url = "https://www.dataaccess.com/webservicesserver/NumberConversion.wso"

headers = {"content-type" : "application/soap+xml"}
body = """
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
      <ubiNum>500</ubiNum>
    </NumberToWords>
  </soap:Body>
</soap:Envelope>
""".strip()

response = requests.post(url, data = body, headers = headers)
print(response.content.decode("utf-8") +'\n')