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

末鹿安然 提交于 2019-12-20 07:14:53

问题


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


回答1:


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




回答2:


This should also work:

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


来源:https://stackoverflow.com/questions/13836242/soap-returning-an-array-of-xsdany-elements-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!