Welcome to WebmasterWorld Guest from 18.212.92.235

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP SOAP problem with SOAP-ENC:Struct

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

Junior Member

10+ Year Member

joined:July 12, 2006
posts: 49
votes: 0


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.

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

Senior Member from MZ 

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 9, 2005
posts:837
votes: 0


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);
}
}
}