PHP - SoapClient和typemap以防止元素消失

时间:2015-11-10 09:51:50

标签: php xml parsing soap

我试图了解当SoapClient解析Soap响应时发生了什么。当我致电$client->__getLastResponse()时,我得到了这个:

<ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/">
  <ns0:Body>
    <ns1:ListPositionBranchResponse xmlns:ns1="http://atollon.com/enterprise/wsdl">
      <result>OK</result>
      <time>0.00505090</time>
      <ROWS>
        <ROW>
          <idPos>1409000</idPos>
          <idBranch>122482000</idBranch>
          <positionName>ekonom</positionName>
        </ROW>
        <ROW>
          <idPos>1412000</idPos>
          <idBranch>122488000</idBranch>
          <positionName>IT specialista</positionName>
        </ROW>
      </ROWS>
    </ns1:ListPositionBranchResponse>
  </ns0:Body>
</ns0:Envelope>

我以这种方式创建SoapClient:

    $client = new SoapClient("https://mblue.atollon.com/recruitment.wsdl", array('trace' => 1, 'exceptions'=>true, 'location' => "https://mblue.atollon.com/soap"));
$requestParams = array(
      'server' => "SERVER",
      'session' => "SESSION"
  );
  $response = $client->ListPositionBranch($requestParams);

但是当我做响应的var_dump时,没有idPos元素。我在64位Linux机器上试过它,但它也不起作用,所以它不是INT限制。所以我想看看发生了什么,并尝试了这个:

  $client = new SoapClient("https://mblue.atollon.com/recruitment.wsdl", array('trace' => 1, 'exceptions'=>true, 'location' => "https://mblue.atollon.com/soap", 'typemap' => array(
          array(
            'type_ns' => 'http://atollon.com/enterprise/wsdl',
            'type_name' => 'idPos',
            'to_xml' => 'to_long_xml',
            'from_xml' => 'from_long_xml',
          )
      )));

功能本身:

  function to_long_xml($longVal) {
    return '<long>' . $longVal . '</long>';
  }
  function from_long_xml($xmlFragmentString) {
    return (string)strip_tags($xmlFragmentString);
  }

from_long_xml函数甚至没有被解雇..我试图将type_name更改为我猜测该响应中的所有元素,但它永远不会触发它。我没有想法 - 可能是错的 - 我猜它可能是命名空间,但我已经尝试了两个列出的xml没有运气。如何让typemap(或idPos)工作? 感谢。

1 个答案:

答案 0 :(得分:0)

type_name元素中的

typemap应该是WSDL服务中定义的类型名称。我有奇怪的经历,typemap应该在classmap元素之前定义。