0

current behavior

I am trying to request a WCF service in python (binding is wsHttpBinding). However I am failing either using suds or zeep. It also failing when using a SOAP client like SOAP UI. The only way I manage to do it is to invoke it from Visual Studio WCF client or via C# code.

Python Suds

from suds.client import Client
import datetime

print("Connecting to Service...")
wsdl = "http://server_name/services/CdsSpread/CdsSpread.svc?wsdl"
client = Client(wsdl, headers={'Content-Type': 'application/soap+xml;charset=UTF-8'})
result = client.service.GetCounterpartiesInfo(datetime.datetime(2020, 11, 5), ['TOTO', 'TATA'])
print(result)

->

Exception: (400, 'Bad Request')

Python Zeep

from zeep import Client, Settings
import datetime

settings = Settings(strict=False, xml_huge_tree=True)
wsdl = r'http://server_name/services/CdsSpread/CdsSpread.svc?wsdl'
client = Client(wsdl=wsdl, settings=settings)
array_of_string = client.get_type('ns2:ArrayOfstring')
array = array_of_string(['TOTO', 'TATA'])
result = client.service.GetCounterpartiesInfo(asOfDate=datetime.datetime(2020, 11, 5), counterparties=array)
print(result)

->

zeep.exceptions.Fault: The message could not be processed. This is most likely because the action 'http://tempuri.org/ICdsSpread/GetCounterpartiesInfo' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

C#

static void Main(string[] args)
              {
                     var f = new ServiceReference1.CdsSpreadClient();
                     var e = f.GetCounterpartiesInfo(DateTime.Today.AddDays(-4), new[] { "TOTO", "TATA" });
                     Console.Write(e);

              }

-> the result is properly sent back by the service

expected behavior

Get the result properly in python like we do in C#

Thanks in advance for your help

JB Rolland
  • 87
  • 10
  • What binding does your server use? As far as I know suds can only support basichttpbinding, if you use a binding that suds does not support, an exception will occur. – Ding Peng Nov 10 '20 at 02:47
  • seems to be a wsHttpBinding (I also see mexHttpBinding in some part of the web.config) – JB Rolland Nov 11 '20 at 02:02
  • Suds does not support wsHttpBinding, suds seems to only support basichttpbinding. – Ding Peng Nov 13 '20 at 08:08
  • ok thx, neither Zeep? Any python lib able to mange wsHttpBinding? – JB Rolland Nov 14 '20 at 01:17
  • I don’t particularly understand python, but I found a SOAP client library for python on SO, you can refer to it: https://stackoverflow.com/questions/206154/what-soap-client-libraries-exist-for-python-and-where-is-the-documentation-for – Ding Peng Nov 17 '20 at 07:43

0 Answers0