简体   繁体   中英

SOAP: Returning an array of xsd:any elements in PHP

I need to return SOAP call answer according to WSDL. Everything is working OK, except returning xsd:any element. Part of the WSDL, that I'm having problem with (this is for excpected answer).

xsd:complexType name="data"
        xsd:sequence
         xsd:any minOccurs="1" maxOccurs="unbounded"
        xsd:sequence
    xsd:complexType

What I tried:

foreach($data as $name=>$value) {
        $object->data->any[$name] = $value;
    }
    return $object;

The SOAP call returns answer like this:

..response>
    -data>value1value2value3value4-/data>
    .../response>

Although before returning the object, it can be seen, that the object is created as it should have been:

$object->data->any[name1] = value1
    $object->data->any[name2] = value2

    etc...

But in the return asnwer, all the values are just put into one string into one return field. This code and returning works correctly with any other field type (for example xsd:string etc).

How should the object be returned in case of xsd:any type, to get the answer with multiple fields according to the names and values?

Thanks

Solved the problem.

I had to create SoapVar object for the field.

$o = new Object();
    $o->field = $value;
    $object->data = new SoapVar($field, XSD_ANYTYPE);
    return $object;

Thanks

这也应该起作用:

$object->data = new SoapVar($data, SOAP_ENC_OBJECT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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