为什么SOAP服务器不返回在函数服务器

时间:2018-01-26 01:20:48

标签: php soap soap-client soapserver

我在SOAP服务器上有一个函数,它返回一个二维数组

example(返回一个关联数组的函数,其中一个字段是二维数组):

function example_function($id_array){

    $res = array("errors" => false, "message" => "ok message", "2_array" => array(array("asd" => 1, "sdf" => 2), array("asd" => 3, "sdf" => 5)));

    echo "<pre>";
    var_dump($res);
    echo "</pre>";

    return $res;

}

如果你直接运行这个功能,转到服务器,我们得到一个结构合理的答案,我需要

array(3) {
  ["errors"]=>
  bool(false)
  ["message"]=>
  string(10) "ok message"
  ["2_array"]=>
  array(2) {
    [0]=>
    array(2) {
      ["asd"]=>
      int(1)
      ["sdf"]=>
      int(2)
    }
    [1]=>
    array(2) {
      ["asd"]=>
      int(3)
      ["sdf"]=>
      int(5)
    }
  }
}

但是,如果我们从SoapClient运行此函数,我们得到以下输出:

$opts = array(
     'http' => array(
         'user_agent' => 'PHPSoapClient'
     )
);
$context = stream_context_create($opts);
$soapClientOptions = array(
    'stream_context' => $context,
    'cache_wsdl' => WSDL_CACHE_NONE,
    'soap_version' => SOAP_1_2,
);
$client = new SoapClient("http://some_address/wsdl.wsdl", $soapClientOptions);
$result = $client->example_function();

var_dump($result);

返回:

object(stdClass)#195 (3) {
  ["errors"]=>
  bool(false)
  ["message"]=>
  string(23) "ok message"
  ["2_array"]=>
  object(stdClass)#196 (1) {  //I don't know why is stdClass
    ["Map"]=>
    array(2) {
      [0]=>
      object(stdClass)#202 (1) { //I dont't know why "item"
        ["item"]=>
        array(2) {
          [0]=>
          object(stdClass)#203 (2) {
            ["key"]=>
            string(3) "asd"
            ["value"]=>
            string(1) "1"
          }
          [1]=>
          object(stdClass)#204 (2) {
            ["key"]=>
            string(3) "sdf"
            ["value"]=>
            string(1) "2"
          }
        }
      }
      [1]=>
      object(stdClass)#205 (1) {
        ["item"]=>
        array(2) {
          //similarly
        }
      }
    }
  }
}

可能是什么错误?

0 个答案:

没有答案