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.

WSDL2Java and WSDL2C tools shipped with the Axis2/Java project are used to generate Stubs(client side) and Skeletons(Server Side) respectively for Axis2/Java and Axis2/C codes. This make the development of web services and consumers more quicker and easier.

The tools come with many options allowing the user to customize the code generation. One of the such option is ‘-uw’ which used to turn on the ‘unwrapping’ mode. WSDL2Java project had this option for a long time, But it is just Today I was able to enable that option in the WSDL2C tool. So lets see how it make the code easier.

Say you have the ’simpleAdd’ operation with the following schema,

            <xs:element name="simpleAdd">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="param0" type="xs:int"/>
                        <xs:element minOccurs="0" name="param1" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="simpleAddResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

When you generate the code for server side with Java using the following command, (note the option -uw which stands for ‘unwrapping’)

wsdl2java.sh -uri xxx.wsdl -u -ss -sd -uw

it gives you the following service function.

public int simpleAdd(int param0, int param1)
{
    //TODO : fill this with the necessary business logic
}

Note the input and output parameters of the function are simple types. If you don’t give the ‘-uw’ option, You will instead get a function with input and output variables as class names wrapping these simple types which is not this much straight forward.

So now the same is available with C. You can use WSDl2C tool with the same option set to generate a very simple service API.

wsdl2c.sh -uri xxx.wsdl -u -ss -sd -uw

And here is the service logic you may write, Can you think of an API simpler than this,

        /**
         * auto generated function definition signature
         * for "simpleAdd|http://ws.apache.org/axis2" operation.
         * @param env environment ( mandatory)
         * @param _param0 of the int
         * @param _param1 of the int
         *
         * @return int
         */
        int axis2_skel_UnwrappedAdder_simpleAdd(const axutil_env_t *env,
                                              int _param0,
                                              int _param1 )

        {
          return _param0 + _param1;
        }

You can find the code for complete case (wsdl, skel and stub) in the Axis2/C Jira Attachment space for the ‘unwrapping’ issue. Note that this update is only available in the nightly build and not in the release. You can download the nightly build from wso2’s axis2/java nightly build page.