Search code examples
pythonwcfsoapwsdl

Is it possible to replace schema locations in Suds/python?


I'm trying to hit a WCF service that's being hosted behind a reverse proxy/redirect. The WCF service is reporting the wrong schemaLocation, based on which machine it's actually being served from. For instance, I get something like this:

<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://badhost1.com/service.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://badhost1.com/service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>

Now, it shouldn't be http://badhost1.com, it should be http://goodhost.com. I can open the xsd in my browser if I point it to the goodhost version - obviously the badhost one doesn't work.

Is there a way to replace these bad endpoints with the correct one?


Solution

  • It turns out the one can create plugins. This one is an easy one:

    import re
    from suds.plugin import DocumentPlugin
    
    class FixUrls(DocumentPlugin):
        def loaded(self, context):
            context.document = re.sub(r'badhost\d', 'goodhost', context.document)
    

    And then it's called a la:

    client = Client(url, plugins=[plugin])
    

    That's all it takes!