Question

I am working on building a web service in PHP using the SoapServer class, but I'm running into an issue with casting of complex types.

The WSDL is completely valid, and the PHP SoapClient handles it flawlessly, but there seems to be an issue with the complex types that are returned not being cast properly. This came to light when consuming the service in .Net, as I was getting exceptions that indicated the type was not present in the given namespace.

I mangled my function numerous times, changing the namespace on the element, but .Net continues to give me errors, regardless of what namespace I use.

Consider the following abbreviation of the script:

function getCommands() {
    $output = array();
    // ...
    foreach($result as $row) {
        $output[] = new SoapVar($row, SOAP_ENC_OBJECT, 'ns1:command');
    }

    return $output;
}

The abbreviated response:

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="urn:MyWebService"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:getCommandsResponse>
      <return SOAP-ENC:arrayType="ns1:command[12]" xsi:type="ns1:ArrayOfCommand">
        <item xsi:type="ns1:command">
            <!-- ... -->
        </item>
      <!-- ... -->
      </return>
    </ns1:getCommandsResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

What I've noticed is that xmlns:ns1 is defined by way of the WSDL, and it does match the namespace in the WSDL. However, the .Net SOAP client doesn't seem to understand that the command element is defined there. It does, however, understand that that's where ArrayOfCommand is defined.

So my question is multipart:

  1. Is this a known bug with the SoapServer?
  2. If not, am I missing something grievous in my WSDL?
  3. Am I not encoding my objects properly?
  4. Is this an issue with .Net? If so, what's the work-around?
Was it helpful?

Solution

I was able to resolve this issue by working over the <types/> section of my WSDL again, using the Google WSDL for reference. Then, I had to work some magic in my PHP function, casting the elements of the $command appropriate to their respective types in the WSDL, and encoding the entire command as a ns2:command. When aligned with the WSDL, this all fell together nicely and .Net is having zero difficulty with it.

I'm surprised nobody in the development community was willing to answer this, but I hope someone will be able to glean from it at least some direction on how to fix their own instance of this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top