简体   繁体   English

从PHP SoapServer返回字符串数组

[英]Returning an array of string from PHP SoapServer

I am trying to build a soap service in PHP. 我试图在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). 我用于Web服务的WSDL是由Visual Studio 2010自动生成的(我只是使用Visual Studio创建WSDL,实际的服务器是使用SoapServer在PHP中构建的)。 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. 对soap服务的请求正在处理中,但是当我尝试返回字符串数组时,客户端没有得到任何结果。 Here is the relevant sections of the WSDL: 这是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: PHP服务器代码如下:

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. 我还尝试从PHP getGroups函数仅返回array('hello world') ,但这也行不通。 Can someone please help me correct the PHP code for returning an array of string that will match my WSDL definition. 有人可以帮我纠正PHP代码,以返回与我的WSDL定义匹配的字符串数组。

it works with this kind of complexType: 它适用于这种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: 在server.php中,有时添加行非常重要:

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

or results could be unpredictable. 否则结果可能无法预测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM