Code First Approach of Developing Services with WSF/PHP 2.0

In the code first approach, WSF/PHP will generate you the WSDL from your annotated PHP code. If you are familiar with older versions of WSF/PHP you should be already familiar with the syntax used in the annotations which are more or less the same as the conventional PHP doc comment. If you are really new to WSF/PHP annotated code here are two examples.

1. Function with simple types for input and output parameters.

/**
 * add function
 * @param int $x (maps to xsd:int)
 * @param int $y (maps to xsd:int)
 * @return int $x (maps to xsd:int)
 */
 function add($x, $y) {
   return $x + $y;
 }

2. Function with PHP classes for input and output parameters

/**
 * add function
 * @param object Vector $x (maps to objects)
 * @param object Vector $y (maps to objects)
 * @return object Vector $z (maps to objects)
 */
 function add($x, $y) {
   return $x + $y;
 }

 class Vector {
    /**
     * @var array of int $numbers (maps to xs:int)
     */
    public $numbers;
 }

WSF/PHP 2.0 has introduced new PHP annotation syntax so you have more control over the generating WSDL.

  • Now you can have custom namespaces for your schemas
  • More control over minOccurs and maxOccurs values.
  • Supporting ‘In only’ Message Exchange Pattern.
  • Generating with WS-Addressing parameters if the ‘useWSA’ option is set to true.
  • Fixes for empty input parameters.

So if you prefer Code First approach, WSF/PHP 2.0 will provide you an ideal platform for quick and easy development of web services.

This entry was posted in Tutorial/Guide, web services, WSDL, wsf/php, wso2, xml, xml schema and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *