BruceHill
BruceHill

Reputation: 7174

Returning an array of string from PHP SoapServer

I am trying to build a soap service in PHP. The WSDL that I am using for the webservice was autogenerated by Visual Studio 2010 (I just used Visual Studio to create the WSDL, the actual server is being built in PHP with SoapServer). The requests to the soap service are being handled, but when I try return an array of string, the client is not getting any results back. Here is the relevant sections of the WSDL:

<s:element name="getGroups">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="code" type="s:string" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:element name="getGroupsResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="getGroupsResult" type="tns:ArrayOfString" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ArrayOfString">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string" />
    </s:sequence>
  </s:complexType>
  .
  .
  <wsdl:message name="getGroupsSoapIn">
     <wsdl:part name="parameters" element="tns:getGroups" />
  </wsdl:message>
  <wsdl:message name="getGroupsSoapOut">
     <wsdl:part name="parameters" element="tns:getGroupsResponse" />
  </wsdl:message>
  .
  .
  <wsdl:operation name="getGroups">
      <wsdl:input message="tns:getGroupsSoapIn" />
      <wsdl:output message="tns:getGroupsSoapOut" />
  </wsdl:operation>

The PHP server code is as follows:

function getGroups($args)
{
    return array('ArrayOfString' => array('hello world'));
}

$server = new SoapServer( 'admin.wsdl' );
$server->addFunction('getGroups');
try {
    $server->handle();
}
catch (Exception $e) {
    $server->fault('Sender', $e->getMessage());
}

I also tried returning just array('hello world') from the PHP getGroups function, but that also did not work. Can someone please help me correct the PHP code for returning an array of string that will match my WSDL definition.

Upvotes: 1

Views: 1924

Answers (1)

Asain Kujovic
Asain Kujovic

Reputation: 2289

it works with this kind of complexType:

<s:complexType name="ArrayOfString2">
   <complexContent>
      <restriction base="SOAP-ENC:Array">
         <attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="string[]"/>
      </restriction>
   </complexContent>
</s:complexType>
.
.
<wsdl:message name="getGroupsSoapOut">
  <wsdl:part name="parameters" type="tns:ArrayOfString2" />
</wsdl:message>

inside server.php it is sometimes very important to add line:

ini_set("soap.wsdl_cache_enabled", "0");

or results could be unpredictable.

Upvotes: 1

Related Questions