我有一个WCF操作GetColors,它返回一个颜色列表GetColorsResult。我得到的结果很好,但我如何通过GetColorsResult在PHP中循环并回显每个元素?从php中的wcf服务回应XML结果?
我做:
<?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,它附加结果我的方法调用。
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
)
)
)
)
你可能想要添加一些你已经有的代码...(没有downvote的方式) – Mr47 2011-05-25 20:29:53
我会很高兴添加代码。不知道为什么downvote,我不熟悉php。 – Xaisoft 2011-05-25 20:30:37
你可以尝试print_r($ retval)并发布输出吗? – TerenceJackson 2011-05-25 20:34:50