簡體   English   中英

從PHP SoapServer返回字符串數組

[英]Returning an array of string from PHP SoapServer

我試圖在PHP中建立一個肥皂服務。 我用於Web服務的WSDL是由Visual Studio 2010自動生成的(我只是使用Visual Studio創建WSDL,實際的服務器是使用SoapServer在PHP中構建的)。 對soap服務的請求正在處理中,但是當我嘗試返回字符串數組時,客戶端沒有得到任何結果。 這是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>

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());
}

我還嘗試從PHP getGroups函數僅返回array('hello world') ,但這也行不通。 有人可以幫我糾正PHP代碼,以返回與我的WSDL定義匹配的字符串數組。

它適用於這種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>

在server.php中,有時添加行非常重要:

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

否則結果可能無法預測。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM