5

我需要实现一个SPML接口,它最终通过 HTTP(s) 执行 SOAP 请求。我有一个 wsdl 可以归结为:

<wsdl:types>
  <schema targetNamespace="http://soapadapter.something" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="receiveRequest" type="xsd:anyType"/>
  </schema>
</wsdl:types>
[...]
<wsdl:operation name="receiveRequest">
 <wsdl:input message="impl:receiveRequestRequest" name="receiveRequestRequest"/>
</wsdl:operation>

如您所见,唯一定义的请求元素是“xsd:anyType”类型。我有一个单独的 xsd,在 wsdl 中根本没有链接,它描述了应该如何形成请求。

我想使用 zeep 来实现一个 SOAP 请求来使用接口。我怎样才能让 zeep 知道那个(本地)xsd 文件?

我找到了这个zeep.xsd.schema.SchemaDocument类,但没有任何地方使用它的例子。有人可以给我一个使用示例,说明如何创建使用 wsdl 和单独 xsd 文件的客户端吗?

4

1 回答 1

4

是的,您可以通过以下方式将其他模式添加到您的 zeep 客户端:

import os
from zeep.loader import load_external
from zeep import Client


XSD_SCHEMA_FILE = "/path/to/your.xsd"
CONTAINER_DIR = os.path.dirname(XSD_SCHEMA_FILE)  # Where to load dependencies if any

client = Client('https://path/to/your.wsdl')
schema_doc = load_external(open(XSD_SCHEMA_FILE, "rb"), None)
doc = client.wsdl.types.create_new_document(schema_doc, f"file://{CONTAINER_DIR}")
doc.resolve()
于 2020-05-19T19:56:16.743 回答