Forum Moderators: coopster

Message Too Old, No Replies

PHP SOAP problem with SOAP-ENC:Struct

         

cschults

3:32 am on Nov 27, 2008 (gmt 0)

10+ Year Member



I've created a web service in WSDL mode. The object I'm passing includes arrays of other objects. For example, a Class object includes an array of Section objects that each includes an array of Session objects.

Using the classmap parameter, my Class object is getting encoded properly, but my Section and Session objects are getting wrapped within <SOAP-ENC:Struct> instead of <section> and <session> respectively.

I'm very new to PHP SOAP, so I could use any help.

Thanks.

phparion

4:24 pm on Nov 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



brother, this is a known problem with PHP5 SOAP extension that it will not encode array of other objects properly.

But it has a work around, visit manual SOAP [php.net] and then search for "NODKZ" comments. He has shown the work around.

here is a snippet of class

abstract class SOAPable {
public function getAsSOAP() {
foreach($this as $key=>&$value) {
$this->prepareSOAPrecursive($this->$key);
}
return $this;
}

private function prepareSOAPrecursive(&$element) {
if(is_array($element)) {
foreach($element as $key=>&$val) {
$this->prepareSOAPrecursive($val);
}
$element=new SoapVar($element,SOAP_ENC_ARRAY);
}elseif(is_object($element)) {
if($element instanceof SOAPable) {
$element->getAsSOAP();
}
$element=new SoapVar($element,SOAP_ENC_OBJECT);
}
}
}