Using SOAP::Lite client to handle server that sends responses missing namespace specification

224 Views Asked by At

I'm writing a SOAP::Lite client to work with a SOAP server that sometimes sends responses that are missing a namespace specification. This is the first time I've ever done anything with SOAP, so I'm not very knowledgeable at all. Here is an example response:

HTTP/1.1 200 OK
Server: "OS/version" UPnP/1.0 "product/version"
Content-Length: 83219
Content-Type: text/xml; charset="UTF-8"
Client-Date: Tue, 01 Aug 2017 06:30:44 GMT
Client-Peer: 192.168.1.123:5000
Client-Response-Num: 1

<?xml version="1.0" encoding="UTF-6"?>
<soap-env:Envelope
        xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
        soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        >
<soap-env:Body>
    <m:GetDataResponse
        xmlns:m="urn:BLACKBOX:service:DataSource:1">
        <DataBlob xsi:type="xsd:base64Binary">Ikf7SPJ...SsA==</DataBlob>
    </m:GetDataResponse>
    <ResponseCode>0</ResponseCode>
</soap-env:Body>
</soap-env:Envelope>

Notice the use of the 'xsi' namespace without specification. There should probably be one for 'xsd' too? SOAP::Lite is giving me this error message:

failed:  Unresolved prefix 'xsi' for attribute 'xsi:type'

How would I work around this with SOAP::Lite in the client, given that I have no control of the server? Is there some way for me to tell SOAP::Lite to assume namespaces I provide?

2

There are 2 best solutions below

10
Borodin On

The server is broken and you should raise an error. Meanwhile, you could get your code working by editing the incoming data, adding

these definitions to the Envelope element

xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1
rahed h On

Just add to SOAP::Lite object:

$soap->serializer->register_ns('http://www.w3.org/2001/XMLSchema' => 'xmlns:xsd');

$soap->serializer->register_ns('http://www.w3.org/2001/XMLSchema-instance' => 'xmlns:xsi');