Unable to consume a .NET WCF service in Python
I am trying to access a .NET WCF web service from Python and am getting the following error – would anyone be able to let me know what I am doing wrong:
File "C:\temp\anaconda3\lib\site-packages\suds\mx\literal.py", line 87, in start raise TypeNotFound(content.tag) suds.TypeNotFound: Type not found: 'authToken'
Below is the python code that I have:
import uuid from suds.client import Client from suds.xsd.doctor import Import, ImportDoctor url = 'http://something/something?wsdl' imp = Import('http://www.w3.org/2001/XMLSchema', location='http://www.w3.org/2001/XMLSchema.xsd') imp = Import('http://schemas.xmlsoap.org/soap/encoding/') imp = Import('http://schemas.xmlsoap.org/soap/encoding/') imp.filter.add('http://tempuri.org/') doctor = ImportDoctor(imp) client = Client(url, doctor=doctor, headers={'Content-Type': 'application/soap+xml'}) logging.basicConfig(level=logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) logging.getLogger('suds.transport').setLevel(logging.DEBUG) logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG) logging.getLogger('suds.wsdl').setLevel(logging.DEBUG) client.set_options myMethod = client.factory.create('myMethod') myMethod.authToken = uuid.UUID('xxxxxxxx-35f4-4b7b-accf-yyyyyyyyyyyy') print(f'CLIENT: {client}') print(f'myMethod: {myMethod}') ls_Token = client.service.myMethod(myMethod) print(f'ACCESSTOKEN: {ls_Token}')
Create ResponseData object, the type is defined in wsdl, if there are multiple schemas, you need to add a prefix, such as ns0, ns1, etc.
ResponseData = client.factory.create('ns1:ResponseData') ResponseData.token = "Test"
Make sure that the properties of the object you created exist,You can view the properties of the object after successfully creating the object.
ResponseData = client.factory.create('ns1:ResponseData') ResponseData.token = "Test" print ResponseData
The following picture is the property of ResponseData object:
If I use the following code I will get the same error as you:
ResponseData = client.factory.create('ns1:ResponseData') ResponseData.authToken = "Test"
So you need to check whether the myMethod object has authToken property.