SOAP:在 PHP 中返回 xsd:any 元素的数组 [英] SOAP: Returning an array of xsd:any elements in PHP

查看:33
本文介绍了SOAP:在 PHP 中返回 xsd:any 元素的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据 WSDL 返回 SOAP 调用应答.一切正常,除了返回 xsd:any 元素.WSDL 的一部分,我遇到了问题(这是预期的答案).

<前>xsd:complexType 名称="数据"xsd:序列xsd:any minOccurs="1" maxOccurs="unbounded"xsd:序列xsd:复杂类型

我尝试了什么:

<前>foreach($data as $name=>$value) {$object->data->any[$name] = $value;}返回 $object;

SOAP 调用返回这样的答案:

<前>..回应>-数据>值1值2值3值4-/数据>.../响应>

虽然在返回对象之前,可以看出对象是按原样创建的:

<前>$object->data->any[name1] = value1$object->data->any[name2] = value2等等...

但是在返回asnwer中,所有的值都只是放在一个字符串中的一个返回字段中.此代码和返回适用于任何其他字段类型(例如 xsd:string 等).

xsd:any 类型的对象应该如何返回,根据名称和值得到多个字段的答案?

谢谢

解决方案

解决了问题.

我必须为该字段创建 SoapVar 对象.

<前>$o = new Object();$o->field = $value;$object->data = new SoapVar($field, XSD_ANYTYPE);返回 $object;

谢谢

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

这篇关于SOAP:在 PHP 中返回 xsd:any 元素的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆