Wednesday, January 23, 2008

WSDL Generation with WSF/PHP

WSF/PHP supports wsdl generation for the well known serviceuri?wsdl request. In addition to that it generates ?wsdl2 as well.

So How can you get make your php service generate the wsdl?
Well, the steps are quite simple. Since php functions does not contain type information for the input or output parameters, WSF/PHP obtains the type infromation
from the documentation comments.

Following is an example service with annotations.

/** BuyItem function
* @param string $item_name of the item to buy
* (maps to the xs:string XML schema type )
* @param int $amount no of items to buy
* (maps to the xs:nonNegativeInteger XML schema type)
* @return float $price total price
*(maps to the xs:double XML schema type )
*/
function getPriceFunction($item_name ,$amount)
{
global $item;
if ($item_name && $amount){
if(isset($item[$item_name])){
return array("price" => ($item[$item_name] * $amount));
}
else
return NULL;
}
return array("price" => 200043);
}

As you can see the doc comments involves the following format.

@param string $item_name
(maps to the xs:string XML schema type )
This comment says that the function parameter $item_name is of type string and is a function parameter. The second line says the corresponding XML Schema data type which is xs:string.

Similarly all the parameters and return types are annotated. Once you do that, WSF/PHP is able to process this information and automatically generate the wsdl on demand.

2 comments:

  1. is this possible with mtom attachments as well?

    ReplyDelete
  2. WSDL Generation for MTOM is not supported.

    ReplyDelete