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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里