2009-11-04 47 views
1

我有一個wsdl文件,我試圖從一個php類調用它。我正在使用以下代碼:php和webservices

<?php 

include(「dbconn.php」);

類數據類 {

function getCountries() 
{ 
    $connection = new dbconn(); 

    $sql = "SELECT * FROM tblcountries"; 

    $dataset = $connection -> connectSql($sql); 

    return $dataset; 
} 

function getTest() 
{ 
    $connection = new dbconn(); 

    $sql = mysql_query('CALL sp_getTest'); 

    $dataset = $connection -> connectSql($sql); 

    return $dataset; 
} 


##-------------------------------------------CUSTOMER METHODS------------------------------------------- 
function registerCustomer($username,$name,$surname,$password,$email,$country,$tel) 
{ 
    $connection = new dbconn(); 

    $sql="INSERT INTO tblcustomer (customer_username, customer_password, customer_name, customer_surname, 
     customer_email, customer_country, customer_tel) 
     VALUES('$username','$name','$surname','$password','$email','$country','$tel')"; 

    $dataset = $connection -> connectSql($sql); 

} 



ini_set("soap.wsdl_cache_enabled", "0"); 
// start the SOAP server - point to the wsdl file 
$webservice = new SoapServer("http://localhost/dataobjects/myWebservice.wsdl", array('soap_version' => SOAP_1_2)); 

// publish methods 
$webservice->addFunction("getCountries"); 
$webservice->addFunction("registerCustomer"); 
// publish 
$webservice->handle(); 

} >

它所有的時間給我ini_set("soap.wsdl_cache_enabled", "0");

該錯誤的問題是:

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\Program Files\xampplite\htdocs\dataobjects\dataClass.php on line 47

+1

你可以發表dataClass.php嗎?您的源代碼看起來沒問題。 – opHASnoNAME 2009-11-04 13:44:10

+0

那麼你在第47行和第47行有什麼?因爲這個ini_set現在肯定會給出這個錯誤,所以它一定是前面的東西。 – 2009-11-04 13:44:18

+0

是的,請看看第47行。實際上,這應該被重新標記爲「第47行」。 – Frankie 2009-11-04 13:45:52

回答

1

我相信這是因爲你有ini_set()調用你的類的主體。把它放在文件的頂部或者在構造函數中(如果有的話)。

class dataClass 
{ 
    function registerCustomer() 
    { 
     // some stuff 
    } 

    ini_set(/*args*/); // it's illegal to put instructions in the body of the class 
} 

現在我看到了整個事情。你可能想與關閉鬥提關閉類線前47

+0

謝謝,這是我的問題 – IanCian 2009-11-04 14:09:27

0

你讓解析器認爲「0」是一個字符串,而不是數字,請刪除引號!

編輯1如果這樣做不行,您的錯誤必須在該行之前,請發佈完整的代碼進行審查。

編輯2您提供的代碼在類中運行,您會錯過ini_set之前的括號。

0

移動最後}中的ini_set(...)

前順便說一句,你說你要調用Web服務,但你正在創建一個可能被其他人調用的服務器。

通話 web服務,嘗試這樣的事情:

try{ 
    $client = new SoapClient($service, array('location' =>"http://example.org/myWebService")); 
    $parameter1 = new myWebServiceParameter(); 
    $result = $client->myWebServiceFunction($parameter1); 
} catch (Exception $e) { 
    // handle errors 
} 

myWebServiceParameter必須具有相同名稱的成員變量的foreach WSDL消息屬性的任何類。 而myWebServiceFunction是Web服務方法的名稱。

+0

非常感謝,這是我的問題:) – IanCian 2009-11-04 14:08:56