tags:

views:

44

answers:

2

how can i convert SOAP struct like

 <wsdl:types>
  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/service1/"&gt;
   <xsd:complexType name="requestDescriptor">
    <xsd:all>
     <xsd:element name="x" type="xsd:string"></xsd:element>
     <xsd:element name="xx" type="xsd:string"></xsd:element>
     <xsd:element name="xxx" type="xsd:int"></xsd:element>
     <xsd:element name="xxxx" type="xsd:string"></xsd:element>

     <xsd:element name="xxxxx" type="xsd:string"></xsd:element>
    </xsd:all>
   </xsd:complexType>
  </xsd:schema>
 </wsdl:types>

to a php object if i call

$soapC = new SoapClient("http://192.168.1.3/forga/tests/vodSoapWS.wsdl");
$ret = $soapC->__getTypes();
$x = $ret[0];

the problem is $x type is string how can i used it as an object ??

A: 

i get around this by creating class which carry the struct and call

$req = new RequestDescriptor();
        $req->x="ar";
        $req->xx="JSON";
        $req->xxx="xxxxx";
        $req->xxxx="-1";
        $req->xxxxx="xwwx11";
        $x = new SoapVar($req,SOAP_ENC_OBJECT);
        $ret = $soapC->function($x);

but is there is any dynamic way to do that ???

S.Hawary
A: 

Not a proper ready to use answer, but take a look at __get and __set "magic" methods overloading.

Implementing them in your RequestDescriptor class (or in an upper level to generalize their use) will make you able to keep properties private or protected (as they should be in each object) and control which ones can be set. You can also use this to validate input before sending it to WS

In your answer's code, the risk to me is that you can call any var in the object potentially a real source of WS errors or worse, bugs (think of a misspelled property name, typo, etc)

Benoit
@Benoit:the problem will steel exist because the request descriptor would steel not connect with the struct var .. it return as a string which i need to parse (i think) to get the data structure ...
S.Hawary
You still have to use SoapVar to encode objects i guess
Benoit