Search code examples
phpweb-servicessoapwsdl

Using PHP SOAP client on .NET web service


I am trying to consume a .NET SOAP service but I'm currently just getting a 'false' response.

Visiting the service endpoint tells me the following:

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
            <SendData xmlns="http://tempuri.org/">
                <myObj>string</myObj>
            </SendData>
        </soap:Body>
    </soap:Envelope>

But when I check my request, it is sending the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
       <SOAP-ENV:Body>
           <ns1:SendData>
               <ns1:myObj>My data</ns1:myObj>
           </ns1:SendData>
       </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

So we can see that my request has different nodes titles and also adds in "ns1:" to the parameters.

Here is my (brief) PHP

$soap = new SoapClient('wsdl.xml', array("trace" => 1, "exception" => 1));
$call = $soap->__soapCall("SendData", array("SendData" => array("myObj" => "My data")));

So my question is: Could this difference in request schema be responsible for the request failing or is this just another way of writing the same thing? If it is responsible, is it possible to write my request exactly as specified at the endpoint?


Solution

  • It is the same thing.

    In the given example <SendData xmlns="http://tempuri.org/"> is without namespace prefix (the ns1 in your own request) so default prefix is used, and it specifies it with xmlns attribute for itself and its descendants.

    In your request ns1 namespace prefix is defined using xmlns:ns1="http://tempuri.org/" and used in <ns1:SendData>.