简体   繁体   English

使用stdClass()创建soap请求wsdl复杂类型

[英]using stdClass() to create soap request wsdl complex type

After finding PHP soap does not handle arrays with a complex type, I'm now using stdClass() I've coded something but it creates the soap request in the wrong sequence. 在发现PHP soap无法处理具有复杂类型的数组之后,我现在使用stdClass()编写了一些代码,但是它以错误的顺序创建了soap请求。 I want the idtag and idtaginfo to be in pairs like below. 我希望idtag和idtaginfo成对,如下所示。

     <soap:Body>
     <ns:sendLocalListRequest>
     <ns:updateType>full</ns:updateType>
     <ns:listVersion>1</ns:listVersion>

     <ns:localAuthorisationList>

           <ns:idTag>1</ns:idTag>
                   <ns:idTagInfo>
                      <ns:status>good</ns:status>
                    </ns:idTagInfo>

            <ns:idTag>2</ns:idTag>
                   <ns:idTagInfo>
           <ns:status>bad</ns:status>
                    </ns:idTagInfo>

     </ns:localAuthorisationList>

  </ns:sendLocalListRequest>
   </soap:Body>

my soap request which is wrong is coming out like the below 我的肥皂请求错了,如下所示

  <env:Body><ns1:sendLocalListRequest><ns1:updateType>FULL</ns1:updateType>
  <ns1:listVersion>1</ns1:listVersion>

  <ns1:localAuthorisationList>
  <ns1:idTag>1</ns1:idTag><ns1:idTag>2</ns1:idTag>

 <ns1:idTagInfo><ns1:status>good</ns1:status><ns1:status>bad</ns1:status>
  </ns1:idTagInfo>
   </ns1:localAuthorisationList></ns1:sendLocalListRequest></env:Body>

this is relevant part of the wsdl 这是wsdl的相关部分

 <s:complexType name="SendLocalListRequest">
    <s:annotation>
      <s:documentation>Defines the SendLocalList.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="localAuthorisationList" type="tns:AuthorisationData"
       minOccurs="1" maxOccurs="unbounded" />
      <s:element name="hash" type="s:string" minOccurs="0" maxOccurs="1" />
    </s:sequence>
  </s:complexType>

    <s:complexType name="AuthorisationData">
          <s:sequence>
       <s:element name="idTag" type="tns:string" minOccurs="1" maxOccurs="unbounded"/>
      <s:element name="idTagInfo" type="tns:IdTagInfo" minOccurs="1"
     maxOccurs="unbounded"/>
            </s:sequence>
                 </s:complexType>

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

 <s:complexType name="SendLocalListResponse">
    <s:annotation>
      <s:documentation>Defines the SendLocalList.conf PDU</s:documentation>
    </s:annotation>
    <s:sequence>
      <s:element name="status" type="tns:UpdateStatus" minOccurs="1" maxOccurs="1" />
      <s:element name="hash" type="s:string" minOccurs="0" maxOccurs="1" />
    </s:sequence>
  </s:complexType>

 <s:complexType name="IdTagInfo">
    <s:sequence>
      <s:element name="status" type="s:string" minOccurs="1" maxOccurs="unbounded" />
      <s:element name="expiryDate" type="s:dateTime" minOccurs="0" maxOccurs="1"/>
      <s:element name="parentIdTag" type="tns:IdToken" minOccurs="0" maxOccurs="1"/>
    </s:sequence>
  </s:complexType>

This my code 这是我的代码

$search_query = new StdClass();
$search_query->updateType = $updatetype;
$search_query->listVersion = $listversion;

 $search_query->localAuthorisationList = new StdClass();

 while ($row = $db->getResult()) {


 $search_query->localAuthorisationList->idTag[] = $row['rfid'];

 $search_query->localAuthorisationList->idTagInfo->status[] = $row['status'];

 }


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

$path        = realpath($_SERVER["DOCUMENT_ROOT"]);
$endpoint    = $wsdl;
$soapOptions = array(    'exceptions'     => 0
                        ,'soap_version'   => SOAP_1_2
                        ,'trace'          => true
                                                                    ,'uri' => $theversion
                        ,'location' => $url
                                                    ); 

$header = new SoapHeader($theversion,'', $ppid);

$client->__setSoapHeaders($header);  

    $response = $client->SendLocalList($search_query);

Update 更新

I've got close but still falling at the last hurdle the following will produce the list 我已经接近了,但仍然处于最后一个障碍,以下将产生列表

while ($row2 = $db->getResult()) { 
$search_query[] = new  SoapStructAuthorisationData($row2['rfid'],array(new 
SoapStructIdTagInfo('ConcurrentTx'))); 
}

// implode with commas and remove last comma

$search_list=implode(', ', $search_query);

$search_list_nocommaend = rtrim($search_list, ', ');

a var_dump of this produces SoapStructAuthorisationData, SoapStructAuthorisationData, SoapStructAuthorisationData, SoapStructAuthorisationData, SoapStructAuthorisationData 这样的var_dump会产生SoapStructAuthorisationData,SoapStructAuthorisationData,SoapStructAuthorisationData,SoapStructAuthorisationData,SoapStructAuthorisationData

if I enclose the code above in speech marks like "new SoapStructAuthorisationData($row2['rfid'],array(new SoapStructIdTagInfo('ConcurrentTx')))"; 如果我将上面的代码括在诸如“ new SoapStructAuthorisationData($ row2 ['rfid'],array(new SoapStructIdTagInfo('ConcurrentTx'))))之类的语音标记中; is will produce the whole thing but this wont show when I do the following 将产生整个事情,但是当我执行以下操作时这不会显示

  if($soapServiceSend->SendLocalList(new SoapStructSendLocalListRequest($updateType,
     $listversion, 
  array( $search_list_nocommaend ))))

if I do something like this for a test piece it works 如果我为试件做这样的事情,它会工作

$search=new SoapStructAuthorisationData('BUKIEE',array(new 
SoapStructIdTagInfo('ConcurrentTx')));

Any ideas anyone? 有任何想法吗?

I've faced a lot of times this type of problems and I've found the easiest solution: http://www.wsdltophp.com/ 我已经多次遇到这种类型的问题,并且找到了最简单的解决方案: http : //www.wsdltophp.com/

Here you upload your WSDL and it will create all the classes needed to communicate with the server. 在这里,您上载WSDL,它将创建与服务器通信所需的所有类。

Try it, and you maybe will find that you don't have to be dealing with the creation of the classes by yourself. 尝试一下,您可能会发现您不必自己处理类的创建。

Ps. 附言 I've found that sometimes the data must not be sent as array, so in the general options unmark " Send An Array As Parameter " 我发现有时数据不一定要作为数组发送,因此在常规选项中取消标记“ 将数组作为参数发送

EDIT - Code from Wsdl2PHP 编辑-来自Wsdl2PHP的代码

<?php
$soap = new Saop2StructSendLocalListRequest(); 
$soap->SendLocalList(
    new Saop2StructSendLocalListRequest(
        $updateType, 
        $listversion, 
        array (
            new Saop2StructAuthorisationData(), 
            new Saop2StructAuthorisationData(), 
            new Saop2StructAuthorisationData()
        )
    )
);

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

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