1

PHP で SOAP サービスを構築しようとしています。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')を返そうとしましたが、これもうまくいきませんでした。私の WSDL 定義と一致する文字列の配列を返すための PHP コードを修正するのを手伝ってくれませんか。

4

1 に答える 1

1

この種の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");

または、結果が予測不能になる可能性があります。

于 2011-11-30T00:05:28.740 に答える