How to access all Webservice methods from a Python Soap Client with multiple bindings using Python zeep

553 views Asked by At

I have to consume data from a SOAP service, which is a new technology for me. I connected from the server using the following code:

from requests import Session
from requests.auth import HTTPBasicAuth
from zeep import Client
from zeep.transports import Transport

wsdl= 'my_service.com/MEX?wsdl'
username = 'john_doe'
password = 'password'

session = Session()
session.auth = HTTPBasicAuth(username, password)
transport = Transport(session=session)
client = Client(wsdl=wsdl, transport=transport)

Using SoapUi software and connecting with this server I realized that it has three bindings and each one has a lot of Webservices. But, with Python, I was able only to access the WebServices (via client.service) for the first binding. I want to know how can I access the Webservice methods from another two bindings.

OBS: client.wsdl.bindings return a dict mapping some urls containing the binding names seen on SoapUI to Soap11Binding instances.

1

There are 1 answers

0
Tarique On

By default, Zeep picks up the first binding in the WSDL. This binding is available via client.service. To use a specific binding you can use the bind() method on the client object sample code:

service2 = client.bind('SecondService', 'Port12')
service2.someOperation(arg1='abc', arg2=2)