[英]Zend Framework - Does Zend_Soap_Client supports SwA (Soap With Attachments)?
[英]SOAP client with Zend framework 2
我正在嘗試在Zend框架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->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>
因此,您需要構建一個對象或一個關聯數組以供Web服務使用。 對於對象變量,可以使用stdClass。 如果要像這樣修改函數調用:
$params = new \stdClass();
$params->CountryName = 'Australia';
$result = $client->GetCurrencyByCountry($params);
您的請求適合該類型,數據將發送到服務器。 在提供的WDSL中,您必須處理甚至更復雜的變體:
<wsdl:message name="GetISOCountryCodeByCountyNameSoapOut">
<wsdl:part name="parameters" element="tns:GetISOCountryCodeByCountyNameResponse"/>
</wsdl:message>
需要這樣的設置:
$params = new \stdClass();
$params->parameters = new \stdClass();
$params->parameters->GetISOCountryCodeByCountyNameResult = 'YOURVALUE';
或作為數組:
$params = array('parameters'=>
array('GetISOCountryCodeByCountyNameResult'=>'VALUE')
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.