duangelin7513 2018-07-25 08:58
浏览 542
已采纳

在nusoap中返回数组的数组

I'm developing a web service in PHP with NUSOAP and i have found the way to return an array. But what i'm trying to do his to return an array with array within. Example of array that i'm trying to return :

$return = array(
    'lastName' => "Dupond",
    'firstName' => array("Bryan", "Michael"),
    'nationality' => "NA",
    'gender' => "M" 
);

Actually when i return this array i'm getting "unable to serialize result" error. I know for sure that it's because it don't understand the array in firstName.

What my code actually look like :

function hello($name, $firstname)
{
    $lastName = "Name";
    $firstName = array("firstName1","firstName2");
    $nationality = "NA";
    $gender = "M";

    $return= array(
        'lastName' => $lastName,
        'firstName' => $firstName,
        'nationality' => $nationality,
        'gender' => $gender 
    );

    return $return;
}

$server = new soap_server();
$server->configureWSDL("CallHello", "urn:CallHello");
$server->wsdl->addComplexType(
    'Game', // the type's name
    'complexType',
    'struct',
    'all',
    '',
    array(
        'lastName' => array('name'=>'test','type'=>'xsd:string'),
        'firstName' => array('name'=>'test','type'=>'tns:test'),
        'nationality' => array('name'=>'test','type'=>'xsd:string'),
        'gender' => array('name'=>'test','type'=>'xsd:string'),
    )
);

$server->wsdl->addComplexType(
   'test', // the type's name
   'complexType',
   'struct',
   'all',
    '',
    array(
            array('name'=>'firtsname1','type'=>'xsd:string'),
            array('name'=>'firstname2','type'=>'xsd:string')
    )
);

$server->wsdl->addComplexType(
    'Games',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        array(
               'ref'=>'SOAP-ENC:arrayType',
               'wsdl:arrayType'=>'tns:Game[]'
        )   
    ),
    'tns:Game'
);

$server->register("hello",
    array("name" => "xsd:string","firstname" => "xsd:xml"),
    array("return" => "tns:Game"),
    "urn:CallHello",
    "urn:CallHello#hello",
    "rpc",
    "encoded",
    "Get a Person Data");

//$server->service('php://input');
$server->service($HTTP_RAW_POST_DATA);

This what the concerned part of my wsdl look like :

<xsd:complexType name="Game">
    <xsd:all>
        <xsd:element name="lastName" type="xsd:string"/>
        <xsd:element name="firstName" type="tns:test"/>
        <xsd:element name="nationality" type="xsd:string"/>
        <xsd:element name="gender" type="xsd:string"/>
    </xsd:all>
</xsd:complexType>

And what i want it too look like :

<xsd:complexType name="Game">
    <xsd:all>
        <xsd:element name="lastName" type="xsd:string"/>
        <xsd:complexType name="firstName">
            <xsd:all>
                <xsd:element name="firstName1" type="xsd:string"/>
                <xsd:element name="firstName2" type="xsd:string"/>
            </xsd:all>
        </xsd:complexType>
        <xsd:element name="nationality" type="xsd:string"/>
        <xsd:element name="gender" type="xsd:string"/>
    </xsd:all>
</xsd:complexType>
  • 写回答

1条回答 默认 最新

  • douyamitong57935 2018-07-31 12:46
    关注

    I had to make a work arround. This :

    $server->wsdl->addComplexType(
       'test', // the type's name
       'complexType',
       'struct',
       'all',
        '',
        array(
                array('name'=>'firtsname1','type'=>'xsd:string'),
                array('name'=>'firstname2','type'=>'xsd:string')
        ));
    

    Had to be like this :

    $server->wsdl->addComplexType(
       'test', // the type's name
       'complexType',
       'struct',
       'all',
        '',
        array(
               'firstName1' => array('name'=>'firstName2','type'=>'xsd:string'),
               'firstName2' => array('name'=>'firstName2','type'=>'xsd:string')
        )
    );
    

    And my array in my response had to be formated the same way. It's not exactly what i wanted but it work as expected.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘