Manjyot Singh
Manjyot Singh

Reputation: 11

Python Zeep Client to consume Ontario Health EBS MCEDT WSDL(SOAP) webservice

I have been trying to use Zeep to generate SOAP envelope for calling a method in the following WSDL:

https://ws.conf.ebs.health.gov.on.ca:1443/EDTService/EDTService?wsdl

So far, I have come up with this:

from zeep import Client, xsd
from zeep.transports import Transport
from requests import Session
import urllib3
from zeep.plugins import HistoryPlugin

urllib3.disable_warnings()

session = Session()
session.verify = False
transport = Transport(session=session)

history = HistoryPlugin()
client = Client(wsdl='https://ws.conf.ebs.health.gov.on.ca:1443/EDTService/EDTService?wsdl', 
transport=transport, plugins=[history])

# client.wsdl.dump()

ebsheader = xsd.Element(
    '{http://ebs.health.ontario.ca/}EBS',
    xsd.ComplexType([
       xsd.Attribute(
          'Id',xsd.String()
       ),
       xsd.Element(
           'SoftwareConformanceKey', xsd.String()
       ),
       xsd.Element(
           'AuditId', xsd.String()
       ),
   ])
)
headers = []
headers.append(ebsheader('id-1','software-key-here','unique-id'))

response = client.service.getTypeList(_soapheaders=headers)

I am nowhere close to generating an envelope which looks like the samples provided in the API spec.

Being new to SOAP/WSDL, I am having a tough time understanding the super complex API spec http://www.health.gov.on.ca/en/pro/publications/ohip/docs/techspec_ebs.pdf

Has anyone been able to consume this API using Zeep?

Upvotes: 1

Views: 367

Answers (1)

Tarique
Tarique

Reputation: 1461

If you look at the documentation of zeep you can see that it makes it very easier to call the soap service methods.

1st of all you need to inspect the wsdl: python -mzeep https://ws.conf.ebs.health.gov.on.ca:1443/EDTService/EDTService?wsdl

then you can see the definition of getTypelist in there (considering the first binding):

getTypeList(_soapheaders={ebsrequest_header: ns0:ebs_header, msarequest_header: 
ns3:msa_header, idprequest_header: ns2:idp_header}) -> return: ns1:typeListResult

so you need to create ebs_header, msa_header & idp_header. create a factory for each:

factory0 = client.type_factory('ns0')
factory2 = client.type_factory('ns2')
factory3 = client.type_factory('ns3')

then create each of these elements:

ebs_header = factory0.ebs_header(SoftwareConformanceKey="key", AuditId="id")
print(ebs_header)

msa_header = factory3.msa_header(ServiceUserMUID="muid", UserID="uid")
print(msa_header)

idp_header = factory2.idp_header(ServiceUserMUID="muid")
print(idp_header)

# then create the _soapheaders
headers = {
    'ebsrequest_header' : ebs_header,
    'msarequest_header' : msa_header,
    'idprequest_header' : idp_header
    }

#finally call the method
response = client.service.getTypeList(_soapheaders=headers)

# you can see the sent request from plugin:
print(history.last_sent)

note that i tried to run the code but i get connection error.

Hope this helps.

Upvotes: 0

Related Questions