5

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

Andreas Blomqvist
  • 437
  • 1
  • 9
  • 22

2 Answers2

8

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
Dan H
  • 14,044
  • 6
  • 39
  • 32
4

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
Modus Tollens
  • 5,083
  • 3
  • 38
  • 46
Andreas Blomqvist
  • 437
  • 1
  • 9
  • 22
  • evenn tough @dan-h has responded before you, you have accepted your own answer, copying his. shame on you – ilhnctn Feb 22 '18 at 13:15
  • @ilhnctn Am I missing something? Dan H answered two months _later_ than this answer. – Modus Tollens Feb 22 '18 at 13:19
  • Auch.. Really sorry. I have just seen "4 '17 at 8:32" part, they are almost same :( Shame on me, i apologise. – ilhnctn Feb 22 '18 at 13:23
  • @ilhnctn It happens. But I hope you didn't downvote based on that. – Modus Tollens Feb 22 '18 at 13:24
  • 1
    Unfortunately i did but it doesnt let me upvote before edit the answer is edited, can you please the answer? Adding parantheses to print function will be enough :) – ilhnctn Feb 22 '18 at 13:26
  • This code generates `NameError: name 'operator' is not defined` so need to add to beginning `import operator` – chadn Oct 22 '21 at 19:51