最近遇到要使用PHP訪問WebService。問了一下PHP程序員,用過的人少。本身配置。 在XP上配置不成功,在Win2003上安裝一個5.2,安裝時記得選擇支持Soap。安裝完後把IIS裏解釋PHP的DLL路徑改正確。 把PHP.ini文件拷貝到Windows目錄下,把Soap的Dll文件php_soap.dll拷貝到System32目錄下。重啓IIS。新建一個PHP文件。 1/* soap.php */ 2/* 鏈接的是C#實現的Webservice */ 3$client = new SoapClient( [url]http://xx.xxx.xx.com/service.asmx?wsdl [/url]); 4$client->YourFunctionName( 5array( 6 "Parameter1"=>"Value1", 7 "Parameter2"=>"Value2") ); 8print $client->YourFunctionNameResult; 9 這樣就獲得結果了。 SoapClient語法詳見php.net。用它也能夠創建PHP的WebService。 <?php require_once(''nusoap.php'');//調用一個開源的類 下載download $client = new soapclient(''http://www.webservicex.net/globalweather.asmx?WSDL'', true); $err = $client->getError(); if ($err) { echo ''<h2>Constructor error</h2><pre>'' . $err . ''</pre>''; } // Doc/lit parameters get wrapped $param = array(''CityName'' => ''dalian'',''CountryName'' => ''china''); $result = $client->call(''GetWeather'', array(''parameters'' => $param), '''', '''', false, true,''document'',''encoded''); // Check for a fault if ($client->fault) { echo ''<h2>Fault</h2><pre>''; print_r($result); echo ''</pre>''; } else { // Check for errors $err = $client->getError(); if ($err) { // Display the error echo ''<h2>Error</h2><pre>'' . $err . ''</pre>''; } else { // Display the result echo ''<h2>Result</h2><pre>''; print_r($result); echo ''</pre>''; } } echo ''<h2>Request</h2><pre>'' . htmlspecialchars($client->request, ENT_QUOTES) . ''</pre>''; echo ''<h2>Response</h2><pre>'' . htmlspecialchars($client->response, ENT_QUOTES) . ''</pre>''; echo ''<h2>Debug</h2><pre>'' . htmlspecialchars($client->debug_str, ENT_QUOTES) . ''</pre>''; ?>