php soap client如何发送多维数组复杂类型?

时间:2013-02-13 10:56:49

标签: php soap soap-client

这是我想要制作的xml 我希望每个标签和taginfo都被xml标签包围,麻烦就是我 从数据库中获取许多列表,并且需要将此列表传递到中 肥皂客户? 请你帮助我,谢谢

这就是我需要的

 <ns1:sendListRequest><ns1:updateType>FULL</ns1:updateType>   
<ns1:listVersion>1</ns1:listVersion><ns1:AuthorisationList> 

<ns1:Tag>tag1</ns1:Tag><ns1:Taginfo>web example</ns1:Taginfo>   
<ns1:Tag>tag2</ns1:Tag><ns1:Taginfo>web  example2</ns1:Taginfo> 
  </ns1:AuthorisationList></ns1:sendListRequest></env:Body></env:Envelope> 

 this what I get <ns1:Tag>tag1tag2</ns1:Tag> which is probably expected from array  I'm using
  soap request 
   while ($row = $db->getResult()) {

   $tags[] = $row['tags'];
 }


 $tags=implode($list);
 $response = $client->SendList(array('updateType' => 
 $updatetype,'listVersion'  =>     $listversion,'AuthorisationList' =>  
 array('Tag' => $tags, 'Taginfo' => $taginfo));      

WSDL文件

    <s:complexType name="SendListRequest">
    <s:annotation>
      <s:documentation>Defines the SendList.req PDU</s:documentation>
    </s:annotation>
    <s:sequence>
      <s:element name="updateType" type="tns:UpdateType" minOccurs="1" maxOccurs="1" />
      <s:element name="listVersion" type="s:int" minOccurs="1" maxOccurs="1" />
     <s:element name="AuthorisationList" type="tns:AuthorisationData" minOccurs="0" maxoccurs="unbounded">
            </s:sequence>
   </s:complexType>

   <s:element name="sendListRequest" type="tns:SendListRequest" />
  <s:element name="sendListResponse" type="tns:SendListResponse" />
  </s:schema>
 </wsdl:types>

    <wsdl:message name="SendListInput">
<wsdl:part name="parameters" element="tns:sendListRequest" />
   </wsdl:message>

   <wsdl:message name="SendListOutput">
<wsdl:part name="parameters" element="tns:sendListResponse" />
 </wsdl:message>

  <wsdl:portType name="Service">
   <wsdl:operation name="SendList">
  <wsdl:input message="tns:SendListInput" wsaw:Action="/SendList" />
  <wsdl:output message="tns:SendListOutput" wsaw:Action="/SendListResponse" />
  </wsdl:operation>

  </wsdl:portType>


    <s:complexType name="AuthorisationData">
    <s:sequence>
      <s:element name="Tag" type="tns:IdToken" minOccurs="1" maxOccurs="1"/>
      <s:element name="TagInfo" type="tns:TagInfo" minOccurs="0" maxOccurs="1"/>
    </s:sequence>
  </s:complexType>

  <s:simpleType name="UpdateType">
    <s:restriction base="s:string">
      <s:enumeration value="Different"/>
      <s:enumeration value="Full"/>
    </s:restriction>
  </s:simpleType>

  <wsdl:service name="Service">
  <wsdl:documentation></wsdl:documentation>
  <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap">
  <soap12:address location="http://Service/" />
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

1 个答案:

答案 0 :(得分:0)

就我在WSDL中看到的而言,AuthorisationList是一个AuthorisationData序列,它是一个包含Tag和TagInfo的数组,所以我认为你的数组结构必须如下所示:

$toSend = array(
    'updateType' => $updatetype,
    'listVersion'  => $listversion,
    'AuthorisationList' => array(
        'AuthorisationData'=> array()
    )
);

// and this could be a way to add your db results:
while ($row = $db->getResult()) {
    // I can't see where you get the TagInfo from.
    $toSend['AuthorisationData'][] = array(
        'Tag'=>$row['tags'],
        'TagInfo'=> ? 
    ); 
}