php和Web服务

php和Web服务,php,web-services,Php,Web Services,我有一个wsdl文件,我试图从php类调用它。我正在使用以下代码: <?php function getCountries() { $connection = new dbconn(); $sql = "SELECT * FROM tblcountries"; $dataset = $connection -> connectSql($sql); return $dataset; } function getTest() { $con

我有一个wsdl文件,我试图从php类调用它。我正在使用以下代码:

<?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();
} ?>

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_集(“soap.wsdl_缓存已启用”,“0”)的问题

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();
错误是:

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();
解析错误:语法错误,意外的T_字符串,在第47行的C:\Program Files\xamplite\htdocs\dataobjects\dataClass.php中需要T_函数

如果让解析器认为“0”是字符串,而不是数字,请删除引号

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();
编辑1如果不起作用,您的错误必须在该行之前,请发布完整代码以供审阅

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();
编辑2您提供的代码在类内运行,您缺少ini_set行前的括号。

如果让解析器认为“0”是字符串,而不是数字,请删除引号

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();
编辑1如果不起作用,您的错误必须在该行之前,请发布完整代码以供审阅

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();

Edit 2您提供的代码在类内部运行,您在ini_set行前面缺少一个括号。

我相信这是因为您在类的主体中有ini_set()调用。将它放在文件的顶部或构造函数中(如果有)

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();
class dataClass
{
    function registerCustomer()
    {
       // some stuff
    }

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

现在我明白了。您可能希望在第47行之前使用结束backet关闭该类。

我认为这是因为在类的主体中有ini_set()调用。将它放在文件的顶部或构造函数中(如果有)

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();
class dataClass
{
    function registerCustomer()
    {
       // some stuff
    }

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

现在我明白了。您可能希望在第47行之前使用结束backet关闭该类。

将最后一个}移动到ini_集(…)

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();
顺便说一下,您说过要调用web服务,但您正在创建一个可能被其他人调用的服务器

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();
要调用web服务,请尝试以下操作:

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();
try{
    $client = new SoapClient($service, array('location' =>"http://example.org/myWebService"));
    $parameter1 = new myWebServiceParameter();
    $result = $client->myWebServiceFunction($parameter1);
} catch (Exception $e) {
    // handle errors
}
myWebServiceParameter必须是具有相同名称的每个WSDL消息属性的成员变量的任何类。
myWebServiceFunction是web服务方法的名称。

将最后一个}移动到ini_集合(…)

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();
顺便说一下,您说过要调用web服务,但您正在创建一个可能被其他人调用的服务器

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();
要调用web服务,请尝试以下操作:

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();
try{
    $client = new SoapClient($service, array('location' =>"http://example.org/myWebService"));
    $parameter1 = new myWebServiceParameter();
    $result = $client->myWebServiceFunction($parameter1);
} catch (Exception $e) {
    // handle errors
}
myWebServiceParameter必须是具有相同名称的每个WSDL消息属性的成员变量的任何类。
myWebServiceFunction是web服务方法的名称。

您可以发布dataClass.php吗?您的源代码看起来不错。那么第47行上和周围有什么?因为这个ini_集合现在肯定给出了那个错误,所以它一定是在它之前。是的,请看一下第47行。事实上,这应该被重新标记为“第47行”。第47行:是ini_集(…在ini_集之前(…还有注册和获取国家/地区等功能。如果连接到网页消除了Web服务,它们工作正常。还尝试删除0“”但是仍然有同样的问题,你能在第47行之前发布几行吗?点击“编辑”。代码缩进4个空格。你能发布dataClass.php吗?你的源代码看起来不错。那么第47行上和周围有什么?因为这个ini_集现在肯定给出了那个错误,它一定是在它之前。是的,请看一下第47行。事实上,这应该被重新标记为“第47行”。第47行:ini_集吗(…在ini_集合之前(…还有注册和获取国家/地区等功能。如果连接到网页,则它们可以正常工作,从而消除Web服务。还尝试删除“”之间的0,但仍然存在相同的问题。是否可以发布第47行之前的几行?点击“编辑”。代码缩进4个空格。
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();