开发者

Read long value from webservice using SoapClient

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开发者_StackOverflow, keeping it in a string.

Does anyone know how to solve this problem?


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";
?>


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;
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜