2009-11-04 29 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