php - 如何处理 NuSoap 中的数组 ComplexType?

标签 php web-services nusoap complextype

目前我使用的是 PHP 版本 5.4.16 和 NuSoap 0.95,我试过这个例子: here

它显示了这样的服务器代码;

$server->wsdl->addComplexType(
    'Chapter',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'title' => array('name'=>'title','type'=>'xsd:string'),
        'page' => array('name'=>'page','type'=>'xsd:int')
    )
);

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

$server->wsdl->addComplexType(
    'Book',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'author' => array('name'=>'author','type'=>'xsd:string'),
        'title' => array('name'=>'title','type'=>'xsd:string'),
        'numpages' => array('name'=>'numpages','type'=>'xsd:int'),
        'toc' => array('name'=>'toc','type'=>'tns:ChapterArray')
    )
);

$server->register(
    'getBook',
    array('title'=>'xsd:string'),
    array('return'=>'tns:Book'),
    $NAMESPACE);

function getBook($title) {
     // Create TOC
     $toc = array();
     $toc[] = array('title' => 'Chapter One', 'page' => 1);
     $toc[] = array('title' => 'Chapter Two', 'page' => 30);

     // Create book
     $book = array(
                 'author' => "Jack London",
                 'title' => $title,
                 'numpages' => 42,
                 'toc' => $toc);

     return $book;
}

但在 SOAP 响应中返回错误,我正在使用 SopUI 对其进行测试。我收到这样的错误:

<br />
<b>Notice</b>:  Array to string conversion in <b>E:\xampp\htdocs\myweb\lib\nusoap.php</b> on line <b>6132</b><br />
<br />
<b>Notice</b>:  Array to string conversion in <b>E:\xampp\htdocs\myweb\lib\nusoap.php</b> on line <b>6132</b><br />
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getBookResponse xmlns:ns1="http://localhost/myweb"><return><author>Jack London</author><title>This is my book</title><numpages>42</numpages><toc><item><title>Chapter One</title><page>1</page></item><item><title>Chapter Two</title><page>30</page></item></toc></return></ns1:getBookResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

我该如何解决这个错误?有人可以帮我解决这个错误吗...非常感谢...

最佳答案

nusoap > lib > nusoap.php 中,注释行 6132:

////$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");

关于php - 如何处理 NuSoap 中的数组 ComplexType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18779953/

相关文章:

javascript - jQuery Ajax 登录中没有 'Access-Control-Allow-Origin' header

php - 对如何从返回一组特定值的查询中获取另一行感到困惑

php - 更改 Paypal 定期付款帐户每月支付的金额

PHP NuSoap 发送 header 的正确方法

php - 使用 PHP 和 NuSOAP 通过 HTTPS 发出 SOAP 请求

javascript - 类别与 Codeigniter 中带有复选框的每个类别的兼容性

javascript - 页面刷新后 Web 应用程序在 Windows Phone 上中断

从 web 服务获取数据的 PHP 函数

javascript - 同一个本地主机端口上的 Web 服务和 Javascript 请求

php - SOAP 消息的最大大小是如何确定的?