Read long value from webservice using SoapClient

二次信任 提交于 2020-01-05 07:37:11

问题


I'm writing a soap consumer in PHP for a ws written in Java (Jax ws). The webservice exports a function listRooms() that returns an array of the complex data type Room which contains an id (64 bit long) and a description (string). Now whenever I consume the webservice using SoapClient, the id is converted to float (as there are no 64 bit integers in PHP) and I want to avoid it. As I will need the room id to consume other web services I would rather avoid this implicit conversion to float, keeping it in a string.

Does anyone know how to solve this problem?


回答1:


This might help:

The long overflows because ext/soap maps it to an int, and you're on a 32bit arch. You can easily fix that problem by using a custom type mapper to override the internal handling of {http://www.w3.org/2001/XMLSchema }long:

function to_long_xml($longVal) {
  return '<long>' . $longVal . '</long>';
}
function from_long_xml($xmlFragmentString) {
  return (string)strip_tags($xmlFragmentString);
}
$client = new SoapClient('http://acme.com/products.wsdl', array(
  'typemap' => array(
    array(
      'type_ns' => 'http://www.w3.org/2001/XMLSchema',
      'type_name' => 'long',
      'to_xml' => 'to_long_xml',
      'from_xml' => 'from_long_xml',
    ),
  ),
));

Also check to see exactly what you get back from the SOAP call, as per the manual add 'trace' and use getLastRequest:

<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
?>



回答2:


Other way to do it, is just using the float() function before the data to sent as a long type.

In the example below I'm use a stdclass object to sent as a parameter:

<?php
if ($index == "Your_longtype_Field"){
    $a->$index = (float) $value;
} else {
    $a->$index = $value;
}
?>


来源:https://stackoverflow.com/questions/6150715/read-long-value-from-webservice-using-soapclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!