Question

I've check the other issues posted that are similar to this and none that I have seen are the same issues. I am going to post this question for both suds and pysimplesoap. I don't care which one I get to work but I kinda need to get one of them working soon. I think the problem may be with the WSDL being generated by a service created in .NET because I am having the same problem with pysimplesoap and every other python soap client I have tried. I have tried this with both suds and suds-jurko with the same results. I am not good with this SOAP stuff (I'd much rather be using a simple RESTful service with JSON) so any help would be very much appreciated. I do upvote and mark the accepted solution to my questions.

Here is the WSDL file

Here is my code:

from suds.client import Client
client = Client('http://url-for-my-service?wsdl')
result = client.service.StartSession('userid','passwd')

Here are the error messages I get:

ERROR:suds.client:<suds.sax.document.Document instance at 0x28fcbd8>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 581, in invoke
    result = self.send(soapenv)
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 619, in send
    description=tostr(e), original_soapenv=original_soapenv)
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 670, in process_reply
    raise WebFault(fault, replyroot)
suds.WebFault

I do kinda like suds better because I can enable logging.DEBUG and get more information:

DEBUG:suds.client:sending to (http://cpldevweb001:3691/Invoke?Handler=CSSoapService)
message:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:CSSoapService" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Header/>
   <ns2:Body>
      <ns1:StartSession>
         <user xsi:type="ns3:string">userid</user>
         <pass xsi:type="ns3:string">passwd</pass>
      </ns1:StartSession>
   </ns2:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': '"#StartSession"', 'Content-Type': 'text/xml; charset=utf-8'}
DEBUG:suds.client:HTTP failed - 500 - Internal Server Error:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP:Body>
   <SOAP:Fault>
     <faultcode>SOAP:Client</faultcode>
     <faultcode>Invalid Request</faultcode>
     <detail>Invalid SOAP Request, most probable incorrect SOAPAction</detail>
   </SOAP:Fault>
  </SOAP:Body>
</SOAP:Envelope>
Was it helpful?

Solution

The vendor provided a working sample client that I was able to run with TcpMon and compare the XML being sent with what was being generated by suds. It turns out the issue was the empty <SOAP-ENV:Header/> tag.

I created a message plugin to filter out the empty Header during the sending phase and now it works. Here is the updated code:

import re

from suds.client import Client
from suds.plugin import MessagePlugin

class HeaderFilter(MessagePlugin):

    def sending(self, context):
        context.envelope = re.sub(r'<[A-Za-z0-9_\-:]*Header/>', '', context.envelope)
        return context

client = Client('http://url-for-my-service?wsdl', plugins=[HeaderFilter()]) 
result = client.service.StartSession('userid','passwd')

I might have been more specific instead of using the regex but I don't know if it will always use the SOAP-ENV prefix or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top