php - using stdClass() to create soap request wsdl complex type -
after finding php soap not handle arrays complex type, i'm using stdclass() i've coded creates soap request in wrong sequence. want idtag , idtaginfo in pairs below.
<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 wrong coming out 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 relevant part of wsdl
<s:complextype name="sendlocallistrequest"> <s:annotation> <s:documentation>defines 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 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 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 still falling @ last hurdle following produce list
while ($row2 = $db->getresult()) { $search_query[] = new soapstructauthorisationdata($row2['rfid'],array(new soapstructidtaginfo('concurrenttx'))); } // implode commas , remove last comma $search_list=implode(', ', $search_query); $search_list_nocommaend = rtrim($search_list, ', '); a var_dump of produces soapstructauthorisationdata, soapstructauthorisationdata, soapstructauthorisationdata, soapstructauthorisationdata, soapstructauthorisationdata
if enclose code above in speech marks "new soapstructauthorisationdata($row2['rfid'],array(new soapstructidtaginfo('concurrenttx')))"; produce whole thing wont show when following
if($soapservicesend->sendlocallist(new soapstructsendlocallistrequest($updatetype, $listversion, array( $search_list_nocommaend )))) if test piece works
$search=new soapstructauthorisationdata('bukiee',array(new soapstructidtaginfo('concurrenttx'))); any ideas anyone?
i've faced lot of times type of problems , i've found easiest solution: http://www.wsdltophp.com/
here upload wsdl , create classes needed communicate server.
try it, , maybe find don't have dealing creation of classes yourself.
ps. i've found data must not sent array, in general options unmark "send array parameter"
edit - code wsdl2php
<?php $soap = new saop2structsendlocallistrequest(); $soap->sendlocallist( new saop2structsendlocallistrequest( $updatetype, $listversion, array ( new saop2structauthorisationdata(), new saop2structauthorisationdata(), new saop2structauthorisationdata() ) ) );
Comments
Post a Comment