NuSoap返回complexType数组不正确?

时间:2012-11-23 12:24:38

标签: php web-services wsdl nusoap complextype

我有一个带NuSoap的Webservice WSDL。我在CodeIgniter中使用它。我有contexttype-array返回的问题。这是我的PHP代码:

$this->nusoap_server->wsdl->addComplexType(
                    "getJobStatusByIdsResponse",
                    "complexType",
                    "array",
                    "all",
                    "SOAP-ENC:Array",
                    array(),
                    array(
                        'Job' => array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:jobStatusResponse[]', 'minOccurs'=>'1', 'maxOccurs'=>'unbounded')
                    ),
                    'tns:jobStatusResponse'
                );


$this->nusoap_server->wsdl->addComplexType(
                    "getJobStatusByIdsResponse",
                    "complexType",
                    "array",
                    "all",
                    "SOAP-ENC:Array",
                    array(),
                    array(
                        'Job' => array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:jobStatusResponse[]', 'minOccurs'=>'1', 'maxOccurs'=>'unbounded')
                    ),
                    'tns:jobStatusResponse'
                );

$this->nusoap_server->register(
                    "getJobStatusByIds",
                    array('getJobStatusByIdsRequest' => 'tns:getJobStatusByIdsRequest'),
                    array('getJobStatusByIdsResponse' => 'tns:getJobStatusByIdsResponse'),
                    false,
                    false,
                    "rpc",
                    "literal",
                    "get JobStatus By Ids"
);

function getJobStatusByIds($data) {
  return array(array('orderId' => '1000', 'jobStatus' => '5'),array('orderId' => '1001', 'jobStatus' => '3'),array('orderId' => '1002', 'jobStatus' => '7'))
}

我将此作为回报:

      <ns1:getJobStatusByIdsResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
         <getJobStatusByIdsResponse>
            <item>
               <orderId>1001</orderId>
               <jobStatus>5</jobStatus>
            </item>
            <item>
               <orderId>1002</orderId>
               <jobStatus>3</jobStatus>
            </item>
            <item>
               <orderId>1003</orderId>
               <jobStatus>7</jobStatus>
            </item>
         </getJobStatusByIdsResponse>
      </ns1:getJobStatusByIdsResponse>

那不对,不是吗?

我怎样才能得到这样的结果(“工作”代替“项目”):

  <ns1:getJobStatusByIdsResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
     <getJobStatusByIdsResponse>
        <Job>
           <orderId>1001</orderId>
           <jobStatus>5</jobStatus>
        </Job>
        <Job>
           <orderId>1002</orderId>
           <jobStatus>3</jobStatus>
        </Job>
        <Job>
           <orderId>1003</orderId>
           <jobStatus>7</jobStatus>
        </Job>
     </getJobStatusByIdsResponse>
  </ns1:getJobStatusByIdsResponse>

我可以帮忙吗? 我在哪里可以找到更多NuSoap的例子?

1 个答案:

答案 0 :(得分:0)

希望这有帮助。

添加了代码注释,以帮助那些无法记住NuSoap params的人。

$this->nusoap_server->register(
                    "getJobStatusByIds",                                                           // method name
                    array('getJobStatusByIdsRequest' => 'tns:getJobStatusByIdsRequest'),           // input params
                    array('getJobStatusByIdsResponse' => 'tns:getJobStatusByIdsResponse'),         // output params
                    false,                                                                         // namespace
                    false,                                                                         // soap action
                    "rpc",                                                                         // style
                    "literal",                                                                     // use
                    "get JobStatus By Ids"                                                         // documentation
);

我认为定义的反应看起来应该是这样的。

// Job Status Result Complex Type (output)
$this->nusoap_server->wsdl->addComplexType(
                        "getJobStatusByIdsResponse",
                        "complexType",
                        "struct",
                        "all",
                        "SOAP-ENC:Array",
                        array('Job' => array('orderId' => 'your value here', jobStatus => 'your value here')),
    );