XML Attributes in your payload

Friday, June 27, 2008

If you want to have xml attributes in your message payload you have to design a WSDL so that it contains schema types with attributes. For an example

<xs:complexType name=\"myType\">
<xs:element name=\"demo1\" type=\"xs:string\"/>
<xs:element name=\"demo2\" type=\"xs:string\"/>
<xs:attribute name=\"demo3\" type=\"tns:derivedType\"/>

PHP webservices demo site have samples WSDLs that defines attributes http://labs.wso2.org/wsf/php/solutions/wsdl_mode/AttributeService.php?wsdl. And you can test a sample service setting your clients endpoint to http://labs.wso2.org/wsf/php/solutions/wsdl_mode/AttributeService.php. Write your client with the help of the generated code for the WSDL. You can try it online from Here. And make sure you have installed WSF/PHP to do all of these.

Testing https requests with WSClient

Tuesday, June 24, 2008

If any case you found your WSClient fails in sending https request, you can use the "https://6ec2.dyndns.org/samples/wsdl_mode/wsdl_11_service.php" service to test whether the problem is in your WSF/PHP installation or something else. What you need to do is edit the samples/wsdl_mode/wsdl_11_client.php so that your WSClient constructor have the following value.

$client = new WSClient(array("wsdl"=>"sample_wsdl_11.wsdl",
"to" => "https://6ec2.dyndns.org/samples/wsdl_mode/wsdl_11_service.php",
"CACert" => "server.crt"

Use the approach mentioned in this blog post to generate the above server.crt certifcate.

Then run the sample in the command prompt or shell
php wsdl_11_client.php and test whether the response comes as expected. if not you have to check the wsf/php instatllatioin steps again.

New Features in the PHP Data Services Library

Thursday, June 19, 2008

Here are the new features in the latest PHP Data Service Library,

1. Multiple data base engine support (with php PDO extension)
2. Nested Query support
3. New Array based API, documented at
4. dbs2php converter, convert WSAS Java data services configuration XMLs to PHP code.
5. WSDL Generation support - works only with the latest WSF/PHP SVN.

You can check the Demos powered by the new library from here. You can see the newly added demo4 that demonstrates the Nested Queries.

And Online dbs2php tool is available from here. Anyway in the demo site the ?wsdl will not work, since it is hosted with wsf/php 1.3.2. (If you want ?wsdl for data services, please use the latest WSF/PHP svn)

Choose among multiple services, multiple ports

If your wsdl has multiple services and multiple ports, You can tell your PHP client to use a preferred service and port by setting "serviceName" and "portName" option in the WSClient.

For an example if you take wsdl1.1 with multiple services and ports like this,

<wsdl:service name=\"Adder1\">
<wsdl:port name=\"SOAP11port_http\" binding=\"ns0:AdderSOAP11Binding\">

<soap:address location=\"http://localhost:8080/axis2/services/Adder1\"/>
<wsdl:port name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\">

<soap12:address location=\"http://localhost:8080/axis2/services/Adder1\"/>
<wsdl:service name=\"Adder2\">

<wsdl:port name=\"SOAP11port_http\" binding=\"ns0:AdderSOAP11Binding\">
<soap:address location=\"http://localhost:8080/axis2/services/Adder2\"/>

<wsdl:port name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\">
<soap12:address location=\"http://localhost:8080/axis2/services/Adder2\"/>


You can select the Adder2 service with SOAP12port_http with the following optional arguments to the getProxy method.

$client = new WSClient(array(\"wsdl\" => \"your_wsdl\"));

$proxy =
$client->getProxy(\"Adder2\", \"SOAP12Port_http\");

This can be represented in wsdl2 as following,

<service name=\"Adder1\" interface=\"ns0:AdderPortType\">
<endpoint name=\"SOAP11port_http\" binding=\"ns0:SOAP11Binding\" address=\"http://localhost:8080/axis2/services/Adder1\"/>

<endpoint name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\" address=\"http://localhost:8080/axis2/services/Adder1\"/>

<service name=\"Adder2\" interface=\"ns0:AdderPortType\">
<endpoint name=\"SOAP11port_http\" binding=\"ns0:SOAP11Binding\" address=\"http://localhost:8080/axis2/services/Adder2\"/>

<endpoint name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\" address=\"http://localhost:8080/axis2/services/Adder2\"/>

Note that here portName you provided is considered as the endpoint name under the selected service.

When you don't provide either serviceName and the portName, wsf/php will pick the first serviceName and portName listed in the wsdl.

Although multiple services in the same wsdl is very rare, multiple ports /endpoints in the same service is very common. Specially when you support multiple versions of SOAP, addressing, or even completely different policies for the interface you will surely be having multiple ports.

WSF/PHP Code generated for Some famous Web Services

Sunday, June 15, 2008

If you ever wanted writing a client for some famous public web service, WSF/PHP will make your task easy. You want proofs?, Ok, here are some links to famous web services and generated WSF/PHP code to invoke the service.


Service NameWSDLWSF/PHP generated code

Alexa Web Search



Alexa Top Sites



Amazon EC2 Service



Betfair Service



Java DataServices to PHP Code Generator

Saturday, June 14, 2008

With WSO2 WSAS you can easily build a data service just using a simple configuration xml. When it come to PHP DataServices, we are introducing a simple PHP friendly array based API which is more comfortable with PHP developers.

But how if someone already have Java configuration XML or say he may prefer writing configuration in XMLs. Well we have a solution for them too.

With the next PHP Data Service library, there will be a code generation tool which give you the WSF/PHP DataServices code from the Java DataService configuration file.

One reason PHP is so much popular is its easiness in working with databases. And I believe our DataService library will fill some of the blank spaces that were there in the PHP space, specially in connecting PHP database developers with the emerging SOA world.

Verify your WSF/PHP installation

Friday, June 13, 2008

You may have installed wsf/php with the help of READMEs in the distribution or following installation guide in the documents. But you may experienced sometime you miss a step and couldn't get samples running. Here is some trouble shooting steps that you may find helpful.

1. run the following command in command line ( make sure php is in your 'PATH' environment variable)

php -m

This will lists the php modules. There you should see wsf and xsl. if either or both of this missing, check xsl.dll(or xsl.so in linux) and wsf.dll(or wsf.so in linux) in the extension directory and the php.ini extension entries.

2. Run the following command
php -i

This will list out the configuration details of php installation. Just check the entries like include_path, to check whether you have set scripts directory under it. (In linux you can check this more easily with
php -i | grep include_path

The above tests can be done using the phpinfo function as well. For that you will create a file (say phpinfo.php) in the apache document root with the following script.

and you call it from the browser (say http://localhost/phpinfo.php). and you have all the details like installed extensions (check xsl and wsf) and their configurations + include_path entries. You can verify your installation with this.

Anyway there may be chances that even though you have all these right but still samples doesn't work. Most probable reason for that result can be that you are upgrading from old wsf/php library and you already have some of old libraries in you PATH. so make sure you delete or move the old libraries to complete seperate place before you install new libraries.

And if still it didn't work just feel free to ask it in the wsf/php forum or the mailing list. Surely there should be a workaround.

PHP Data Service API revised

Thursday, June 12, 2008

If you were aware of PHP Data Service library published in the demo site, you may have realized how easy to expose your database data as a web service using a simple php script.

The next version of this library includes providing multiple database support ( in fact using the PDO extension), nested query support, WSDL generation and ability to define elements, attriubutes and text of soap payload from database data and many more. But this will not break the current simple API.

For this we came with a revised API for the DS library. I did a rough documentation (hopefully this will be improved with the time) on this at here. And this is an attempt to make it more closer to the Java Data Service API and the implementation. The ultimate goal is to allow the Data Services to move from Java to PHP and and vice versa in no time. We will let you know, when it is ready and I believe it won't be that far.

PHP Web Services Interoperability with Microsoft .NET

Wednesday, June 11, 2008

In the Microsoft TechED 2008 keynote, there was a demonstration on WSF/PHP and .NET 3.5 interoperability using the stock trader application. Watch the video.

I was responsible for setting up the PHP stuff for the demo. Red my testimony on how easy it was to get the stuff working.

Also, you can read more information form the presenter himself, Jonathan.

WSF/PHP on TechEd IT 2008

Tuesday, June 10, 2008

The interoperability between Microsoft Web Services (.NET 3.5) with WSO2 WSF/PHP and WSAS was presented at TechEd IT 2008. You can read more about this from Jonathan Marsh.

WSDL Generation with arrays

Currently WSF/PHP generates WSDL using the annotation mechanism. But this works only if you hard code the annotation in your script page. How if your operation parameters and operations change dependingon the user configuration. In fact that happened when we were providing Data Service Library. There we needed to generate the WSDL according the data base schema information, which can be configured by the library user.

So we came up with a mechanism to describe the service operation and operation parameters using arrays in addition to the annotation API already shipping with WSF/PHP.

You can visit here, for complete demonstration on the array based annotation API which is to going to be part of the WSF/PHP next release.

Http Basic Authentication in WSF/PHP

Monday, June 9, 2008

Normally in Web Services stacks authentication is done using user name token comes with WS-Security specifications. But if you are more interacting with legacy systems, you may have come across situations where you have to use http authentication.

Here is how you are going to do it with WSF/PHP. I will take simple echo sample to demonstrate this,

server side:
You have to configure apache to do the authentication, so the php and wsf/php applications which are running behind the apache server also get authenticated. The following guide will help you to do the configuration very easily,

Your server side code is same as the code for a regular service


function echoFunction($inMessage) {
$outMessage = new WSMessage($inMessage->str);
return $outMessage;

$operations = array("echoString" => "echoFunction");

$service = new WSService(array("operations" => $operations));



client side:

$requestPayloadString = <<<XML
<ns1:echoString xmlns:ns1="http://php.axis2.org/samples"><text>Hello World!</text></ns1:echoString>

try {

$client = new WSClient(array( "to" => "http://localhost/samples/echo_service.php",
"httpAuthUsername" => "xxx",
"httpAuthPassword" => "x@x",
"httpAuthType" => "Basic",

$responseMessage = $client->request( $requestPayloadString );

printf("Response = %s
", htmlspecialchars($responseMessage->str));

} catch (Exception $e) {

if ($e instanceof WSFault) {
printf("Soap Fault: %s\n", $e->Reason);
} else {
printf("Message = %s\n",$e->getMessage());


You will fill the fields specific to http authentication. And here you have web service client and service which uses http basic authentication.

Web Services Interoperability Demo with WSO2 Stock Trader Implementation

The stock trader sample application implemented by both IBM and Microsoft, is now also available in PHP and Java with WSO2 SOA Stacks.

The PHP implementation is based on WSO2 WSF/PHP and the Java implementation is based on WSO2 WSAS.

The application has three layers, presentation, middle tier and the back end. Presentation tier talks to the middle business services layer and the business service layer talks to the back end order processing layer. PHP implementation has all the three layers implemented. Java implementation has the order processing layer implemented.

Both the PHP and Java layers can work with each other, as well as with the .NET implementations of the three tiers. You can mix and match tiers, swap them with each other, to get the same SOA behavior.


As an example, as shown in the above diagram, PHP presentation tier can talk to the .NET business service layer and the .NET business service layer can talk to the Java order processing layer. And it can use advanced WS-* specs such as WS-Security, between tiers and you can still get the tiers achieve seamless interoperability.

WSDL Generation with and without $classmap option

Sunday, June 8, 2008

The $classmap is an option you can provide to the WSService constructor to tells the WSF/PHP engine that how you map the xml elements to PHP classes in your program.

When you provide classmap option, your service function declration should be such that it input the request object and output the response object.

When you don't provide classmap option, you will have a service function declration with set of input fields as input parameters. (Note that in both cases the response can be either an array or response, only the request parameter set is different from each other in two cases)

You can see how the WSDL is genererting for both above cases, which will also demonstrate the different between the service fuction declarations.

1. When the $classmap is provided, http://labs.wso2.org/wsf/php/php2wsdltool.php?example=Example3
The function declration is

* echoValue function
* @param object Foo $echoString echoString description
* @return object FooResponse $echoStringResponse
function echoValue($echoString){

2. When the $classmap is not provided, http://labs.wso2.org/wsf/php/php2wsdltool.php?example=Example4
The function declration is
* echoValue function
* @param array of object Foo $param1 param1 description
* @param string $param2
* @return array of object Boo $ret_value
function echoValue($param1, $param2){

You can find more details at here, http://wso2.org/project/wsf/php/1.3.2/docs/wsdl_generation_api.html

Comprehensive PHP REST Support on the way

The next release of WSO2 WSF/PHP would have PUT and DELETE supported, along with GET and POST, and also, the user will have the luxury of configuring the URL mapping for a given operation.

Nandika has already implemented this and is in the svn trunk of WSF/PHP. Hopefully, we will be able to provide a complete sample on how to use the API, before we do release this feature.

Currently, the next release is planned for the end of July.

WSF/PHP Against different Schema Constructs

Saturday, June 7, 2008

WSF/PHP 1.3.2 have support for many Schema constructs in the WSDL mode. You may like to check in what are the new schema constructs it is supporting.
You can find test cases for clients in here, https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/wsdl_mode and for service in here, https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/wsdl_mode

These test cases have a description about what scenarios it is testing and provide simple demonstrations how you should write programs for different schemas.

NEW WSClient option for the 1.3.0

Friday, June 6, 2008

WSF/PHP 1.3.* introduced many features specially for WSDL mode API. In addition to that it has updated WSClient a bit as well.

Here are the WSClient options you will found in 1.3.* that was not there in earlier releases.

"httpAuthUsername" - Http basic/digest authentication was added in this release, here is where you give the username to authenticate

"httpAuthPassword" - Password for Http authentication

"httpAuthType" - What type of authentication is used. The possible values are "Basic" or "Digest"

"proxyAuthUsername" - Similar to http authentication, proxy authentication too added.

"proxyAuthPassword" - Password for Proxy authentication

"proxyAuthType" - Declare whether the authentication type used is "Basic" or "Digest"

"useMTOM" - This option was already there, but possible values were only TRUE/FALSE. With this release you can give another value to this option, i.e. "swa". You can enable SOAP with Attachement with setting "useMTOM" => "swa"

For more information look at the documentation http://wso2.org/project/wsf/php/1.3.2/docs/api.html

WSO2 Web Services Framework for PHP v1.3.2 Released

Thursday, June 5, 2008

Users reported some problems in http basic authentication support which have newly implemented specially for 1.3.0. So we did another quick release fixing the issue + some other minor issues.
Please try out the new release.

WSO2 Web Services Framework for PHP v1.3.2 Released

We are pleased to announce the release of WSO2 WSF/PHP 1.3.2.

WSO2 Web Services Framework for PHP (WSO2 WSF/PHP), is an open source,enterprise grade, PHP extension for providing and consuming Web Services in PHP. WSO2 WSF/PHP is a complete solution for building and deploying Web services and is the only PHP extension with the widest range of WS-* specification implementations. It's Key features include, secure services and clients with WS-Security support, binary attachments with MTOM, automatic WSDL generation (code first model),
WSDL mode for both services and clients (contract first model) and interoperability with .NET and J2EE.

You can download the release from: http://wso2.org/downloads/wsf/php

Project home page: http://wso2.org/projects/wsf/php

Key Features

  1. Client API to consume Web services

    • WSMessage class to handle message level options

    • WSClient class with both one way and two way service invocation support

    • Option of using functions in place of object oriented API with ws_request

  2. Service API to provide Web services

    • WSMessage class to handle message level options

    • WSService class with support for both one way and two way operations

    • Option of using functions in place of object oriented API with ws_reply

  3. Attachments with MTOM

    • Binary optimized

    • Non-optimized (Base64 binary)

  4. WS-Addressing

    • Version 1.0

    • Submission

  5. WS-Security

    • UsernameToken and Timestamp

    • Encryption

    • Signing

    • WS-SecurityPolicy based configuration

  6. WS-Reliable Messaging

    • Single channel two way reliable messaging

  7. WSDL Generation for Server Side

    • WSDL generation based on annotations and function signatures, and

      serving on ?wsdl or ?wsdl2 requests

  8. WSDL mode support for both client and server side

    • Write services and client based on a given WSDL

    • WS-Addressing and WS-SecurityPolicy is supported in WSDL mode

  9. REST Support

    • Expose a single service script both as SOAP and REST service

  10. Provide easy to use classes for common services

    • Consume some well known services such as Yahoo search and Flickr
      and Amazon services using predefined classes

  11. wsdl2php.php script. This script can generate PHP classes for services

    and clients for a given WSDL to be used with WSDL Mode .

Major Changes Since Last Release

  1. Added HTTP Authentication support in WSDL mode

  2. Fixed memory corruption in wsdl mode

Reporting Problems

Issues can be reported using the public JIRA available at:


Contact Us

Please subscribe to our user or developer mailing lists. For details on how to subscribe please visit: http://wso2.org/mail#wsfphp

We welcome your early feedback on this implementation.

Thank you for your interest in WSO2 WSF/PHP.

-- WSO2 WSF/PHP Team --