繁体   English   中英

在nusoap中返回数组数组

[英]Returning array of array in nusoap

我正在使用 NUSOAP 用 PHP 开发 Web 服务,并且找到了返回数组的方法。 但是我试图做的是返回一个包含数组的数组。 我试图返回的数组示例:

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

实际上,当我返回此数组时,出现“无法序列化结果”错误。 我肯定知道这是因为它不理解 firstName 中的数组。

我的代码实际上是什么样的:

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

这就是我的 wsdl 相关部分的样子:

<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>

我也想要它看起来像:

<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>

我不得不解决。 这个 :

    $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(
       'test', // the type's name
       'complexType',
       'struct',
       'all',
        '',
        array(
               'firstName1' => array('name'=>'firstName1','type'=>'xsd:string'),
               'firstName2' => array('name'=>'firstName2','type'=>'xsd:string')
        )
    );

我的响应中的数组必须以相同的方式格式化。 这不完全是我想要的,但它按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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