7

I need to implement a SPML interface, which in the end is performing a SOAP request over HTTP(s). I have a wsdl for it which boils down to this:

<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>

As you can see, the only defined request element is of type "xsd:anyType". I have a separate xsd, not at all linked in the wsdl, which describes how the request should be formed.

I'd like to use zeep to implement a SOAP request for consuming the interface. How can I make zeep aware of that (local) xsd file?

I have found the zeep.xsd.schema.SchemaDocument class, but no example of it being used anywhere. Can someone give me a usage example of how to create a client that uses an wsdl and separate xsd file?

  • 2
    Any luck with this @devOp_in_hiding? I'm facing the same problem and I could use some help – David Ortiz Mar 13 '18 at 23:16
  • 1
    I have given up on using libraries to create SOAP requests. Instead, I use SoapUI to create an example request, copy that into a string and post that to the SOAP interface in question using the requests library. – devOp_in_hiding Apr 03 '19 at 07:24
  • try py-suds because it permits to add schema with ImportDoctor. if neither py-suds works, as @devOp_in_hiding said ,i push a raw xml using requests.post. – Andrea Bisello Jan 22 '20 at 09:48

1 Answers1

6

Yes, you can add additional schemas to your zeep client the following way:

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()
leotrubach
  • 1,509
  • 12
  • 15