first of all it is my first experience with SOAP Webservice, so I'm trying to understand how to interpret it. The first step that I did was to read the wsdl file, for do that I needed to insert the username and password that the webservice provider gave. The webservice looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="http://infocomercial.cifin.asobancaria.com" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:intf="http://infocomercial.cifin.asobancaria.com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://infocomercial.cifin.asobancaria.com" xmlns:tns1="http://dto.infocomercial.cifin.asobancaria.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<!--WSDL created by Apache Axis version: 1.4
Built on Oct 06, 2010 (02:39:27 GMT)-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://dto.infocomercial.cifin.asobancaria.com">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ParametrosConsultaDTO">
<sequence>
<element name="codigoInformacion" nillable="true" type="soapenc:string"/>
<element name="motivoConsulta" nillable="true" type="soapenc:string"/>
<element name="numeroIdentificacion" nillable="true" type="soapenc:string"/>
<element name="tipoIdentificacion" nillable="true" type="soapenc:string"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<message name="consultaXmlRequest">
<part name="in0" type="tns1:ParametrosConsultaDTO"/>
</message>
<message name="consultaXmlResponse">
<part name="consultaXmlReturn" type="soapenc:string"/>
</message>
<message name="consultaPlanoRequest">
<part name="in0" type="tns1:ParametrosConsultaDTO"/>
</message>
<message name="consultaPlanoResponse">
<part name="consultaPlanoReturn" type="soapenc:string"/>
</message>
<message name="cambioPasswordRequest">
<part name="in0" type="soapenc:string"/>
</message>
<message name="cambioPasswordResponse">
<part name="cambioPasswordReturn" type="soapenc:string"/>
</message>
<portType name="InformacionComercialWS">
<operation name="consultaXml" parameterOrder="in0">
<input name="consultaXmlRequest" message="intf:consultaXmlRequest"/>
<output name="consultaXmlResponse" message="intf:consultaXmlResponse"/>
</operation>
<operation name="consultaPlano" parameterOrder="in0">
<input name="consultaPlanoRequest" message="intf:consultaPlanoRequest"/>
<output name="consultaPlanoResponse" message="intf:consultaPlanoResponse"/>
</operation>
<operation name="cambioPassword" parameterOrder="in0">
<input name="cambioPasswordRequest" message="intf:cambioPasswordRequest"/>
<output name="cambioPasswordResponse" message="intf:cambioPasswordResponse"/>
</operation>
</portType>
<binding name="InformacionComercialSoapBinding" type="intf:InformacionComercialWS">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="consultaXml">
<wsdlsoap:operation soapAction=""/>
<input name="consultaXmlRequest">
<wsdlsoap:body use="encoded" namespace="http://infocomercial.cifin.asobancaria.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output name="consultaXmlResponse">
<wsdlsoap:body use="encoded" namespace="http://infocomercial.cifin.asobancaria.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="consultaPlano">
<wsdlsoap:operation soapAction=""/>
<input name="consultaPlanoRequest">
<wsdlsoap:body use="encoded" namespace="http://infocomercial.cifin.asobancaria.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output name="consultaPlanoResponse">
<wsdlsoap:body use="encoded" namespace="http://infocomercial.cifin.asobancaria.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="cambioPassword">
<wsdlsoap:operation soapAction=""/>
<input name="cambioPasswordRequest">
<wsdlsoap:body use="encoded" namespace="http://infocomercial.cifin.asobancaria.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output name="cambioPasswordResponse">
<wsdlsoap:body use="encoded" namespace="http://infocomercial.cifin.asobancaria.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="InformacionComercialWSService">
<port name="InformacionComercial" binding="intf:InformacionComercialSoapBinding">
<wsdlsoap:address location="https://ttuweb3.universo.corp/InformacionComercialWS/services/InformacionComercial"/>
</port>
</service>
</definitions>
I can interpret according to this file the following:
- service name: InformacionComercialWSService
- port name: InformacionComercial
- possible operations: consultaXml, consultaPlano and cambioPassword
So, according to the development environment of the webservice I need to pass this info as parameters: 'codigoInformacion':"1401", 'motivoConsulta':"24", 'numeroIdentificacion':"80775779", 'tipoIdentificacion':"1"
The following is the SOAP UI Request that works:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inf="http://infocomercial.cifin.asobancaria.com">
<soapenv:Header/>
<soapenv:Body>
<inf:consultaXml soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<in0 xsi:type="dto:ParametrosConsultaDTO" xmlns:dto="http://dto.infocomercial.cifin.asobancaria.com">
<codigoInformacion xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1401</codigoInformacion>
<motivoConsulta xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">24</motivoConsulta>
<numeroIdentificacion xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">80775779</numeroIdentificacion>
<tipoIdentificacion xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</tipoIdentificacion>
</in0>
</inf:consultaXml>
</soapenv:Body>
</soapenv:Envelope>
Additionally I need to insert the certification of the company to confirm the footprint of the request. So to do that I decided to implement a python development because is my main language. I found a library call Zeep that allows use it as a soap client. The webservice documentation says that the authentication should be Http Basic, it is the unique information I have.
So I install the requirements as follows:
python = "^3.8"
zeep = "^4.0.0"
After that, I needed to research information to code using Zeep, the result is this:
import requests
from requests import Session
from requests.auth import HTTPBasicAuth # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
from zeep.transports import Transport
from zeep import xsd
session = Session()
session.cert = "XXXXXX/certificate.pem"
session.auth = HTTPBasicAuth("XXXXXX", "XXXX")
end_point= 'https://cifinpruebas.asobancaria.com/InformacionComercialWS/services/InformacionComercial?wsdl'
soap_client = Client(end_point,
transport=Transport(session=session), service_name="InformacionComercialWSService", port_name="InformacionComercial")
print("conexión establecida en :" + end_point)
request_data = {
'codigoInformacion':"1401",
'motivoConsulta':"24",
'numeroIdentificacion':"80775779",
'tipoIdentificacion':"1"
}
print(soap_client.service.consultaXml(**request_data))
I could solve many difficulties in the process, but I have been spend a lot of time in the following error that I don't understand how to solve it, and the webservice company is not supporting in coding because they only have information in Java and .Net. The error is:
Traceback (most recent call last):
File "prueba_wsdl.py", line 35, in <module>
print(soap_client.service.consultaXml(**request_data))
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/proxy.py", line 46, in __call__
return self._proxy._binding.send(
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 123, in send
envelope, http_headers = self._create(
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 73, in _create
serialized = operation_obj.create(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/definitions.py", line 222, in create
return self.input.serialize(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/messages/soap.py", line 73, in serialize
body_value = self.body(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 58, in __call__
instance = self.type(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/types/complex.py", line 63, in __call__
return self._value_class(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/valueobjects.py", line 106, in __init__
items = _process_signature(self._xsd_type, args, kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/valueobjects.py", line 241, in _process_signature
raise TypeError(
TypeError: ComplexType() got an unexpected keyword argument 'codigoInformacion'. Signature: `in0: {http://dto.infocomercial.cifin.asobancaria.com}ParametrosConsultaDTO`
I think, I'm not passing in the correct way the parameters, but I don't understand well the WSDL file, I was trying change the request for:
print(soap_client.service.consultaXml(**{'ParametrosConsultaDTO':request_data}))
but the error is like the same...
Traceback (most recent call last):
File "prueba_wsdl.py", line 35, in <module>
print(soap_client.service.consultaXml(**{'ParametrosConsultaDTO':request_data}))
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/proxy.py", line 46, in __call__
return self._proxy._binding.send(
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 123, in send
envelope, http_headers = self._create(
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 73, in _create
serialized = operation_obj.create(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/definitions.py", line 222, in create
return self.input.serialize(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/messages/soap.py", line 73, in serialize
body_value = self.body(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 58, in __call__
instance = self.type(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/types/complex.py", line 63, in __call__
return self._value_class(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/valueobjects.py", line 106, in __init__
items = _process_signature(self._xsd_type, args, kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/valueobjects.py", line 241, in _process_signature
raise TypeError(
TypeError: ComplexType() got an unexpected keyword argument 'ParametrosConsultaDTO'. Signature: `in0: {http://dto.infocomercial.cifin.asobancaria.com}ParametrosConsultaDTO`
Following this code https://stackoverflow.com/a/50093489/2607773 I could collect:
{'InformacionComercialWSService': {'InformacionComercial': {'operations': {'cambioPassword': {'input': {'in0': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}}}},
'consultaPlano': {'input': {'in0': {'optional': False,
'type': {'codigoInformacion': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}},
'motivoConsulta': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}},
'numeroIdentificacion': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}},
'tipoIdentificacion': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}}}}}},
'consultaXml': {'input': {'in0': {'optional': False,
'type': {'codigoInformacion': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}},
'motivoConsulta': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}},
'numeroIdentificacion': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}},
'tipoIdentificacion': {'optional': False,
'type': {'_value_1': {'optional': False,
'type': 'String(value)'}}}}}}}}}}}
So I change the request_data for:
request_data = {
'in0': {
'codigoInformacion': {
'_value_1': {
'optional': False,
'type': "1401"
}
},
'motivoConsulta': {
'_value_1': {
'optional': False,
'type': "24"
}
},
'numeroIdentificacion': {
'_value_1': {
'optional': False,
'type': "80775779"
}
},
'tipoIdentificacion': {
'_value_1': {
'optional': False,
'type': "1"
}
}
}
}
But I received another error:
Traceback (most recent call last):
File "prueba_wsdl.py", line 123, in <module>
print(soap_client.service.consultaXml(**request_data))
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/proxy.py", line 46, in __call__
return self._proxy._binding.send(
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 123, in send
envelope, http_headers = self._create(
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 73, in _create
serialized = operation_obj.create(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/definitions.py", line 222, in create
return self.input.serialize(*args, **kwargs)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/wsdl/messages/soap.py", line 79, in serialize
self.body.render(body, body_value)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/types/complex.py", line 295, in render
element.render(node, element_value, child_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/indicators.py", line 251, in render
element.render(parent, element_value, child_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/types/complex.py", line 295, in render
element.render(node, element_value, child_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/indicators.py", line 251, in render
element.render(parent, element_value, child_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 232, in render
self._render_value_item(parent, value, render_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
return self.type.render(node, value, None, render_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/types/complex.py", line 293, in render
element.type.render(node, element_value, None, child_path)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/types/simple.py", line 96, in render
node.text = self.xmlvalue(value)
File "/home/steven/.cache/pypoetry/virtualenvs/soap-conexion-hvcf0k35-py3.8/lib/python3.8/site-packages/zeep/xsd/types/builtins.py", line 27, in _wrapper
raise ValueError(
ValueError: The String type doesn't accept collections as value
Another thing that I did was to use Factory objects as the documentation says at factory object zeep:
factory = soap_client.type_factory('ns0')
request = factory.ParametrosConsultaDTO(codigoInformacion="1401", motivoConsulta="24", numeroIdentificacion="80775779",
tipoIdentificacion="1")
print(request)
try:
print(soap_client.service.consultaXml(request))
except requests.exceptions.ConnectionError as e:
response = "Without response"
print(response)
but it shows another error:
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fb685c865b0>: Failed to establish a new connection: [Errno -2] Name or service not known
I verified that .pem certificate still available and it works with SOAP UI.
If someone can help me, I'm very grateful, maybe I'm near to solve it.
Postdata: Sorry if my english is not very good.