Php 具有Zend framework 2的SOAP客户端
我试图在Zend framework 2中创建一个SOAP客户机,我已经创建了下面正确返回数据的Php 具有Zend framework 2的SOAP客户端,php,soap,zend-framework2,soap-client,Php,Soap,Zend Framework2,Soap Client,我试图在Zend framework 2中创建一个SOAP客户机,我已经创建了下面正确返回数据的 try { $client = new Zend\Soap\Client("http://www.webservicex.net/country.asmx?WSDL"); $result = $client->GetCountries(); print_r($result); } catch (SoapFault $s) { die('ERROR: [' . $s-
try {
$client = new Zend\Soap\Client("http://www.webservicex.net/country.asmx?WSDL");
$result = $client->GetCountries();
print_r($result);
} catch (SoapFault $s) {
die('ERROR: [' . $s->faultcode . '] ' . $s->faultstring);
} catch (Exception $e) {
die('ERROR: ' . $e->getMessage());
}
但是,当我尝试向Web服务发送数据时,例如使用
try {
$client = new Zend\Soap\Client("http://www.webservicex.net/country.asmx?WSDL");
$result = $client->GetCurrencyByCountry('Australia');
print_r($result);
} catch (SoapFault $s) {
die('ERROR: [' . $s->faultcode . '] ' . $s->faultstring);
} catch (Exception $e) {
die('ERROR: ' . $e->getMessage());
}
我只是得到以下信息
ERROR: [soap:Receiver] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Procedure or function 'GetCurrencyByCountry' expects parameter '@name', which was not supplied. at WebServicex.country.GetCurrencyByCountry(String CountryName) --- End of inner exception stack trace ---
如何向Web服务提供参数?您的问题在于请求,WDSL定义了复杂类型:
<s:element name="GetCurrencyByCountryResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetCurrencyByCountryResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
您的请求符合类型,数据将发送到服务器。在提供的WDSL中,您必须处理更复杂的变体:
<wsdl:message name="GetISOCountryCodeByCountyNameSoapOut">
<wsdl:part name="parameters" element="tns:GetISOCountryCodeByCountyNameResponse"/>
</wsdl:message>
或作为数组:
$params = array('parameters'=>
array('GetISOCountryCodeByCountyNameResult'=>'VALUE')
);
您可以提供请求的示例XML吗?不确定如何在调用handle()后立即输出原始XML。您可以调用getLastRequest()和getLastResponse()方法。您可以将其写入文件。print\r($client->getLastRequest());不返回任何内容并打印($client->getLastResponse());返回相同的soap:receiver msgI不控制服务器端,我正在连接到第三方。对于我来说,此设置适用于方法“GetISOCountryCodeByCountyName”:$params=array('CountryName'=>'Australia')$结果=$client->GetISOCountryCodeByCountyName($params);
$params = new \stdClass();
$params->parameters = new \stdClass();
$params->parameters->GetISOCountryCodeByCountyNameResult = 'YOURVALUE';
$params = array('parameters'=>
array('GetISOCountryCodeByCountyNameResult'=>'VALUE')
);