Hello everybody,
I have a small module must be convert from PHP-core to Yii Controller.
First is simple Webservice using NuSOAP:
<?php
include "nusoap.php";
$server = new soap_server();
$server->configureWSDL('MOReceiver');
$server->xml_encoding = "utf-8";
$server->soap_defencoding = "utf-8";
$namespace = "http://canhsong.com/MO/";
$server->wsdl->schemaTargetNamespace = $namespace;
/**
* 0: success receive
* 1: unsuccess receive
* 2: wrong user
* 3: wrong password
*/
function MOReceiver($User_ID, $Service_ID, $Command_Code, $Message, $Request_ID, $username, $password)
{
if ($username == 'canhsong') { // Check User
if ($password == '123qwe') { // Check Password
// Do something here when access successful
return 0;
}
else
return 3;
}
else
return 2;
}
$server->register("MOReceiver",
array('User_ID' => 'xsd:string',
'Service_ID' => 'xds:string',
'Command_Code' => 'xds:string',
'Message' => 'xds:string',
'Request_ID' => 'xds:string',
'username' => 'xds:string',
'password' => 'xds:string'),
array('result' => 'xsd:string'),
$namespace,
false,
'rpc',
'literal',
false);
$query = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : '';
$server->service($query);
and the test code is:
<?php
echo "Create SOAP Client<br>";
$svTest = new SoapClient("http://canhsong.com/MO/index.php?wsdl");
echo "Call SOAP Function<br>";
$result = $svTest->MOReceiver("mrdan32","8385","DD","DD TEST","1","canhsong","123qwe");
echo "Print Return Function<br>";
print_r($svTest->__getFunctions());
echo "Print Result<br>";
print_r($result);
?>
the result is
Now I want to convert this code into Yii Action, I did that:
- Create an actionSoap in SiteController: call by http://canhsong.com/yii/site/soap.php
function MOReceiver($User_ID, $Service_ID, $Command_Code, $Message, $Request_ID, $username, $password)
{
if ($username == 'canhsong') { // Check User
if ($password == '123qwe') { // Check Password
// Do something here when access successful
return 0;
}
else
return 3;
}
else
return 2;
}
public function actionSoap()
{
//$this->render('index');
include "soap/nusoap.php";// Included right file
$server = new soap_server();
$server->configureWSDL('MOReceiver');
$server->xml_encoding = "utf-8";
$server->soap_defencoding = "utf-8";
$namespace = "http://canhsong.com/yii/site/soap.php";
$server->wsdl->schemaTargetNamespace = $namespace;
$server->register("MOReceiver",
array('User_ID' => 'xsd:string',
'Service_ID' => 'xds:string',
'Command_Code' => 'xds:string',
'Message' => 'xds:string',
'Request_ID' => 'xds:string',
'username' => 'xds:string',
'password' => 'xds:string'),
array('result' => 'xsd:string'),
$namespace,
false,
'rpc',
'literal',
false);
$query = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : '';
$server->service($query);
}
But it couldn’t call the function MOReceiver, if you run the test (edit link) only stop on:
So I know that the actionSoap couldn’t add the function MOReceiver on $server->register(“MOReceiver”,
Anybody could help me? Or if you use the Default Yii Webservice, let me know how to make a Webservice like the Service above:
http://canhsong.com/MO/index.php
The XML site is: http://canhsong.com/MO/index.php?wsdl