首页 新闻 赞助 找找看

ZF2 中soap client调用soap server 中的方法,但是adapter始终都为空的错误

0
悬赏园豆:20 [已关闭问题] 关闭于 2013-05-06 10:55

我在项目中定义了一个Api的module,用于接口的调用模块。

api模块中存放格式和ZF2的标准结构一样。我在controller中编写了如下代码:

class IndexController extends AbstractActionController
{

    private $_WSDL_URI = "http://m158/ff-zf2/public/api?wsdl";
        
    private function handleSOAP() {
        $soap = new \Zend\Soap\Server($this->_WSDL_URI);
        $soap->setClass('Api\Api');
        $soap->handle();
        exit;
    }
    
    private function handleWSDL()
    {
          $autodiscover = new \Zend\Soap\AutoDiscover(); 
          
        $autodiscover->setClass('Api\Api')
                     ->setUri( $this->_WSDL_URI );
                          
           $autodiscover->generate();
        $autodiscover->handle();
        exit;
    }

    public function indexAction()
    {    
            $view = new ViewModel();
            $view->setTerminal(true);
            ini_set("soap.wsdl_cache_enabled","0");
        
            if (isset($_GET['wsdl'])) {
                $this->handleWSDL();
            } else {
            $this->handleSOAP();
            }
    }
    
    public function clientAction() {
         $options = array('location' => 'http://m158/ff-zf2/public/api',
                 'uri' => 'http://m158/ff-zf2/public/api?wsdl');
            
          $client = new \Zend\Soap\Client(null, $options);
          $result = $client->api('user.login', array("email"=>"shimanjun@126.com",
                                          "password"=>"dfjofosdfe"));
    }
}

在和controller同级目录下创建了一个名为Api的类,该类主要是做api调用的主类。代码如下:

class Api
{
    /**
     * 
     * 登录帐号密码是否正确
     * @param string $operation
     * @param Array $statement
     * @return string
     */
    public function api($operation, $statement){
        $apiInfo = explode('.', $operation);    
        
        $className = '\\Api\\Model\\'.ucwords($apiInfo[0]);
        $method = $apiInfo[1];
        
        extract($statement);
        
        switch ($apiInfo[0]) {
            case 'user':
                $result = $user->$method($email, $password);
                return $result;
                break;
                
            case '';
            
                break;
            
            default:
                
                break;
        }
    }
}

现在我遇到的问题是在调用User类中的方法时,因没有办法得到adapter对象,而无法执行查询操作。请高手们帮忙看下这个问题该怎么解决。

我试过的解决方法:

  1. 在调用方传递adapter对象。
  2. 在User Model中实现ServiceLocatorAwareInterface
    (总是提示serviceLocator为空)
  3. 在Module.php中的init方法中设置Model的adapter对象的值,但是在Api类中实例化后adapter被清空了。
  4. 在Api类中获取adapter对象。通过实例化serviceManager来获取adpater,但是不知道是不是方法不对。serviceManager总是为空。

测试操作是调用index的clientAction即可

@sheep的主页 @sheep | 初学一级 | 园豆:158
提问于:2013-05-02 19:36
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册