WSDL Generation in WSO2 WSF/PHP is done using PHP reflection and an annotation parser. In order 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.
@param PHP_parameter_type $parameterName
( xs:XSDType )
Users can add their own comments only after the $parameter Name
@return PHP_return_type $returnValueName
( xs:XSDType )
Users can add their own comments only after the $parameter Name
/** The purchaseOrder function
* @param int $itemNo ID of the purchase Item
* (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 your lucky number
*(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 needed 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 |
To get WSDL 1.1 use ?wsdl .To get WSDL 2.0 use ?wsdl2
e.g.
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 treated as default.
e.g.
$service = new WSService(array("operations"=>$operations, "bindingstyle"=>"rpc"))
Binding Style
Parameter
Document/literal wrapped
doc-lit
RPC/encoded rpc
e.g. Generating Message elements and a schema for the document/literal wrapped 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>
e.g. 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>