Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp soap服务器_Php_Web Services_Cakephp_Soap_Wsdl - Fatal编程技术网

Cakephp soap服务器

Cakephp soap服务器,php,web-services,cakephp,soap,wsdl,Php,Web Services,Cakephp,Soap,Wsdl,我试图在CakePHP2中创建一个Web服务,但我找到的所有信息都是关于CakePHP1的。 我已经做了几天的搜索,但它不工作。 我创建了以下控制器: class SoapsController extends AppController { var $components = array('RequestHandler'); //listes des model utilisé public $uses =array('Pompe', 'Serie', 'Fluide','Control'

我试图在CakePHP2中创建一个Web服务,但我找到的所有信息都是关于CakePHP1的。 我已经做了几天的搜索,但它不工作。 我创建了以下控制器:

class SoapsController extends AppController {

var $components = array('RequestHandler');

//listes des model utilisé
public $uses =array('Pompe', 'Serie', 'Fluide','Control');

function service() {
    $this->layout = false;
    $this->autoRender = false;
    Configure::write('debug', 0);
    ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
    $server = new SoapServer('http://localhost/pps/soaps/wsdl');
    $server->setClass("Soap");
    $server->handle();
}

function wsdl() {
    $this->layout = false;
    Configure::write('debug', 0);
    $this->RequestHandler->respondAs('xml');
}
}
并将wsld文件放在view/soaps/wsdl.ctp中。 当我用客户端调用webservice时,它不起作用。 你能帮我做这个吗

经过一些尝试后,我更改了代码,如下所示,但当我使用客户端调用webservice时,出现了其他错误 我创建了一个messagescontroller

class MessagesController extends AppController {

 public $uses = null; //for demostration purposes we do not need a model

function beforeFilter(){
  parent::beforeFilter();
  $this->Auth->allow();

}

    public $components = array(
        'Soap' => array(
            'wsdl' => 'myWSDLFile', //the file name in the view folder
            'action' => 'service', //soap service method / handler
        )
    );

    public function soap_wsdl(){
        //will be handled by SoapComponent
    }

    public function soap_service(){
        //will be handled by SoapComponent
    }

    /**
     * A soap call 'soap_foo' is handled here
     *
     * @param Object $in The input parameter 'foo'
     * @return Object
     */
    public function soap_foo($in){
        $obj = new stdClass();
        $obj->out = 'foo response';
        return $obj;
    }
}
WSDL文件放置在view/Elements/myWSDLFile.WSDL中

创建一个消息模型

class Message extends AppModel {
    public $useTable = false; // Ce model n'utilise pas une table de la base de données
 }
在Controller/Component/soapComponent.php中添加类soapComponent

App::import('core', 'AppHelper');

/**
* Soap component for handling soap requests in Cake
*
* @author      Marcel Raaijmakers (Marcelius)
* @copyright   Copyright 2009, Marcel Raaijmakers
* @license     http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class SoapComponent extends Component{

    var $name = 'Soap';

    var $components = array('RequestHandler');

    var $controller;

    var $__settings = array(
        'wsdl' => false,
        'wsdlAction' => 'wsdl',
        'prefix' => 'soap',
        'action' => array('service'),
    );

    public function initialize($controller, $settings = array()){
        if (Configure::read('debug') != 0){
            ini_set('soap.wsdl_cache_enabled', false);
        }

        $this->controller = $controller;

        if (isset($settings['wsdl']) && !empty($settings['wsdl'])){
            $this->__settings['wsdl'] = $settings['wsdl'];
        }

        if (isset($settings['prefix'])){
            $this->__settings['prefix'] = $settings['prefix'];
        }

        if (isset($settings['action'])){
            $this->__settings['action'] = is_array($settings['action']) ? $settings['action'] : array($settings['action']);
        }

        parent::initialize($controller);
    }


    public function startup(){
        if (isset($this->controller->params['soap'])){
            if ($this->__settings['wsdl'] != false){
                //render the wsdl file
                if ($this->action() == $this->__settings['wsdlAction']){
                    Configure::write('debug', 0);
                    $this->RequestHandler->respondAs('xml');

                    $this->controller->ext = '.wsdl';
                    $this->controller->render(null, false, DS . 'elements' . DS . $this->__settings['wsdl']); //only works with short open tags set to false!
                } elseif(in_array($this->action(), $this->__settings['action'])) {

                    //handle request
                    $soapServer = new SoapServer($this->wsdlUrl());
                    $soapServer->setObject($this->controller);
                    $soapServer->handle();

                    //stop script execution
                    $this->_stop();
                    return false;

                }
            }
        }
    }

    /**
     * Return the current action
     *
     * @return string
     */
    public function action(){
        return (!empty($this->__settings['prefix'])) ? str_replace( $this->__settings['prefix'] . '_', '',  $this->controller->action) : $this->controller->action;
    }

    /**
     * Return the url to the wsdl file
     *
     * @return string
     */
    public function wsdlUrl(){
        return AppHelper::url(array('controller'=>Inflector::underscore($this->controller->name), 'action'=>$this->__settings['wsdlAction'], $this->__settings['prefix'] => true), true);
    }

}
最后,通过添加

Router::connect('/soap/:controller/:action/*', array('prefix'=>'soap', 'soap'=>true));
当我尝试对客户端使用web服务时,如下所示

<?php 
ini_set('soap.wsdl_cache_enabled', 0); //enable when in production mode, this does save a lot of        time 

$soapClient = new SoapClient('http://localhost/pps-soap/soap/messages/wsdl'); 

$param = new StdClass(); 
$param->in = 'param'; 

$foo = $soapClient->soap_foo($param); 
var_dump($foo); //an object of StdClass with an 'out' field and the value 'foo response' 
?> 

我有一个soap错误,PHP致命错误:soap-error:解析WSDL:无法从中加载
'http://localhost/pps-soap/soap/messages/wsdl“

我完全迷路了!!需要帮助才能在cakePHP中使用Soap服务。遵循以下步骤。 我们有两个选择。1.使用WSDL2。使用位置和uri参数。我使用了uri参数:

在滚动中:

App::uses('Controller', 'Controller');
App::uses('Post', 'Model');  // Dont forgot to add this

class PostsController extends AppController {

    var $components = array('RequestHandler');

    function myservice() {
        $this->layout = false;
        $this->autoRender = false;
        Configure::write('debug', 2);
        ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache

        $server = new SoapServer(null, array(
            'location' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
            'uri' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
        )
        );
        $server->setClass('Post');
        $server->handle();
    }

function testClient() {
        $client = new SoapClient(null, array('location' => "http://localhost:81/webcake/posts/service",
                                     'uri'      => "http://localhost:81/webcake/posts/service"));


        echo $client->myTest(5,5); 
    }
在模型中:

class Post extends AppModel {
    var $useDbConfig = 'soap';
    var $useTable = false;

    function myTest($x,$y) {
        return $x+$y;
    }

In oder to see the results open url: Ex: http://localhost:81/webcake/posts/testClient

在cakePHP中使用Soap服务。遵循以下步骤。 我们有两个选择。1.使用WSDL2。使用位置和uri参数。我使用了uri参数:

在滚动中:

App::uses('Controller', 'Controller');
App::uses('Post', 'Model');  // Dont forgot to add this

class PostsController extends AppController {

    var $components = array('RequestHandler');

    function myservice() {
        $this->layout = false;
        $this->autoRender = false;
        Configure::write('debug', 2);
        ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache

        $server = new SoapServer(null, array(
            'location' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
            'uri' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
        )
        );
        $server->setClass('Post');
        $server->handle();
    }

function testClient() {
        $client = new SoapClient(null, array('location' => "http://localhost:81/webcake/posts/service",
                                     'uri'      => "http://localhost:81/webcake/posts/service"));


        echo $client->myTest(5,5); 
    }
在模型中:

class Post extends AppModel {
    var $useDbConfig = 'soap';
    var $useTable = false;

    function myTest($x,$y) {
        return $x+$y;
    }

In oder to see the results open url: Ex: http://localhost:81/webcake/posts/testClient

在cakePHP中使用Soap服务。遵循以下步骤。 我们有两个选择。1.使用WSDL2。使用位置和uri参数。我使用了uri参数:

在滚动中:

App::uses('Controller', 'Controller');
App::uses('Post', 'Model');  // Dont forgot to add this

class PostsController extends AppController {

    var $components = array('RequestHandler');

    function myservice() {
        $this->layout = false;
        $this->autoRender = false;
        Configure::write('debug', 2);
        ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache

        $server = new SoapServer(null, array(
            'location' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
            'uri' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
        )
        );
        $server->setClass('Post');
        $server->handle();
    }

function testClient() {
        $client = new SoapClient(null, array('location' => "http://localhost:81/webcake/posts/service",
                                     'uri'      => "http://localhost:81/webcake/posts/service"));


        echo $client->myTest(5,5); 
    }
在模型中:

class Post extends AppModel {
    var $useDbConfig = 'soap';
    var $useTable = false;

    function myTest($x,$y) {
        return $x+$y;
    }

In oder to see the results open url: Ex: http://localhost:81/webcake/posts/testClient

在cakePHP中使用Soap服务。遵循以下步骤。 我们有两个选择。1.使用WSDL2。使用位置和uri参数。我使用了uri参数:

在滚动中:

App::uses('Controller', 'Controller');
App::uses('Post', 'Model');  // Dont forgot to add this

class PostsController extends AppController {

    var $components = array('RequestHandler');

    function myservice() {
        $this->layout = false;
        $this->autoRender = false;
        Configure::write('debug', 2);
        ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache

        $server = new SoapServer(null, array(
            'location' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
            'uri' => 'http://localhost:81/webcake/posts/myservice', // Required for non wsdl mode
        )
        );
        $server->setClass('Post');
        $server->handle();
    }

function testClient() {
        $client = new SoapClient(null, array('location' => "http://localhost:81/webcake/posts/service",
                                     'uri'      => "http://localhost:81/webcake/posts/service"));


        echo $client->myTest(5,5); 
    }
在模型中:

class Post extends AppModel {
    var $useDbConfig = 'soap';
    var $useTable = false;

    function myTest($x,$y) {
        return $x+$y;
    }

In oder to see the results open url: Ex: http://localhost:81/webcake/posts/testClient
对我有用的是: 创建SoapController:

<?php

namespace App\Controller;

use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Log\Log;
use Cake\View\ViewBuilder;

class SoapController extends AppController {

var $components = array('RequestHandler');

public function initialize () {
    parent::initialize(); 
    $this->Auth->allow(["wsdl"]);
    $this->Auth->allow(["service"]);

}

public function beforeFilter (Event $event) {
    parent::beforeFilter($event);

    if (Configure::read('Security')) {
        $this->Security->config('unlockedActions', ['service']);
        $this->Security->config('unlockedActions', ['wsdl']);
    }

}

public function wsdl () {
    try {

        $builder = new ViewBuilder();
        $builder->autoLayout(false);

        $builder->template('Soap/wsdl');

        $view = $builder->build();

        $viewContent = $view->render();

        header('Content-Type: text/xml');

        echo $viewContent;

    } catch (\Exception $e) {
        Log::error("SOAP Server error: %s\n", $e->getMessage());

    }
    exit();
}

public function service () {

    $this->viewBuilder()->layout = false;
    $this->autoRender = false;
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer('http://localhost/soap/wsdl');

    $server->setClass("App\Controller\{yourClassWithSoapFunctions}");

    $server->handle();
}

}
对我有用的东西: 创建SoapController:

<?php

namespace App\Controller;

use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Log\Log;
use Cake\View\ViewBuilder;

class SoapController extends AppController {

var $components = array('RequestHandler');

public function initialize () {
    parent::initialize(); 
    $this->Auth->allow(["wsdl"]);
    $this->Auth->allow(["service"]);

}

public function beforeFilter (Event $event) {
    parent::beforeFilter($event);

    if (Configure::read('Security')) {
        $this->Security->config('unlockedActions', ['service']);
        $this->Security->config('unlockedActions', ['wsdl']);
    }

}

public function wsdl () {
    try {

        $builder = new ViewBuilder();
        $builder->autoLayout(false);

        $builder->template('Soap/wsdl');

        $view = $builder->build();

        $viewContent = $view->render();

        header('Content-Type: text/xml');

        echo $viewContent;

    } catch (\Exception $e) {
        Log::error("SOAP Server error: %s\n", $e->getMessage());

    }
    exit();
}

public function service () {

    $this->viewBuilder()->layout = false;
    $this->autoRender = false;
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer('http://localhost/soap/wsdl');

    $server->setClass("App\Controller\{yourClassWithSoapFunctions}");

    $server->handle();
}

}
对我有用的东西: 创建SoapController:

<?php

namespace App\Controller;

use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Log\Log;
use Cake\View\ViewBuilder;

class SoapController extends AppController {

var $components = array('RequestHandler');

public function initialize () {
    parent::initialize(); 
    $this->Auth->allow(["wsdl"]);
    $this->Auth->allow(["service"]);

}

public function beforeFilter (Event $event) {
    parent::beforeFilter($event);

    if (Configure::read('Security')) {
        $this->Security->config('unlockedActions', ['service']);
        $this->Security->config('unlockedActions', ['wsdl']);
    }

}

public function wsdl () {
    try {

        $builder = new ViewBuilder();
        $builder->autoLayout(false);

        $builder->template('Soap/wsdl');

        $view = $builder->build();

        $viewContent = $view->render();

        header('Content-Type: text/xml');

        echo $viewContent;

    } catch (\Exception $e) {
        Log::error("SOAP Server error: %s\n", $e->getMessage());

    }
    exit();
}

public function service () {

    $this->viewBuilder()->layout = false;
    $this->autoRender = false;
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer('http://localhost/soap/wsdl');

    $server->setClass("App\Controller\{yourClassWithSoapFunctions}");

    $server->handle();
}

}
对我有用的东西: 创建SoapController:

<?php

namespace App\Controller;

use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Log\Log;
use Cake\View\ViewBuilder;

class SoapController extends AppController {

var $components = array('RequestHandler');

public function initialize () {
    parent::initialize(); 
    $this->Auth->allow(["wsdl"]);
    $this->Auth->allow(["service"]);

}

public function beforeFilter (Event $event) {
    parent::beforeFilter($event);

    if (Configure::read('Security')) {
        $this->Security->config('unlockedActions', ['service']);
        $this->Security->config('unlockedActions', ['wsdl']);
    }

}

public function wsdl () {
    try {

        $builder = new ViewBuilder();
        $builder->autoLayout(false);

        $builder->template('Soap/wsdl');

        $view = $builder->build();

        $viewContent = $view->render();

        header('Content-Type: text/xml');

        echo $viewContent;

    } catch (\Exception $e) {
        Log::error("SOAP Server error: %s\n", $e->getMessage());

    }
    exit();
}

public function service () {

    $this->viewBuilder()->layout = false;
    $this->autoRender = false;
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer('http://localhost/soap/wsdl');

    $server->setClass("App\Controller\{yourClassWithSoapFunctions}");

    $server->handle();
}

}

你说的“它不工作”是什么意思?事实上,我想它可以工作,但我不知道我想在web服务中的什么地方实现我的功能,以及如何使用它。我对soap有点迷茫:(你说“它不工作”是什么意思?事实上,我想它可以工作,但我不知道在web服务中我想在哪里实现我的功能以及如何使用它。我对soap有点迷茫:(你说“它不工作”是什么意思?)?事实上,我想它可以工作,但我不知道在web服务中我想在哪里实现我的功能以及如何使用它。我对soap有点迷茫:(你说“它不工作”是什么意思?事实上,我想它可以工作,但我不知道在web服务中我想在哪里实现我的功能,以及如何使用它。我对soap有点迷茫:(