【发布时间】:2012-04-02 06:40:37
【问题描述】:
我正在使用一种返回通用列表的方法从 .net Web 服务中获取结果。在 php 页面中使用 var_dump(使用 WSDL 调用 .net 方法),我能够看到从 .net Web 服务返回以下内容:
object(stdClass)#4 (1) {
["testClass"]=> array(2) {
[0]=> object(stdClass)#5 (2) {
["City"]=> string(7) "Hello_1"
["State"]=> string(8) "World!_1"
}
[1]=> object(stdClass)#6 (2) {
["City"]=> string(7) "Hello_2"
["State"]=> string(8) "World!_2"
}
}
}
这可能是一个愚蠢的问题,但我被困在 php 中处理(循环)这个结果?我还必须在 php 中创建类“testClass”吗?
这是 .net 网络服务代码
public class testClass
{
public string City;
public string State;
}
[WebMethod]
public List<testClass> testAspMethod(string Param1, string Param2)
{
List<testClass> l = new List<testClass>();
l.Add(new testClass { City = Param1 + "_1", State = Param2 + "_1" });
l.Add(new testClass { City = Param1 + "_2", State = Param2 + "_2" });
return l;
}
这是调用这个 .net 网络服务的 php 代码
$client = new SoapClient("http://testURL/MyTestService.asmx?WSDL");
$params->Param1 = 'Hello';
$params->Param2 = 'World!';
$result = $client->testAspMethod($params)->testAspMethodResult;
var_dump($result);
如何在 php 中循环遍历结果?
【问题讨论】:
标签: php asp.net web-services wsdl