PHP Soap传递对象数组

时间:2015-03-18 11:51:00

标签: php arrays soap wsdl

我的方法:

/**
 * @param \LeosEbayGateway\Soap\Model\Apigw\SkuQty $changeStocksBySkus[]
 */
public function change_stocks_by_skus(array $changeStocksBySkus)
{
    var_dump($changeStocksBySkus);
    die();
}

了SoapUI

输入:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ind="http://ebay/index.php">
   <soapenv:Header/>
   <soapenv:Body>
      <ind:change_stocks_by_skus>
         <changeStocksBySkus>
            <sku>1</sku>
            <qty>2</qty>
         </changeStocksBySkus>
         <changeStocksBySkus>
            <sku>3</sku>
            <qty>4</qty>
         </changeStocksBySkus>
      </ind:change_stocks_by_skus>
   </soapenv:Body>
</soapenv:Envelope>

输出是:

object(stdClass)#236 (2) {
  ["sku"]=>
  string(1) "1"
  ["qty"]=>
  string(1) "2"
}

我传递了数组值,但输出只有1个对象而不是数组,为什么?

操作:

public function wsdlAction(Request $request)
{
    $autodiscover = new \Zend\Soap\AutoDiscover();
    $autodiscover->setClass('\\LeosEbayGateway\\Soap\\Service\\SoapServerService');
    $autodiscover->setUri('http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']);

    return new Response($autodiscover->toXml(), 200, ['Content-Type' => 'application/xml']);
}

public function apiAction(Request $request)
{
    $options = array(
        'cache_wsdl'    => WSDL_CACHE_NONE,
        'uri'           => 'http://localhost:8000/api/wsdl',
    );

    $server = new \Zend\Soap\Server(null, $options);
    $server->setObject(new SoapServerService());
    $server->handle();
}

SoapServerService.php

<?

namespace test\Soap\Service;


class SoapServerService {

    /**
     * @var array
     */
    private $config;

    /**
     * @var Application
     */
    private $application;

    public function __construct()
    {

    }

    /**
     * @param \test\Soap\Model\Apigw\SkuQty $changeStocksBySkus[]
     */
    public function change_stocks_by_skus(array $changeStocksBySkus)
    {
        if(!is_array($changeStocksBySkus)) {
            throw $this->toSoapFault("changeStocksBySkus param is not array!");
        }

        try {
            return (new SoapServiceProducts())->ChangeStocksBySkus($changeStocksBySkus);
        } catch (Exception $e) {
            throw $this->toSoapFault($e->getMessage());
        }

    }
}

0 个答案:

没有答案