Php 在nusoap中返回数组的数组

Php 在nusoap中返回数组的数组,php,web-services,soap,nusoap,soapserver,Php,Web Services,Soap,Nusoap,Soapserver,我正在用PHP和NUSOAP开发一个web服务,我找到了返回数组的方法。 但我要做的是返回一个数组,数组在其中。 我尝试返回的数组示例: $return = array( 'lastName' => "Dupond", 'firstName' => array("Bryan", "Michael"), 'nationality' => "NA", 'gender' => "M" ); 实际上,当我返回这个数组时,我得到了“无法序列化结果

我正在用PHP和NUSOAP开发一个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);
<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>
我的wsdl的相关部分是这样的:

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

我想要的也是这样的:

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);
<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',//类型的名称
“complexType”,
“struct”,
“全部”,
'',
排列(
数组('name'=>'firtsname1','type'=>'xsd:string'),
数组('name'=>'firstname2','type'=>'xsd:string')
));
必须是这样的:(添加了与标记同名的索引)

$server->wsdl->addComplexType(
'test',//类型的名称
“complexType”,
“struct”,
“全部”,
'',
排列(
'firstName1'=>array('name'=>'firstName1','type'=>'xsd:string'),
'firstName2'=>array('name'=>'firstName2','type'=>'xsd:string')
)
);
我的响应中的数组必须以相同的方式格式化。
这不完全是我想要的,但它按预期工作。

Bryan和Michael不是第一个代码示例中的字符串。这正常吗?当我复制我的代码时失败,他们实际上在我的代码中被钉住了,只是忘记了堆栈上的引号。