Developing SOAP API's With TYPO3 Flow

SOAP, originally defined as Simple Object Access protocol, is a protocol specification for exchanging structured information in the implementation of web services in computer networks. It relies on XML Information Set for its message format, and usually relies on other application layer protocols, most notably Hypertext Transfer Protocol (HTTP) or Simple Mail Transfer Protocol (SMTP), for message negotiation and transmission. 

Requirements: 

You should have a running, TYPO3 Flow installation. Your PHP installation should have the soap extension installed and activated.


Installing TYPO3.Soap Package: 

  1. Installing TYPO3.Soap package using composer:  
    1. Add following in the require section of the global composer.json file:  
       "typo3/soap": "*" 
    2. Run command: 
      composer update --dev 
  2. For the WSDL generation to work, you have to add the subroutes of the TYPO3.Soap package to your global routes in Configuration/Routes.yaml:

    ##
    # TYPO3.Soap subroutes
    #
     
    -
    name: 'TYPO3.Soap'
    uriPattern: '<SoapSubroutes>'
    subRoutes:
    SoapSubroutes:
    package: TYPO3.Soap


Kickstarting the WebService: 

Kickstart a new package (Lelesys.ProductStore.Webservice) in the TYPO3 Flow installation.

Classes/Service/Soap/ProductService.php 

<?php

namespace Lelesys\ProductStore\WebSerice\Soap\Service\Soap;
use Neos\Flow\Annotations as Flow;

/**
 * A simple SOAP Product service
 *
 * @Flow\Scope("singleton")
 */
class ProductService {

/**
* Display simple message
*
* @param string $product 
* @return string A nice product message
*/
public function message($product) {
return $product . ' can be found in Lelesys Store';
}

}

?>

A WSDL will be generated for the above code by the TYPO3.Soap Package.


Complex Data:

To deal with the complex data we can use the DTO (Data Transfer Objects) in TYPO3 Flow. 

Classes/Service/Soap/Dto/Store.php 

<?php

namespace Lelesys\ProductStore\WebService\Soap\Service\Soap\Dto;

use Neos\Flow\Annotations as Flow;

/**
 * A simple Store DTO
 */
class Store {

/**
* @var string
*/
protected $name;

/**
* @param string $name
*/
public function setName($name) {
$this->name = $name;
}

/**
* @return string
*/
public function getName() {
return $this->name;
}

}

?>


Complex Data Service: 

Classes/Service/Soap/StoreService.php

<?php

namespace Lelesys\ProductStore\WebSerice\Soap\Service\Soap;

use Neos\Flow\Annotations as Flow;

/**
 * A simple SOAP Store service
 *
 * @Flow\Scope("singleton")
 */
class StoreService {

/**
* @Flow\Inject
*  @param Lelesys\ProductStore\Domain\Repository\StoreRepository
*/
protected $storeRepository;

/**
* Returns Store DTO
*
* @param string $storeId
* @return  Lelesys\ProductStore\WebService\Soap\Service\Soap\Dto\Store The store DTO
*/
public function findByIdentifier($storeId) {
$store = $this->storeRepository->findByIdentifier($storeId);
$storeDto = new Lelesys\ProductStore\WebService\Soap\Service\Soap\Dto\Store();
$storeDto->setName($store->getName);
return $storeDto;
}

}

?>


Using SOAP API:

You can PHP Soap client to use the SOAP API's.
There are SOAP UI available to use the SOAP API's.

For more information on SOAP API you can read here:
http://www.typo3-tutorials.org/flow/soap-webservices-with-flow3.html


Categories: Flow Framework, APIs

Copyright © 2019 Lelesys Informatik GmbH, Deutschland. All Rights Reserved.