Leisure and SOAP

How can I implement both restful and SOAP together?

+3
source share
6 answers

REST and SOAP are mutually exclusive concepts. You can not.

0
source

You cannot implement a single API that conforms to both REST and SOAP.

However, you can create a system that provides RESTful and SOAP APIs with equivalent functionality.

To do this, the base system implementation must be independent of both APIs. If, for example, you implement your system with Java, the base implementation and each API must be in independent packages. If Python, independent modules. Etc.

, , API , : API RESTful , SOAP API .

, , SOAP API REST API, HTTP. - REST-via-SOAP.

, REST API Mailboxes, GET, POST, PUT DELETE, application/json, , SOAP:

  • get_mailboxes(url, options) returns jsonDoc
  • post_mailboxes(url, options, jsonDoc) returns jsonDoc
  • put_mailboxes(url, options, jsonDoc) returns jsonDoc
  • delete_mailboxes(url, options) returns nothing

, , SOAP.

+12

, SOAP, RESTful. Axis2 WSDL 2.0 .

, RESTful Web Services Apache Axis2 - .

..

+2

, REST, SOAP-. , .

+1

, wsdlLocation @webserivce

+1

, . php zend framework.

, api, . php script, , , . .

, , , , , , , , , Zend_Rest_Server Zend_Soap_Server ($ controllerClassName) .

, api () .

public function dispatch()
{

    $this->preDispatch();

    $include_file_path = sprintf(APPLICATION_PATH . "/modules/%s/controllers/%s.php", ucfirst($this->request->getModuleName()), ucfirst($this->request->getControllerName()));
    require_once $include_file_path;

    $controllerClassName = sprintf("%s_Controller", ucfirst($this->request->getControllerName()));

    switch (strtolower($this->request->getServiceType())) {
        case self::REST_SERVICE:
            $r = $this->getRequest();
            $server = new Rest_Server();
            $server->setClass($controllerClassName);
            $server->handleRequest($this->request);

            break;

        case self::SOAP_SERVICE:

            if (array_key_exists('wsdl', $this->getRequest()->getQuery()) || array_key_exists('WSDL', $this->getRequest()->getQuery())) {

                $auto = new Zend_Soap_AutoDiscover();
                $auto->setClass($controllerClassName);
                $auto->handle();
            } elseif (count($this->getRequest()->getQuery()) == 0) {

                $wsdl = sprintf('http://%s%s?wsdl', $this->getRequest()->getHttpHost(), $this->getRequest()->getPathInfo());

                $soapServer = new Soap_Server($wsdl);
                $soapServer->setClass($controllerClassName);
                $soapServer->handle();
            }

            break;

        default:
            break;
    }

    $this->postDispatch();
}
0

Source: https://habr.com/ru/post/1715974/


All Articles