php 怎么 使用soap,在php(如示例)中如何使用soap类?

最简单的做法是:

$requestParams = array(

'CityName' => 'Berlin',

'CountryName' => 'Germany'

);

$client = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');

$response = $client->GetWeather($requestParams);

print_r($response);

将输出

stdClass Object

(

[GetWeatherResult] => <?xml version="1.0" encoding="utf-16"?>

Berlin-Tegel, Germany (EDDT) 52-34N 013-19E 37M

Jan 26, 2012 - 07:50 AM EST / 2012.01.26 1250 UTC

from the SE (130 degrees) at 14 MPH (12 KT):0

greater than 7 mile(s):0

mostly clear

33 F (1 C)

Windchill: 23 F (-5 C):1

21 F (-6 C)

59%

30.27 in. Hg (1025 hPa)

Success

)

其余的可以用SimpleXML或类似的东西进行解析。

请注意,该类型的响应特定于此Web服务。在那里有更好的Web服务,它不仅仅是返回一个xml字符串,而是在WSDL中提供响应结构。

编辑“更结构化”的Web服务的示例可以是同一站点上的GeoIP查找:

$client = new SoapClient('http://www.webservicex.net/geoipservice.asmx?WSDL');

$result = $client->GetGeoIP(array('IPAddress' => '8.8.8.8'));

print_r($result);

这给你:

stdClass Object

(

[GetGeoIPResult] => stdClass Object

(

[ReturnCode] => 1

[IP] => 8.8.8.8

[ReturnCodeDetails] => Success

[CountryName] => United States

[CountryCode] => USA

)

)

现在您可以通过调用简单地访问这些值

$country = $result->GetGeoIPResult->CountryName;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值