WSDL generation in WSO2 WSF/PHP is done using PHP reflection and an annotation parser. To generate a WSDL from a given WSO2 WSF/PHP service, a ?wsdl request should be sent to the server. For example, if you want to generate the WSDL for the service echoService.php, a request should be sent as,
http://localhost/services/echoService.php?wsdl
Upon receiving the request, the relevant WSDL is generated. If the PHP script that implements the service contains annotations provided by the programmer, they will be used for WSDL generation. If the annotations are missing or if there is a syntax error, the WSDL will be generated using reflection and XSD:Any as the type for the parameters.
Parameter types and return types should be annotated for a PHP function using the following syntax.
Syntax:
@param PHP_parameter_type $parameterName ( xs:XSDType )
Example:
/** * @param string $name your first name * (maps to the xs:string XML schema type) */
You can add your own comments only after the $parameterName
Syntax:
@return PHP_return_type $returnValueName ( xs:XSDType )
Example:
/** * @return int $t your lucky number * (maps to the xs:int XML schema type ) */
You can add your own comments only after the $returnValueName
/** * The purchaseOrder function * @param int $itemNo ID of the item to be purchased * (maps to the xs:int XML schema type ) * @param string $date Date that the purchase order was done * (maps to the xs:gDate XML schema type) * @return int $price tolal price * (maps to the xs:nonNegativeInteger schema type ) */ function purchaseOrder ($itemNo, $date) { // some logic return $Price; }
Since PHP is a weakly-typed language in nature, the following type mapping is required to map the PHP types to the XML Schema types.
Schema Type | PHP Type |
string | string |
boolean | boolean |
double | float |
float | float |
int | int |
integer | int |
byte | int |
decimal | string |
base64Binary | string |
hexBinary | string |
anyType | soap var object |
any | soap var object |
QName | string |
dateTime | string |
date | string |
time | string |
unsignedLong | int |
unsignedInt | int |
unsignedShort | int |
unsignedByte | int |
positiveInteger | int |
negativeInteger | int |
nonNegativeInteger | int |
nonPositiveInteger | int |
gYearMonth | string |
gMonthDay | string |
gYear | string |
gMonth | string |
gDay | string |
duration | string |
Name | string |
NCName | string |
NMTOKEN | string |
NOTATION | string |
NMTOKENS | string |
ENTITY | string |
ENTITIES | string |
IDREF | string |
IDREFS | string |
anyURI | string |
language | string |
ID | string |
normalizedString | string |
token | string |
Both WSDL 1.1 as well as WSDL 2.0 are supported.
To get WSDL 1.1 use '?wsdl'. To get WSDL 2.0 use '?wsdl2'
Example,
For WSDL 1.1 - http://localhost/services/echoService.php?wsdl
For WSDL 2.0 - http://localhost/services/echoService.php?wsdl2
The SOAP binding style should be set in a PHP service option array. If the SOAP style is not set, then the document style is assumed as the default.
Example,
$service = new WSService(array("operations"=>$operations, "bindingstyle"=>"rpc"))
Binding Style | Parameter |
---|---|
Document literal | doclit |
RPC encoded | rpc |
Example: Generating Message elements and a schema for the document literal style .
/** The LuckyNo function * @param string $yr year of your birthday * (maps to the xs:gYear XML schema type ) * @param string $name your first name * (maps to the xs:string XML schema type) * @return int $t your lucky number * (maps to the xs:int XML schema type ) */ function luckyNoFunction($yr,$name) { // some logic return $t; }
In the generated WSDL, the operation named "luckyfunction" has two messages.
<operation name="luckyNoFunction"> <input message="s0:luckyNoFunctionInput"/> <output message="s0:luckyNoFunctionOutput"/> </operation>
In message elements,
<message name="luckyNoFunctionInput"> <part name="parameters" element="luckyNoFunction"/> </message> <message name="luckyNoFunctionOutput"> <part name="parameters" element="luckyNoFunctionResponse"/> </message>
Therefore, the generated schema that can be accessible on the server side is,
<element name="luckyNoFunction"> <complexType> <sequence> <element name="yr" type="xsd:gYear"/> <element name="name" type="xsd:string"/> </sequence> </complexType> </element> <element name="luckyNoFunctionResponse"> <complexType> <sequence> <element name="t" type="xsd:int"/> </sequence> </complexType> </element>
Example, for RPC style:
The message elements are,
<message name="luckyNoFunction"> <part name="yr" type="xsd:gYear"/> <part name="name" type="xsd:string"/> </message> <message name="luckyNoFunctionResponse"> <part name="t" type="xsd:int"/> </message>