当我运行以下脚本时,我在行上收到“无法将stdClass类的对象转换为SOAP请求的字符串”错误,$client->LatLonListZipCode($args)
并且我不知道为什么。有任何想法吗?
<?php
$contextOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
),
'http' => array(
'timeout' => 5 //seconds
)
);
//create stream context
$stream_context = stream_context_create($contextOptions);
//create client instance (over HTTPS)
$client = new SoapClient('http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl', array(
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => 1,
'trace' => 1,
'stream_context' => $stream_context,
'soap_version'=> SOAP_1_2,
'connection_timeout' => 5 //seconds
));//SoapClient
$args = new stdClass();
$args->zipCodeList = '10001';
$z = $client->LatLonListZipCode($args);
首先,此服务使用的是SOAP 1.1, 而不是 SOAP 1.2。将您的$client
规范更改为:
$client = new SoapClient('http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl', array(
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => 1,
'trace' => 1,
'stream_context' => $stream_context,
'soap_version'=> SOAP_1_1,//<-- note change here
'connection_timeout' => 5 //seconds
));//SoapClient
如WSDL服务规范中所述,您可以发现该LatLonListZipCode
函数定义为:
<operation name="LatLonListZipCode">
<documentation>Returns a list of latitude and longitude pairs with each pair corresponding to an input zip code.</documentation>
<input message="tns:LatLonListZipCodeRequest"/>
<output message="tns:LatLonListZipCodeResponse"/>
</operation>
和预期参数定义为:
<xsd:simpleType name="zipCodeListType">
<xsd:restriction base='xsd:string'>
<xsd:pattern value="\d{5}(\-\d{4})?( \d{5}(\-\d{4})?)*" />
</xsd:restriction>
</xsd:simpleType>
因此我们知道,服务器仅需要一个string
名为的参数zipCodeList
。现在我们可以推断出您的代码应如下所示:
$args = array("zipCodeList"=>'10001');
try {
$z = $client->LatLonListZipCode($args);
} catch (SoapFault $e) {
echo $e->faultcode;
}
请注意,我正在捕获SoapFault
异常。它将帮助您了解服务器端错误。在PHP文档中阅读有关它的更多信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句