or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

client-operations.mdexception-handling.mdindex.mdplugin-system.mdtransport-settings.mdwsse-security.mdxsd-types.md

client-operations.mddocs/

0

# Client Operations

1

2

Core SOAP client functionality for connecting to web services, calling operations, and handling responses. Zeep provides synchronous, asynchronous, and caching client variants with automatic WSDL parsing and type conversion.

3

4

## Capabilities

5

6

### Main Client Class

7

8

The primary interface for SOAP web service interactions, handling WSDL parsing, service binding, and operation execution.

9

10

```python { .api }

11

class Client:

12

def __init__(

13

self,

14

wsdl: str,

15

wsse=None,

16

transport=None,

17

service_name: str = None,

18

port_name: str = None,

19

plugins: list = None,

20

settings=None

21

):

22

"""

23

Create a SOAP client for the given WSDL.

24

25

Parameters:

26

- wsdl: URL or file path to WSDL document

27

- wsse: WSSE security configuration

28

- transport: Custom transport instance

29

- service_name: Specific service name to use

30

- port_name: Specific port name to use

31

- plugins: List of plugin instances

32

- settings: Settings instance for configuration

33

"""

34

35

@property

36

def service(self):

37

"""Default ServiceProxy instance for calling operations."""

38

39

@property

40

def namespaces(self) -> dict:

41

"""WSDL namespace prefix mappings."""

42

43

def bind(self, service_name: str = None, port_name: str = None):

44

"""

45

Create ServiceProxy for specific service/port combination.

46

47

Parameters:

48

- service_name: Name of the service to bind to

49

- port_name: Name of the port to bind to

50

51

Returns:

52

ServiceProxy instance

53

"""

54

55

def create_service(self, binding_name: str, address: str):

56

"""

57

Create ServiceProxy for given binding and endpoint address.

58

59

Parameters:

60

- binding_name: QName of the binding

61

- address: Endpoint URL

62

63

Returns:

64

ServiceProxy instance

65

"""

66

67

def create_message(self, service, operation_name: str, *args, **kwargs):

68

"""

69

Create SOAP message payload for operation.

70

71

Parameters:

72

- service: Service instance

73

- operation_name: Name of operation to create message for

74

- args, kwargs: Operation parameters

75

76

Returns:

77

lxml.etree._Element: SOAP message envelope

78

"""

79

80

def get_type(self, name: str):

81

"""Get XSD type by qualified name."""

82

83

def get_element(self, name: str):

84

"""Get XSD element by qualified name."""

85

86

def type_factory(self, namespace: str):

87

"""

88

Return type factory for given namespace.

89

90

Parameters:

91

- namespace: Target namespace for type factory

92

93

Returns:

94

Factory instance for creating types

95

"""

96

97

def set_ns_prefix(self, prefix: str, namespace: str):

98

"""

99

Set namespace prefix shortcut.

100

101

Parameters:

102

- prefix: Short prefix to use

103

- namespace: Full namespace URI

104

"""

105

106

def set_default_soapheaders(self, headers):

107

"""

108

Set default SOAP headers for all operations.

109

110

Parameters:

111

- headers: Default headers to include in requests

112

"""

113

```

114

115

### Async Client

116

117

Asynchronous SOAP client for non-blocking operations using httpx for HTTP transport.

118

119

```python { .api }

120

class AsyncClient(Client):

121

"""

122

Asynchronous SOAP client using AsyncTransport.

123

124

All methods from Client are available as async variants.

125

Requires 'httpx' package for async HTTP support.

126

"""

127

128

async def __aenter__(self):

129

"""Async context manager entry."""

130

131

async def __aexit__(self, exc_type, exc_val, exc_tb):

132

"""Async context manager exit."""

133

```

134

135

### Caching Client

136

137

SOAP client with built-in response caching for improved performance.

138

139

```python { .api }

140

class CachingClient(Client):

141

"""

142

Client with automatic caching of SOAP responses.

143

144

Inherits all functionality from Client with added caching capabilities.

145

Cache configuration is handled through Transport settings.

146

"""

147

```

148

149

### Factory Class

150

151

Helper for creating XSD types and elements from WSDL namespaces.

152

153

```python { .api }

154

class Factory:

155

def __init__(self, types, kind: str, namespace: str):

156

"""

157

Create factory for XSD types/elements.

158

159

Parameters:

160

- types: Types registry

161

- kind: 'type' or 'element'

162

- namespace: Target namespace

163

"""

164

165

def __getattr__(self, key: str):

166

"""Get type/element by local name."""

167

168

def __getitem__(self, key: str):

169

"""Get type/element by local name (alternative syntax)."""

170

```

171

172

## Usage Examples

173

174

### Basic Client Usage

175

176

```python

177

from zeep import Client

178

179

# Simple SOAP service call

180

client = Client('http://www.dneonline.com/calculator.asmx?WSDL')

181

result = client.service.Add(intA=10, intB=20)

182

print(f"Result: {result}")

183

184

# Access service information

185

print("Available operations:")

186

for operation in client.service._binding._operations.keys():

187

print(f" - {operation}")

188

```

189

190

### Service Binding

191

192

```python

193

from zeep import Client

194

195

client = Client('http://example.com/multi-service.wsdl')

196

197

# Use default service

198

default_result = client.service.DefaultOperation(param='value')

199

200

# Bind to specific service/port

201

specific_service = client.bind('SpecificService', 'SpecificPort')

202

specific_result = specific_service.SpecificOperation(param='value')

203

204

# Create service with custom endpoint

205

custom_service = client.create_service(

206

'{http://example.com}ServiceBinding',

207

'http://custom-endpoint.com/service'

208

)

209

custom_result = custom_service.Operation(param='value')

210

```

211

212

### Async Client Usage

213

214

```python

215

import asyncio

216

from zeep import AsyncClient

217

218

async def call_soap_service():

219

async with AsyncClient('http://example.com/service.wsdl') as client:

220

result = await client.service.AsyncOperation(param='value')

221

return result

222

223

# Run async operation

224

result = asyncio.run(call_soap_service())

225

```

226

227

### Working with Complex Types

228

229

```python

230

from zeep import Client

231

232

client = Client('http://example.com/service.wsdl')

233

234

# Create complex type instance

235

address_type = client.get_type('{http://example.com}Address')

236

address = address_type(

237

street='123 Main St',

238

city='Anytown',

239

state='CA',

240

zip='12345'

241

)

242

243

# Use in operation

244

result = client.service.UpdateAddress(address=address)

245

246

# Use type factory for creating types

247

factory = client.type_factory('http://example.com')

248

person = factory.Person(name='John', age=30)

249

250

# Set namespace prefix shortcut

251

client.set_ns_prefix('ex', 'http://example.com')

252

person_type = client.get_type('ex:Person')

253

254

# Set default SOAP headers

255

client.set_default_soapheaders([

256

{'name': 'Authentication', 'value': 'Bearer token123'}

257

])

258

```