当我运行以下脚本时,我得到一个" 类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);
答案 0 :(得分:1)
首先 - 此服务使用 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 service specification中所述,您可以发现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
的{{1}}参数。现在我们可以推断出您的代码应该是这样的:
zipCodeList
请注意,我抓住$args = array("zipCodeList"=>'10001');
try {
$z = $client->LatLonListZipCode($args);
} catch (SoapFault $e) {
echo $e->faultcode;
}
例外。它将帮助您了解服务器端错误。请在PHP documentation中了解详情。