Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 36 ยท Building and Consuming Services

Dynamic Clients from a WSDL

See how SOAP toolkits turn a WSDL into callable methods. Parse a WSDL 1.1 document in Node.js, list its operations and parameters, and build a proxy client that validates arguments before sending.

When you point a SOAP toolkit at a URL ending in ?wsdl, it gives you back an object with methods named after the service's operations. How does it know that getQuote exists, which parameters it needs, which URL to call and what SOAPAction to send? It read the WSDL, the service's machine-readable contract.

This lesson shows that mechanism in miniature. You will parse a WSDL 1.1 document (the document/literal wrapped style that almost every modern service uses), extract the operations, and build a dynamic client: a JavaScript Proxy whose method calls turn into SOAP requests. Once you have done it by hand, generated clients stop being mysterious.

The parts of a WSDL, as a client sees them

A client needs answers to four questions, and each lives in a different part of the document:

Question WSDL element
What data shapes exist? types (XML Schema)
What messages are exchanged? message and portType operations
How are they encoded and which SOAPAction? binding
Where do I send them? service / port / soap:address
flowchart TD
  S["service: CalcService"] --> P["port: CalcPort"]
  P --> B["binding: CalcBinding (SOAP/HTTP, document/literal)"]
  B --> T["portType: CalcPortType (operations)"]
  T --> M["messages"]
  M --> X["types: XML Schema elements"]

A client reads the diagram from the top down: service gives the address, binding the protocol rules, portType the operations, and types the data.

Parsing the contract

The example below contains a complete small WSDL and extracts what a client needs. The reader keeps attributes and drops namespace prefixes, which is enough for this contract.

Node.js Reading operations out of a WSDL

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The output lists each operation with typed parameters, straight from the contract. This is the data every toolkit works from: the generated Java class CalcPortType with a method int add(int a, int b) is simply this information rendered as code.

Turning the contract into method calls

Next we use that information. A Proxy intercepts any property access, checks that the name is an operation, validates the arguments against the declared types, builds the envelope, and returns the result. We combine it with a loopback service whose WSDL we serve ourselves, and replace the endpoint address with the real port (WSDLs often contain placeholder addresses).

Node.js A Proxy client that validates before sending

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The two invalid calls never reach the network: the client catches them using the contract. That is a major practical benefit of a WSDL, since mistakes surface on the caller's machine with a clear message.

Real WSDLs are more varied than our example: import of external schemas, xsd:complexType with nested types and arrays, rpc/encoded binding style, SOAP headers, multiple ports and faults declared per operation. Mature toolkits (Apache CXF wsdl2java, .NET svcutil / dotnet-svcutil, Python zeep) handle these; hand-rolled parsers such as ours do not. Use a toolkit in production.

Static versus dynamic clients

Generated (static) stubs Dynamic client
When code is created Build time Run time
Type safety Compile-time checks Run-time checks
Handles contract change Regenerate and rebuild Picks up automatically
Typical use Long-lived applications Tools, scripts, testing

Static stubs catch errors earlier; dynamic clients are handy for test tools and exploratory scripts. Tools like SoapUI are essentially large dynamic clients (see Testing SOAP Services).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which WSDL section tells a client the URL to call?

    The service element lists ports, and each port's soap:address gives the endpoint location.
  2. 2. Where does a client find the SOAPAction for an operation?

    The binding adds protocol details to each operation, including the soapAction attribute.
  3. 3. What is a benefit of validating arguments against the contract before sending?

    The client knows the types, so it can reject bad input immediately.
  4. 4. Which approach regenerates automatically when the service contract changes?

    A dynamic client reads the current WSDL, so new operations appear without a rebuild (though your code still has to use them).

Summary

  • A WSDL tells a client the data types, operations, protocol binding, SOAPAction values and endpoint.
  • Toolkits turn this into generated stubs or dynamic clients.
  • A Proxy over parsed operations is enough to build a client that validates input and calls a service.
  • Real WSDLs use imports, nested types, headers and faults, so use a maintained toolkit for production.

Next: SOAP with Java (JAX-WS) and .NET (WCF)