PHP SOAP 将错误值返回给客户端
我正在尝试通过 SOAP 将值从我的 (MySQL) 数据库返回到 C# 客户端。
服务器是用 PHP 编写的,我认为这就是一切出错的地方:
class foo{
function bar()
{
$result = $connection->query("SELECT value
FROM table
WHERE id='$id'");
$row = $result->fetch_assoc();
return (int)$row['value'];
}
}
无论数据库中的值是什么,在 C# 中都会显示为 0。但是,
class foo{
function bar()
{
return 5;
}
}
在 C# 中显示为正确值(本例中为 5)。
我在这里缺少什么?似乎数据库中的数据不会正确返回到 C#,但在 PHP 中(静态)写入相同值的任何其他方法都会成功。
编辑: 我现在已经设置了一个 PHP SOAP 客户端,它接收与 C# 相同的值。因此,问题似乎出在 PHP SOAP 服务器上,向客户端传达了错误的值(只要返回的值不是静态的)。
编辑: 我现在已经找到了解决问题的方法;我的 WSDL 文件具有复杂的请求类型,尽管它只需要一个简单的类型。将此复杂类型更改为简单类型,解决了问题。不要问我为什么——这对我来说毫无意义!
I'm trying to return a value from my (MySQL) database to a C# client, through SOAP.
The server is written in PHP, which I think is where everything goes wrong:
class foo{
function bar()
{
$result = $connection->query("SELECT value
FROM table
WHERE id='$id'");
$row = $result->fetch_assoc();
return (int)$row['value'];
}
}
Will turn up as 0 in C#, no matter what value was in the database. However,
class foo{
function bar()
{
return 5;
}
}
turns up as the correct value (5 in this case) in C#.
What am I missing here? It seems that data from the database will not be returned to C# correctly, but any other ways of writing the same value (statically) in PHP, will succeed.
EDIT:
I've now set up a PHP SOAP-client, which receives the same values as C# does. So it seems that the problem is with the PHP SOAP-server, communicating the wrong values to the client (whenever the value to return is not static).
EDIT:
I have now found the solution to my problem; My WSDL file had a complex request type, even though it only required a simple type. Changing this complex type to a simple type, fixed the problem. Do not ask me why - it does not make the slightest sense to me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个关联数组。这可能会返回不止一项。
You are asking for an associative array. This may return more that one item.