【发布时间】:2011-05-25 20:28:07
【问题描述】:
我有一个 WCF 操作 GetColors,它返回一个颜色列表作为 GetColorsResult。我得到的结果很好,但是如何在 php 中循环 GetColorsResult 并回显每个元素?
我在做:
<?php
header('Content-Type: text/plain');
echo "WCF Test\r\n\r\n";
// Create a new soap client based on the service's metadata (WSDL)
$client = new SoapClient('http://localhost:8181/Colors.svc?wsdl',array(
'login' => "test", 'password' => "test"));
$retval = $client->GetColors();
//Need to loop throuh $retval here
echo $retval->GetColorsResult; //This throws error.
?>
有没有办法控制结果的名称,例如我没有指定WCF返回GetColorsResult,它在我的方法调用中附加了Result。同样,它将响应附加到 GetColors 以获取响应 (GetColorsResponse)
执行 print_r($retval) 时的输出:
stdClass Object
(
[GetColorsResult] => stdClass Object
(
[Color] => Array
(
[0] => stdClass Object
(
[Code] => 1972
[Name] => RED
)
[1] => stdClass Object
(
[Code] => 2003
[Name] => BLUE
)
[2] => stdClass Object
(
[Code] => 2177
[Name] => GREEN
)
)
)
)
【问题讨论】:
-
你可能想要添加一些你已经拥有的代码......(顺便说一下没有投票)
-
我很乐意添加代码。不知道为什么投反对票,我对php不熟悉。
-
你可以试试 print_r($retval) 并发布输出吗?
-
@TerrenceJackson,我更新了我的帖子以显示 print_r($retval) 结果