Skip to content

WSDL Modeling

The implementation is experimental and currently only WSDL 1.1 and SOAP 1.1 bindings have been implemented.

The code generator in addition to models derived from xml schemas will also generate dataclasses for messages and simple classes to describe the unique operations.

Make sure you install both cli and soap requirements.

$ pip install xsdata[cli,soap]
$ xsdata --package calculator

Message Model

The message models are not any different to xsd derived classes and include the complete structure of the Envelope wrapper.

class CalculatorSoapAddInput:
    class Meta:
        name = "Envelope"
        namespace = ""

    body: Optional["CalculatorSoapAddInput.Body"] = field(
            "name": "Body",
            "type": "Element",

    class Body:
        add: Optional[Add] = field(
                "name": "Add",
                "type": "Element",
                "namespace": "",

Operation Class

The DefinitionsMapper will generate simple static classes to describe all the unique operations and the binding procedure.

class CalculatorSoapAdd:
    style = "document"
    location = ""
    transport = ""
    soap_action = ""
    input = CalculatorSoapAddInput
    output = CalculatorSoapAddOutput


The Client is a proxy for consuming web services. The client needs a web service Config with the directives to process requests and responses.

Optionally you can also provide and override

Creating instances

The client can be initialized from the operation class directly

>>> from xsdata.formats.dataclass.client import Client
>>> from tests.fixtures.calculator import CalculatorSoapAdd
>>> client = Client.from_service(CalculatorSoapAdd)
>>> client.config
Config(style='document', location='', transport='', soap_action='', input=<class ''>, output=<class ''>, encoding=None)

But you can also override any properties as you see fit

>>> client = Client.from_service(CalculatorSoapAdd, location="")
>>> client.config
Config(style='document', location='', transport='', soap_action='', input=<class ''>, output=<class ''>, encoding=None)

Or if you know what you are doing

config = Config(
client = Client(config=config)

Override transport

Initialize transport with a custom requests session instance.

from requests import Session

transport = DefaultTransport(session=Session())
client = Client(config=config, transport=transport)

Performing Requests

The send method requires either an object that matches the config input type or a dictionary with raw values that matches the input dataclass field names and structure.

request = CalculatorSoapAddInput(body=CalculatorSoapAddInput.Body(add=Add(10, 2)))
# CalculatorSoapAddOutput(body=CalculatorSoapAddOutput.Body(add_response=AddResponse(add_result=12)))
client = Client.from_service(CalculatorSoapAdd)
params = {"body": {"add": {"int_a": 3, "int_b": 4}}}
# CalculatorSoapAddOutput(body=CalculatorSoapAddOutput.Body(add_response=AddResponse(add_result=7)))

You can also provide a dictionary of custom headers as well, although the headers that are needed for the webservice to work can not be overwritten.,

client.send(params, headers={"User-Agent": "xsdata"})

You will need to encode the payload if you intend to send non-ascii characters.

client = Client.from_service(encoding="utf-8")