我正在按照本教程扩展Sugarcrm webservice以定义我的自定义模块的新服务。 问题:但是,作为初步检查,我试图调用现有的登录服务,但这本身就失败了。请帮助指出问题所在。我被困住了。
如教程中所述,我在文件夹中创建了以下文件:custom / service / v4_1_custom
registry.php
<?php
require_once('service/v4_1/registry.php');
class registry_v4_1_custom extends registry_v4_1
{
protected function registerFunction()
{
parent::registerFunction();
$this->serviceClass->registerFunction('my_get_orders',
array(
'session' => 'xsd:string',
'module_name' => 'xsd:string',
'id' => 'xsd:string',
),
array(
'return' => 'xsd:string',
)
);
}
}
?>
soap.php
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
chdir('../../..');
require_once('SugarWebServiceImplv4_1_custom.php');
$webservice_class = 'SugarSoapService2';
$webservice_path = 'service/v2/SugarSoapService2.php';
$registry_class = 'registry_v4_1_custom';
$registry_path = 'custom/service/v4_1_custom/registry.php';
$webservice_impl_class = 'SugarWebServiceImplv4_1_custom';
$location = 'custom/service/v4_1_custom/soap.php';
require_once('service/core/webservice.php');
?>
SugarWebServiceImplv4_1_custom.php
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('service/v4_1/SugarWebServiceImplv4_1.php');
class SugarWebServiceImplv4_1_custom extends SugarWebServiceImplv4_1
{
/*
* Returns the id if authenticated
*
* @param id
* @return string $session - false if invalid.
*
*/
function my_get_orders($session, $module_name, $id)
{
$GLOBALS['log']->info('Begin: SugarWebServiceImplv4_1_custom->my_get_orders');
$error = new SoapError();
//authenticate
if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error))
{
$GLOBALS['log']->info('End: SugarWebServiceImplv4_1_custom->my_get_orders.');
return false;
}
return $id;
}
}
?>
我的webservice客户端用于测试webservice:SoapTest.php
SoapTest.php
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('../include/nusoap/nusoap.php'); //must also have the nusoap code on the ClientSide.
$user_name ='myuser';
$user_password = 'mypassword';
$hostname = 'http://127.0.0.1/sugarcrm/custom/service/v4_1_custom/soap.php?wsdl';
// Create the SOAP client instance
$soapclient = new nusoapclient($hostname, true);
// Login to the server
echo '<b>LOGIN:</b><BR>';
$result = $soapclient->call('login',array('user_auth'=>array('user_name'=>$user_name,'password'=>md5($user_password), 'version'=>'.01'), 'application_name'=>'SoapTest'));
echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
echo print_r($result);
echo var_dump($result);
$session = $result['id'];
echo "sessionid is ".$session;
?>
预期结果:由于我正在呼叫登录,我希望看到sessionid。
注意:我没有调用自定义方法my_get_orders
,因为登录本身失败。所以我想先修复它。
实际结果:[在调用http://127.0.0.1/sugarcrm/prash/SoapTest.php
时]
HERE IS RESULT:
1
boolean false
sessionid is
答案 0 :(得分:0)
我在service / custom下放置了同一组文件[现有版本直接服务/例如:service / v4_1]。
现在它可以正常工作,所以更早的是文件路径解决问题。