Parse WSDL with Zeep

2019-05-20 04:05发布

问题:

I want to parse a WSDL file with Zeep and get out:

  • All the operations
  • Request xml messages for each operations

Any examples on parsing the wsdl?

I guess I should use zeep.wsdl and the parse_service method?

/A

回答1:

updated:

import operator
from zeep import Client

wsdl = 'http://www.soapclient.com/xml/soapresponder.wsdl'
client = Client(wsdl=wsdl)
for service in client.wsdl.services.values():
    print "service:", service.name
    for port in service.ports.values():
        operations = sorted(
            port.binding._operations.values(),
            key=operator.attrgetter('name'))

        for operation in operations:
            print "method :", operation.name
            print "  input :", operation.input.signature()
            print "  output:", operation.output.signature()
            print
    print


回答2:

solved:

client= Client('url_to_wsdl')
for service in client.wsdl.services.values():
    for port in service.ports.values():
        operations = sorted(
        port.binding._operations.values(),
        key=operator.attrgetter('name'))

        for operation in operations:
           print operation.name
           node = client.create_message(client.service, operation.name)
           print node


标签: zeep