使用SoapClient从Web服务读取长值 [英] Read long value from webservice using SoapClient
问题描述
我正在用PHP编写肥皂使用者,以用Java(Jax ws)编写ws.该Web服务导出一个函数 listRooms(),该函数返回一个复杂数据类型 Room 的数组,该数组包含一个id(64位长)和一个描述(字符串).现在,每当我使用SoapClient使用Web服务时,id都会转换为float(因为PHP中没有64位整数),我想避免使用它.因为我需要房间ID来使用其他Web服务,所以我宁愿避免将此隐式转换转换为float并将其保存在字符串中.
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?
推荐答案
长时间溢出是因为ext/soap将其映射到一个int,并且您位于32位拱门上.您可以使用自定义类型映射器覆盖{http://www.w3.org/2001/XMLSchema} long的内部处理,轻松解决该问题:
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',
),
),
));
还请按照手册添加'trace'并检查一下您从SOAP调用中得到的结果.使用getLastRequest :
<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
?>
这篇关于使用SoapClient从Web服务读取长值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!