PHP Web Services - Authentication Based on Client’s IP
Saturday, December 27, 2008
REST Vs SOAP
Saturday, December 20, 2008
Both REST ( Representational states transfer) and SOAP is widely adopted techniques for building distributed systems. REST is an architectural style for implementing systems on top of HTTP infrastructure. A large number of Specifications has been developed on top of SOAP and there are large number of SOAP stacks both open source and proprietary out there implementing large part of this WS* stack.
Both these d techniques have their advantages and drawbacks. Here are few of the advantages and disadvantages of each paradigm.
REST
Advantages
1. Based on few simple principles which are already in wide adoption on the Web itself
2. Can be implemented very quickly.
3. Ideal for providing simple API's to the users. (Eq Whether Services, Flicker, Yahoo REST services )
4. Amount of learning required to get started is minimum in comparison to SOAP
5. Has a very large following amount the scripting community
Disadvantages
1. If the system is a very large one, then designing based on REST could become a very complex task.
2. Implementing Security on a REST system is one major issues. Although HTTPS, and HTTP Authentication can be used, they only provide transport level security.
SOAP
Advantages
1. Well designed mature technology
2. Has been widely adopted in industry
3. Large number of SOAP stacks available to choose from.
4. Has support for Both Transport level and message level security which is a big advantage over REST.
5. Supports multiple protocol bindings ( Not just HTTP)
6. Ideal for implementing complex enterprise systems since the SOAP Stacks cater for security, reliability, transactions ect.
Disadvantages
1. Complex in comparison to REST
2. Big learning curve required
3. Difficult to debug a complex system
One great thing about using WSF/PHP is that it can support Both of these techniques simultaneously. However, if you are building a complex system which require security, I would always recommend the use of SOAP.
Data Services Best Practices
Thursday, December 18, 2008
Sending Encrypted Binary Messages With PHP Web Services
Sunday, December 14, 2008
PHP Data Services with PostgreSQL
Sunday, December 7, 2008
Using command line to debug your Web Service
Thursday, December 4, 2008
You can actually run your PHP Web Service on the command line. One may wonder what the use of doing that ?
The main use case is that, you can test your service, without having to write a client. It is specially useful, if your are following the code first approach. You can find the code for actually doing this in one of the WSF/PHP samples. It is in fact the simplest sample of all. The echo_service.php.
Lets have a look at how this becomes possible.
WSService->reply() function takes an optional string argument .
1. You can pass the actual XML string expected from the client to the reply function. Then, the service can be executed on the command line to see the actual executed output from an operation.
However, this would work only in cases where you using SOAP Body dispatching or WS-Addressing.
In SOAP Body dispatching case, the XML qualified name of the child element of soap body is used to identify the operation which should be invoked.
In case of WS-Addressing, the addressing action header is used.
2. Lets look at a code sample on implementing this. This is the echo_service.php sample that comes with WSF/PHP
<?php
$requestPayloadString = <<<XML
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header/>
<soapenv:Body>
<ns1:echoString xmlns:ns1="http://wso2.org/wsfphp/samples">
<text>Hello World!</text>
</ns1:echoString>
</soapenv:Body>
</soapenv:Envelope>
XML;function echoFunction($inMessage) {
$outMessage = new WSMessage($inMessage->str);
return $outMessage;
}$operations = array("echoString" => "echoFunction");
$service = new WSService(array("operations" => $operations));
$service->reply($requestPayloadString);?>
I have highlighted the important code segments. Note how the Expected soap envelope string is passed to the reply() function as an argument.
3. Now you can execute this service on the command line and get the result.
php echo_service.php
Now you should see the expected output soap envelope after invoking the echoString operation.
4. You can also generate the WSDL for the service on the command line as well. Simply set the reply function argument string to "wsdl" or "wsdl2".
$service->reply("wsdl");
5. Now you can re execute the service and get the wsdl for the service on the command line.
php echo_service.php
This is a very useful feature for debugging your hand coded services :).
Steps to Convert a SQL Query to a Data Service
Thursday, November 27, 2008
5 Facts About WS-Addressing Action in WSF/PHP
Wednesday, November 26, 2008
The Use of SOAP Action with WSF/PHP
Tuesday, November 25, 2008
Data Services - Databases For SOA
Sunday, November 23, 2008
WS-SecurityPolicy With PHP
Wednesday, November 19, 2008
Signing SOAP Headers In PHP Web Services
Tuesday, November 18, 2008
Detect Replay Attacks In to Your PHP Web Service
Monday, November 17, 2008
How to contribute to WSF/PHP project
Sunday, November 16, 2008
As an open source software development project, WSF/PHP always encourage users,developers to raise bugs, and post patches etc. Of course if you have any great idea related to WSF/PHP or some enhancement to WSF/PHP, you are most welcome to contribute.
Lets see how you can contribute to WSF/PHP project in various ways. If you encounter a bug, you can first check on the svn to see whether it is already fixed as well.
1. How do I provide a patch to WSF/PHP .
Step1.
WSF/PHP uses svn as its version control system. You can checkout the source code of WSF/PHP from the following URL.
https://wso2.org/repos/wso2/trunk/wsf/php/
On windows you can use Tortoise SVN to checkout the source code as follows.
Step 1.
Create a folder to which you will checkout the source code.
Step2. Check out the code
Now you can make any changes or additions, you would like to make.
Step 3.
Use create patch option in Tortoise svn to create a patch.
This should provide you with a patch file.
Step 4.
Go to WSO2 Jira project and select WSF/PHP project
Go to create new issue options and select WSO2 WSF/PHP from projects drop down menu. Then select the issue type
Now in this issue form, you can fill out information about the issue.
Next fill out the issue description, your testing environment, and attach the patch.
Now click create button to create the issue.
This way you can contribute to WSF/PHP project which is used by a large number of PHP Developers worldwide. Looking forward to your contributions.
RESTful URL Mapping in WSF/PHP
XML Schema Simple Types & How WSDL2PHP Convert Them To PHP
Thursday, November 13, 2008
WSF/PHP Test Cases Explained
Tuesday, November 11, 2008
Introduction to reliable messaging part 3
Monday, November 10, 2008
In this blog post, we will look at how you can send multiple application messages within a single sequence reliably using
WSClient API. For this purpose WSClient has an option named willContinueSequence. If you intend to send only a since application message within your reliable sequence, then you do not need to touch this option. However, when sending multiple application messages, you need to use it as follows.
1. When sending the first message, set willContinueSequence=TRUE in WSClient.
2. Send your application messages by using WSMessage object.
3. When you want to send the final application message to be sent within the reliable sequence, set the option lastMessage to true.
Here is a code example demonstrating this.
Step 1. First create an application message.
$requestPayloadString = <<<XML
<ns1:pingString xmlns:ns1="http://wso2.org/wsfphp/samples/reliable">
<text>Hello World!</text>
</ns1:pingString>
XML;
Step 2. Create a WSClient object with willContinueSequence option set to TRUE
$client = new WSClient(array( "reliable" => TRUE, "useWSA" => TRUE, "willContinueSequence" => TRUE));
Step 3. Create and Send WSMessage objects containing application messages.
$message = new WSMessage($requestPayloadString,
array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
"action" => http://wso2.org/wsfphp/samples/pingString));$client->send($message);
$message1 = new WSMessage($requestPayloadString,
array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
"action" => "http://wso2.org/wsfphp/samples/pingString"));$client->send($message1);
Step 4. When you want to send the last application message, set the option lastMessage to true in WSMessage object.
$message2 = new WSMessage($requestPayloadString,
array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
"action" => "http://wso2.org/wsfphp/samples/pingString",
"lastMessage" => TRUE));$client->send($message2);
Note that this is a ping service and hence the use of the method send in WSClient. You can similarly use request method as well.
Sending Custom SOAP Headers in PHP Web Services
Monday, November 3, 2008
Introduction to reliable messaging part 2
In my previous blog post, we had a look at a set of messages exchanged between a web services client and a server using WS-Reliable Messaging protocol. Today, we will explore the API available in WSF/PHP to achieve reliable messaging.
WS-Reliable messaging API in WSF/PHP is a simple an uncomplicated one. Lets go thorough each of the options available on WS-Client to achieve reliable messaging.
To enable WS-Reliable Messaging you need to use the "reliable" option in WS-Client. However, for WS-RM to work, it is mandatory to have WS-Addressing enabled. There for you need to enable WS-Addressing or at least define the "action" option in WS-Client. If the action is present, and "reliable" options is set to "true", WSF/PHP will automatically enables WS-Addressing and enables Reliable Messaging. So following options are valid on WS-Client to enable reliable messaging.
1.
oparray["action"] = "http://wso2.org/wso2-wsf-php";
oparray["reliable"]= TRUE;
client = new WSClient(oparray);
2.
oparray["action"] ="http://wso2.org/wso2-wsf-php"
oparray["reliable"]=1.1
In this option, we are telling WS-Client to use WS-RM version 1.1.
In my next blog post, we will explore other configuration options of WSClient and WS-Service
Sending And Handling Faults From PHP Web Service
Thursday, October 30, 2008
ScreenCast - How to Consume a Web Service Using WSF/PHP
Wednesday, October 29, 2008
WSF/PHP Services Performance test with WSDL Caching
Tuesday, October 28, 2008
Introduction to Reliable Messaging with WSF/PHP
Monday, October 27, 2008
With WSF/PHP you can add reliability to your web services integrations . Due to the nature of PHP, WSF/PHP supports only single channel reliable messaging. Single channel means you are using the same channel to transmit both the request and response.
When reliable messaging is used, in addition to the actual message being transmitted , there will be handshake interactions between the client and the service to make sure that the sent message is actually delivered to the service. In addition the , reliable messaging middleware make sure that if the receiver endpoint down, it will keep polling till the message is delivered etc.
Let see how you can implement a simple reliable messaging client using WSF/PHP.
These are the requirements.
1. You service endpoint should be able to handle single channel reliable messaging.
2.Then you need to enable addressing.
In RM, the communication happens using a sequence. The initial handshake is to build this sequence, and with a sequence , one or more application messages is transmitted. Once the messaging transmission is complete, the sequence is terminated.
So the messages exchanged in a single channel scenario is as follows. I am using the actual xml messages exchanged in the echo_client_rm.php sample that comes with WSF/PHP release here.
1. Client sending the CreateSequence Message to the service.
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://localhost/samples/reliable/echo_service_rm.php</wsa:To>
<wsa:Action>http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</wsa:Action>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:6dbfe9a0-304f-415e-91d1-49d2993bcf56</wsa:MessageID>
</soapenv:Header>
<soapenv:Body>
<wsrm:CreateSequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">
<wsrm:AcksTo xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">
<wsa:Address xmlns:wsa="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsrm:AcksTo>
<wsrm:Offer xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">
<wsrm:Identifier>df2ceab0-b04f-428a-bb94-0cfdcb0a524b</wsrm:Identifier>
</wsrm:Offer>
</wsrm:CreateSequence>
</soapenv:Body></soapenv:Envelope>
2. Service responding with a CreateSequenceResponse message.
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
<wsa:Action>http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequenceResponse</wsa:Action>
<wsa:From>
<wsa:Address>http://localhost/samples/reliable/echo_service_rm.php</wsa:Address>
</wsa:From>
<wsa:MessageID>urn:uuid:48020317-4e90-4b79-97ae-2fa9b78c544b</wsa:MessageID>
<wsa:RelatesTo wsa:RelationshipType="http://www.w3.org/2005/08/addressing/reply" xmlns:wsa="http://www.w3.org/2005/08/addressing">urn:uuid:6dbfe9a0-304f-415e-91d1-49d2993bcf56</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
<wsrm:CreateSequenceResponse xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">
<wsrm:Identifier>8883a8b9-9f6a-4e40-b78a-872a2708a4b3</wsrm:Identifier>
<wsrm:Accept xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">
<wsrm:AcksTo xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">
<wsa:Address xmlns:wsa="http://www.w3.org/2005/08/addressing">http://localhost/samples/reliable/echo_service_rm.php</wsa:Address>
</wsrm:AcksTo>
</wsrm:Accept>
</wsrm:CreateSequenceResponse>
</soapenv:Body></soapenv:Envelope>
3. Client sending the sequence Message
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsrm:Sequence soapenv:mustUnderstand="1" xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<wsrm:Identifier>8883a8b9-9f6a-4e40-b78a-872a2708a4b3</wsrm:Identifier>
<wsrm:MessageNumber xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">1</wsrm:MessageNumber>
<wsrm:LastMessage xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"/>
</wsrm:Sequence>
<wsa:To>http://localhost/samples/reliable/echo_service_rm.php</wsa:To>
<wsa:Action>http://wso2.org/wsfphp/samples/echoString</wsa:Action>
<wsa:MessageID>urn:uuid:8e275ba1-b34b-49c1-92fa-ce86782ff803</wsa:MessageID>
</soapenv:Header>
<soapenv:Body>
<ns1:echoString xmlns:ns1="http://wso2.org/wsfphp/samples">
<text>Hello World!</text>
</ns1:echoString>
</soapenv:Body></soapenv:Envelope>
4. Service Responding with a SequenceAcknowledgement message. Since this is an echo service, in addition to sending the acknowledgement, the service also initiate a sequence here and send the application message back to the client.
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsrm:Sequence soapenv:mustUnderstand="1" xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<wsrm:Identifier>df2ceab0-b04f-428a-bb94-0cfdcb0a524b</wsrm:Identifier>
<wsrm:MessageNumber xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">1</wsrm:MessageNumber>
<wsrm:LastMessage xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"/>
</wsrm:Sequence>
<wsrm:SequenceAcknowledgement soapenv:mustUnderstand="0" xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<wsrm:Identifier>8883a8b9-9f6a-4e40-b78a-872a2708a4b3</wsrm:Identifier>
<wsrm:AcknowledgementRange Lower="1" Upper="1"/>
</wsrm:SequenceAcknowledgement>
<wsa:Action>http://wso2.org/wsfphp/samples/echoString</wsa:Action>
<wsa:ReplyTo>
<wsa:Address>http://localhost/samples/reliable/echo_service_rm.php</wsa:Address>
</wsa:ReplyTo>
<wsa:From>
<wsa:Address>http://localhost/samples/reliable/echo_service_rm.php</wsa:Address>
</wsa:From>
<wsa:MessageID>urn:uuid:307e881d-8ac7-4cb4-8acf-0eb04831707f</wsa:MessageID>
<wsa:RelatesTo wsa:RelationshipType="http://www.w3.org/2005/08/addressing/reply" xmlns:wsa="http://www.w3.org/2005/08/addressing">urn:uuid:8e275ba1-b34b-49c1-92fa-ce86782ff803</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
<ns1:echoString xmlns:ns1="http://wso2.org/wsfphp/samples">
<text>Hello World!</text>
</ns1:echoString>
</soapenv:Body></soapenv:Envelope>
5. Client send the SequenceAcknowledgement message to the service.
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsrm:SequenceAcknowledgement soapenv:mustUnderstand="0" xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<wsrm:Identifier>df2ceab0-b04f-428a-bb94-0cfdcb0a524b</wsrm:Identifier>
<wsrm:AcknowledgementRange Lower="1" Upper="1"/>
</wsrm:SequenceAcknowledgement>
<wsa:To>http://localhost/samples/reliable/echo_service_rm.php</wsa:To>
<wsa:Action>http://schemas.xmlsoap.org/ws/2005/02/rm/SequenceAcknowledgement</wsa:Action>
<wsa:MessageID>urn:uuid:3b2b7a50-f962-4027-b240-5eea57142df1</wsa:MessageID>
</soapenv:Header>
<soapenv:Body/></soapenv:Envelope>
6. Now the service sends back a TerminateSequence Message.
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence</wsa:Action>
<wsa:MessageID>urn:uuid:6e8178c6-a566-4010-a77e-d05af67ad21a</wsa:MessageID>
</soapenv:Header>
<soapenv:Body>
<wsrm:TerminateSequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm">
<wsrm:Identifier>df2ceab0-b04f-428a-bb94-0cfdcb0a524b</wsrm:Identifier>
</wsrm:TerminateSequence>
</soapenv:Body></soapenv:Envelope>
Similarly the client and service exchanges TermianteSequenceResponse messages as well.
I am sure, now you have some understanding on what actually happens when you try to send a soap message reliably from one endpoint to another. In my next blog post, we will discuss how to configure WSF/PHP to implement reliable clients and services.
WSF/PHP WSDL Mode - Handling XML Schema Arrays
Saturday, October 25, 2008
How to learn the SOAP version by looking at a soap message
Thursday, October 23, 2008
I have seen number of questions on the forums on issues related to this. So here are some tips on getting to know spec versions by looking at a soap message with http headers.
Here is an example SOAP1.1 one message.
POST /samples/echo_service.php HTTP/1.1
User-Agent: Axis2C/1.5.0
SOAPAction: ""
Content-Length: 242
Content-Type: text/xml;charset=UTF-8
Host: 127.0.0.1:8080<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns1:echoString xmlns:ns1="http://wso2.org/wsfphp/samples">
<text>Hello World!</text>
</ns1:echoString>
</soapenv:Body></soapenv:Envelope>
I have marked highlighted the important points.
In SOAP1.1
1. Content-Type will be "text/xml".
2. SOAPAction is a separate HTTP Header
3. SOAP envelope namespace uri is "http://schemas.xmlsoap.org/soap/envelope/"
Here is a SOAP 1.2 message.
POST /samples/echo_service.php HTTP/1.1
User-Agent: Axis2C/1.5.0
Content-Length: 240
Content-Type: application/soap+xml;charset=UTF-8;action="urn:echoString"
Host: 127.0.0.1:8080<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header/>
<soapenv:Body>
<ns1:echoString xmlns:ns1="http://wso2.org/wsfphp/samples">
<text>Hello World!</text>
</ns1:echoString>
</soapenv:Body></soapenv:Envelope>
In SOAP 1.2
1. Content-Type header is "application/soap+xml"
2. SOAP envelope namespace uri is "http://www.w3.org/2003/05/soap-envelope".
3. soap action header will go in the Content-type header as 'action'
Depending on you requirement, you can switch between between soap versions by passing the option "useSOAP"=>1.1 or "useSOAP"=>1.2.
For a service in WSF/PHP, the soap version does not matter since the framework is capable of handling either type.
WSDL Generation From PHP - Using Different Names in WSDL and PHP Code
How to Get WS-Security working without WS-Addressing in WSF/PHP
Tuesday, October 21, 2008
Usually, most security scenarios use WS-Addressing. But there are scenarios that uses security without WS-Addressing. Due to configuration file settings, WSF/PHP works with WS-Security only when WS-Addressing is also used. However, by doing some simple changes to a couple of Xml files, you can get WSF/PHP to support some security scenario's that does not use WS-Addressing.
Here is what you need to do.
1. Step One.
Open the axis2.xml file found in was_c directory. In it, change in inflow by adding another phase named Security as follows.
<phaseOrder type="inflow"> - <!-- System pre defined phases -->
<phase name="Transport" />
<phase name="PreDispatch" />
<phase name="Dispatch" />
<phase name="PostDispatch" />
<!-- End system pre defined phases -->
<!-- After PostDispatch phase, module or service author can add any phase as required -->
<!-- User defined phases could be added here -->
<phase name="Security" />
<phase name="Rahas" />
<phase name="RMPhase" />
</phaseOrder>
I have highlighted the line added in red.
2. Step two
Open the module.xml file found in wsf_c/modules/rampart/ directory and change the inflow elements phase name attribute from "PreDispatch" to "Security" as follows.
<inflow>
<handler name="RampartInHandler" class="mod_rampart">
<order phase="Security"/>
</handler>
</inflow>
Again, I have highlighted the change.
That's all you need to do to get WS-Security to work without using WS-Addressing.
Note that,for this to work, you will have to have either SOAPAction or an element that matches the operation name in Soap Body. Of course there are some WS-Security scenarios that cannot work without WS-Addressing.
Tips on avoiding common WSF/PHP installation issues.
Here are some useful tips avoid common fit falls in installing WSF/PHP.
1. Often users complain that When the run the sample clients, they see the response
"ERROR, WS Client not Found'.
This is often due not setting the wsf.home entry correctly. Make sure to set wsf.home directory to point to wsf_c directory if your are on windows or using pecl installation with WSF/C library installed separately.
Another reason for this is not adding the wsf_c/lib directory to PATH environment variable if you are on a windows system.
2. WSDL Generation and WSDL mode does not work.
This is often due to you not having added the scripts folder found inside the wsfphp distribution to the php.ini's include path entry.
3. Compile WSF/PHP using source gives errors.
This could be due to two issues.
1. First you need to have installed the dev-libraries of PHP, Libxml2 and OpenSSL.
2. Incorrect configure options provided to the configure script.
Often you do not need to provide any options to the configure script since it is written to work as
./configure, make , make install sequence.
RESTful PHP Web Services - Book
My book on RESTful PHP Web Services is now available for download from Packt Publishing.
What you will learn from this book
- Basic concepts of REST architecture
- Consuming public REST-style services from your PHP applications
- Consuming RESTful web services, such as those from leading APIs such as Flickr, and Yahoo Web Search
- Making your own PHP applications accessible to other applications through a RESTful API
- REST support in the popular Zend framework
- Debugging RESTful services and clients
- A case study of designing a RESTful PHP service from the ground up, and designing clients to consume the service
It is also note worthy that there is a dedicated appendix chapter in this book on using WSO2 WSF/PHP.
Coding Schema Inheritance in PHP
How to install WSF/PHP in Debian/Ubuntuu Systems from scratch
Monday, October 20, 2008
How to use Attachment Caching with WSF/PHP
WSF/PHP 2.0.0 has the support for caching attachments ( writing to a file ). This effectively reduces the amount of memory used when sending and receiving attachments and its specially useful, if your application requires to send or receiving a very large file in the scale of megabytes.
WSF/PHP adds two php.ini entries in order to allow attachment caching.
1. wsf.attachment_cache_dir
2.wsf.enable_attachment_caching
wsf.attachment_cache dir is the location where the received attachments will be saved.
wsf.enable_attachment_caching option enables attachment caching.
By default, attachment caching can be done only for attachments larger than 1 MB.
Lets see a code sample on how to use this. This is a simple php service, which reads a binary file and send it to the client as an MTOM attachment.
<?php
ini_set("wsf.enable_attachment_caching", 1);
ini_set("wsf.attachment_cache_dir","E:\\");
function sendAttachment($msg)
{
$responsePayloadString = <<<XML
<ns1:download xmlns:ns1="http://php.axis2.org/samples/mtom">
<ns1:fileName>test.jpg</ns1:fileName>
<ns1:image xmlmime:contentType="image/jpeg" xmlns:xmlmime="http://www.w3.org/2004/06/xmlmime">
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:myid1"></xop:Include>
</ns1:image>
</ns1:download>
XML;
$responseMessage = new WSMessage($responsePayloadString,
array( "attachments" => array("myid1" => "../resources/large_image.jpg")));
return $responseMessage;
}
$operations = array("download" => "sendAttachment");
$service = new WSService(array("operations" => $operations, "useMTOM" => TRUE));
$service->reply();
?>
Now in above code, I have highlighted the important code pieces.
1. The php ini settings at the top of the code where the attachment_cache_dir is set and attachment caching is enabled.
ini_set("wsf.enable_attachment_caching", 1);
ini_set("wsf.attachment_cache_dir","E:\\");
2. Setting of a fake content id to which the actual attachment is assigned.
href="cid:myid1"
3. Instead of setting binary attachment as an string in the attachment array, we should set the actual path to the file.
array("myid1" => "../resources/large_image.jpg")
Thats all you need to do to get attachment caching working. The same technique can be used for the client as well. It will be consuming lot less amount of memory.
Demo on Consuming Flickr, Yahoo and Amazon Search Web Services
Sunday, October 19, 2008
DEMO on a SOAP and REST Client with PHP
Friday, October 17, 2008
Using Open SSL to manage Your Keys
When it comes to WS-Security, for most of the operations, you will need to have either a certificate, or a key or both. Or you will need to provide a key store. WSF/PHP uses Open SSL library underneath to build WS-Security. Therefore knowing how to work with Open SSL can be really useful.
Lets go through some of the important commands you need to know to effectively get work done using Open SSL.
1. Generating a Certificate using Open SSL.
When generating a certificate, you have to decide whether you want an encrypted key or not. If you select the encrypted key option, your key will be protected by a passphrase. This adds more security to your key since it will be difficult for some one stealing your key to use it. How ever you will need to provide this passphrase, every time you use the key. A self signed certificate is used to sign other certificates.
Use the command
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
These options tells openssl to generate key length 1024 bits which is valid for 365 days and put both private key and certificate to a file named mycert.pem.
Now you will be prompt to answer a number of questions and then OpenSSL will generate you a self signed certificate. Now if you open the mycert.pem you will see both the private key and the certificate stored there. If you remove the -nodes option, you will be asked to provide a passphrase.
2. Generating a private key and a matching public key using RSA algorithm.
It is sometimes necessary to generate the private key and public keys separately.
You can generate an RSA public key using the option genrsa.
openssl genrsa -out mykey.pem 2048
This generates a rsa private key with 2048 bits.
Using rsa option, you can get the corresponding public key.
openssl rsa -in mykey.pem -pubout
3. Creating a PKCS12 Keystore and adding keys to it.
openssl pkcs12 -export -out mycert.pfx -in mycert.pem -name "My Keystore"
This command generates a PKCS12 key store by exporting the above generated certificate. Here you will be asked for a passphrase as well.
XML Signature
Thursday, October 16, 2008
XML signature is used in WS-Security to sign SOAP messages. Here is a blog post describing XML Signature.
Installing WSF / PHP with Wampserver Article in French
Demo on Providing PHP Web Service with Username Token
Fetching song lyrics
How to build PHP from source
Wednesday, October 15, 2008
It is an interesting thing to build PHP source on a Windows Platform. It is extremely useful to build PHP source with various options specially if you wish to write a PHP extension. Here are some interesting tips on how you can build PHP source on a windows platform.
First you need to download the following dependencies.
1. You need to have visual studio or windows platform SDK install on you machine in order to have the required compiler and build tools.
2. You need to download the PHP build dependencies.
These include
1. Binary tools - Essential
2. Libxml2 - Optional
3. Iconv Optional
4. Zlib - Optional
5. Apache or other web server that you intend to build modules.
6. PHP Source - Essential
7. bindlib-cvs-vc8 - Essential
Most of these tools can be downloaded from here.
Once you have downloaded these tools, you are ready to build PHP from source.
First unzip all these tools to a directory.
Next, open visual studio command prompt and add binary-tools\bin directory to the path.
Now, go to the PHP source extract directory and type,
buildconf.bat
Then run
cscript /nologo configure.js --help
You will see a large number of options as shown above.
Next open the config.nice.bat file located in the php source directory and add necessary configure options for your build
Here are my configuration options
cscript /nologo configure.js "--with-extra-includes=E:\phpbuild\bindlib-cvs-vc8\include;E:\Apache22\include;E:\phpbuild\iconv-1.9.2.win32\include;E:\phpbuild\libxml2-2.6.30.win32\include;E:\phpbuild\zlib-1.2.3.win32\include"
"--with-extra-libs=E:\phpbuild\iconv-1.9.2.win32\lib;E:\phpbuild\libxml2-2.6.30.win32\lib;E:\phpbuild\zlib-1.2.3.win32\lib;E:\Apache22\lib;E:\phpbuild\bindlib-cvs-vc8\lib"
"--enable-debug" "--enable-apache2-2handler" %*
Here I am using the option --with-extra-includes to specify the include paths of the dependency libraries. Similarly --with-extra-libs is used to specify the library path.
I use the options --enable-debug to make it a debug build.
Now run config.nice.bat file.
Next you can try nmake on the command line and it will build the PHP Source.
Bridging the Gap Between Enterprise and Web Applications
WSF/PHP allows web applications to integrate with enterprise applications using the Web Services. Here is a blog post talks about Bridging the Gap Between Enterprise and Web Applications using WSF/PHP.
Writing a Simple REST and SOAP Service With PHP
Friday, October 10, 2008
WSClient WSDL Mode With Array Based API
Wednesday, October 8, 2008
Test your SSL SOAP Client with an Online Service
Tuesday, October 7, 2008
Invoking WSF/PHP Web Services Through Proxy
Monday, October 6, 2008
Data Services with SQLite in PHP
Sunday, October 5, 2008
MSSQL(Microsoft SQL) Data Services In PHP
Saturday, October 4, 2008
XPath in SimpleXML
Wednesday, October 1, 2008
Online Tools for PHP Web Services Developers
Sunday, September 28, 2008
REST Framework for PHP
Saturday, September 27, 2008
I have been blogging about WSF/PHP 2.0 being a comprehensive REST framework. Now it is available for you to download.
If you want to design services from scratch, WSF/PHP would be a very good choice, because it provides a natural mapping form design to implementation.
Also, given the fact that this is an extension written in C, it would also provide you with better performance, compared to other REST frameworks purely written in PHP.
RESTful CRUD Data Services Demo
Http Authentication for SOPA Messages in PHP - 2 Minutes Introduction
Thursday, September 25, 2008
But if you want to do Http Basic Authentication you can still use WSF/PHP as your client. Here is a blog How you send Basic Authentication information with your SOAP message in PHP. Note that here authentication is handled in trasport layer. So this approach is only valid if you are using HTTP transport which is the most common transport to use in web services.
Authenticate using Username Token from PHP - 2 Minutes Introduction
Tuesday, September 23, 2008
The blog "Authenticate using Username Token from PHP - 2 Minutes Introduction" give you quick tutorial how you can implement this in PHP using WSF/PHP.
Webinar - Introducing Enterprise Web services with WSO2 WSF/PHP 2.0.0
Monday, September 22, 2008
You can register from this link. Note that you don't need any registration fees.
Send Binary With Web Services in PHP - 2 Minutes Introduction
WSDL2PHP 2 Minutes Introduction
WSDL2PHP is the tool to do the same in PHP. Have a look at this tutorial to learn how to use it in your application.
SOA Way of Writing PHP
Integrating PHP CMS systems with other applications
Friday, September 19, 2008
Here are some interesting thoughts on how to integrate PHP CMS system with other enterprise applications.
Video - WSF/PHP in Enterprise Applications
Thursday, September 18, 2008
Do REST in PHP - PHP RESTful Data Services
Check out this demo about 'RESTful School' and see how can map unique urls to each piece of data you have.
Check "Do REST in PHP - PHP RESTful Data Services" for a guideline of the demo.
Simplest Approach to Enterprise Grade Web Services
Are you bored with spending lots of time and money writing web services? Are you bored dealing with complex API's provided by Java and .Net based web services platforms? These are the things that we worry every day when we want to bring our software solutions to the outside world as standard services.
Now we are moving to a new era of Web Services with WSF/PHP as a platform for developing enterprise grade web services with the minimal effort from the programmer. Now lets look at what are tools required to build a enterprise solution using Web Services.
Obviously the first requirement is the ability to create and consume web services. WSF/PHP has this capability in the simplest form possible. You can read more about how to create and consume web services in the online documentation of WSF/PHP. This includes the creating services from WSDL and creating services manually. Also for the client side you have the option of building the client manually as well as using the WSDL.
But creating and consuming web services is only a small part of your overall solution. At the beginning you may think that "who cares about security". But when your application grows I can guarantee you will feel the need for security. But there is nothing to worry as WSF/PHP can cater for all your web services security requirements. As the service writer you don't have to worry about the details of complex WS-Security mechanisms underneath. That is the best part of the story.
If you want more than the delivery guarantees of TCP protocol and want the message level reliability, WSF/PHP can use the WS-ReliableMessaging delivery guarantees.
Also WSF/PHP comes with a nice way to convert all your data to web services very easily. Now you don't have to write services manually to expose your existing data to the world. WSF/PHP Data services can do this for you in very few easy steps.
WSF/PHP comes with two very distinctive features that you won't find in any other web services platform. Enterprise readiness and ease of use are these two distinctive features. So if you want to develop enterprise grade web services with the minimal effort try WSF/PHP and feel the difference.
Debugging PHP Web Services
I wrote a blog on some of the tips of how to debug web service client and services. It would be useful to you if you are getting started with WSF/PHP.
Installing WSF/PHP in windows
Tuesday, September 16, 2008
WSF/PHP is a new era for web services with its ease of use and all the cool features. To unveil this new world of web services you need to get started in some way. I have chosen the hard way and decided to build it from the scratch. I have blogged about my first experience with WSF/PHP. In this I have explained how to build and configure WSF/PHP under windows.
PHP Data Services With WS-Security
Read my blog post on Data Services with WS-Security where I used an online DEMO application to demonstrate the use of WS-Security in Data Services.
Implementing REST Client and Services Using WSF/PHP
Monday, September 15, 2008
WSF/PHP 2.0.0 supports implementing REST Services and clients using HTTP Methods POST,GET,DELET, and PUT. It addition, it allows custom URL mappings for service operations.
You can find more details on implementing REST client and Services using WSF/PHP here.
Code First Approach of Developing Services with WSF/PHP 2.0
I have blogged about existing features + new features avaialble in the WSF/PHP supporting the code first approach of developing services. If you prefer this approach you will find this post really helpful.
Only PHP Library for Creating Both SOAP and REST Services
WSO2, the open source SOA company, today announced the availability of the WSO2 Web Services Framework for PHP (WSF/PHP) 2.0. WSF/PHP is the industry's only PHP scripting language library that enables developers to create and consume both SOAP and REST Web services -- with the security and reliability required for an enterprise service-oriented architecture (SOA).
WSF/PHP 2.0 adds significantly expanded REST functionality, new Data Services, greater interoperability, and extended security. With WSF/PHP 2.0, developers now have a comprehensive framework for deploying PHP services that meet the strict enterprise SOA standards implemented by corporations and governments worldwide.
WSF/PHP 2.0 is part of the WSO2 family of Web Services Framework (WSF) products designed to support enterprises' heterogeneous SOAs. Other WSO2 WSF products include WSF/Ruby, WSF/Perl, WSF/Java, WSF/JavaScript, and WSF/Spring. With the WSF family, enterprises' diverse developer communities have the functionality they need to create Web services in their language of choice.
"WSO2 exists to enable heterogeneous SOAs, and WSF/PHP 2.0 is an important part of that mission. Through WSF/PHP 2.0, enterprises can tap an expansive community of PHP developers by giving them the first comprehensive framework for easily creating both SOAP and REST services," said Dr. Sanjiva Weerawarana, CEO of WSO2. "With our new Data Services and expanded interoperability, WSF/PHP 2.0 also provides a critical bridge between tens of thousands of PHP Web applications and the many enterprise data sources, applications and services driving today's enterprises."
WSF/PHP 2.0 Development, Interoperability and Security Enhancements
With full support for REST, SOAP, and WS-* specifications, WSF/PHP lets a single service be exposed both as a SOAP-style and as a REST-style service using a simple PHP-friendly programming model. WSF/PHP 1.0 provided a REST API along with support for SOAP 1.1 and 1.2, WSDL 1.1 and 2.0, and SOAP Message Transmission Optimization Mechanism (MTOM). WSF/PHP 2.0 adds a comprehensive REST framework featuring custom Uniform Resource Identifier (URI) mapping -- making it easy and intuitive to map a REST API into PHP when creating a Web service.
WSF/PHP 2.0 facilitates Web service creation for the large majority of PHP Web applications that rely on databases. The new WSF/PHP Data Services solution lets developers take data in LAMP(1), WAMP(2), and other PHP-based systems and expose it as a Web service with full WS-* support. Key features include a dbs2php converter tool, and support for multiple database engines, nested queries, and WSDL generation.
Extended interoperability in WSF/PHP 2.0 makes it easier for developers to seamlessly integrate PHP applications with those based on other enterprise platforms. WSF/PHP 2.0 offers much stronger support for the latest WS-* standards, as well as increased testing against Microsoft .NET, the WSO2 WSAS, Axis2/Java, and other J2EE implementations.
WSF/PHP enterprise security and reliability includes the support
for WS-Security, WS-SecurityPolicy, and WS-ReliableMessaging available
with WSF/PHP 1.0. Version 2.0 of WSF/PHP adds capabilities in four
areas.
-- Replay detection tracks whether a message is fresh or has been
previously sent, preventing replay attacks that can lead to
denial of service.
-- WS-Trust for issuing, renewing, and validating security tokens
ensures trusted relationships.
-- WS-SecureConversation support allows a series of messages (a
conversation) to be protected by a single session key,
improving efficiency of the operation.
-- Support for the Public Key Cryptography Standards (PKCS) makes
it possible for services written in WSF/PHP to handle multiple
client x509 certificates simultaneously, further improving
efficiency.
Other development and performance enhancements in WSF/PHP 2.0 include:
-- Increased WSDL support includes tools, such as wsdl2php for
contract-first development of services and clients; the
ability to generate WSDLs for WSF/PHP Web services scripts;
and proven support for a range of WSDL styles, including
support for advanced schemas such as extensions and
restrictions.
-- Policy-driven design provides users with a maximum level of
control by allowing developers to configure the behavior of
services using policies.
-- Binary data capability gives users a choice between sending
and receiving binary data as attachments using either MTOM or
a SOAP message with attachment (SwA). MTOM in version 2.0 has
been optimized through caching, enhancing performance.
-- Expanded deployment models for WSF/PHP 2.0 include several
platforms -- notably Linux, Windows, and Solaris -- as well as
seamless integration with Apache and Microsoft Internet
Information Services (IIS) Web servers.
-- Enhanced stability to ensure high availability and
reliability.
Zend Core Support Featured at ZendCon
With version 2.0, WSF/PHP has been tested and proven to run with Zend Core, Zend's tested, certified and supported version of PHP, which has been widely adopted by enterprises for their production PHP environments. WSF/PHP 2.0 is being launched in conjunction with ZendCon 2008; the Zend/PHP conference runs September 15-18, at the Santa Clara Convention Center in Santa Clara, CA. WSO2 will demonstrate WSF/PHP 2.0 at the Microsoft ZendCon booth.
"Zend and WSO2 are mutually dedicated to serving the diverse needs of PHP developers with world-class open-source software for implementing Web services," said Andi Gutmans, CTO and co-founder at Zend Technologies. "By bringing support for both enterprise-oriented WS-* and REST Web services to our managed PHP production environment, WSO2 joins us in empowering the developers supporting more than 20 million PHP websites with unprecedented flexibility for delivering enterprise-class Web services."
WSF/PHP 2.0 Webinar
WSO2 will present a free webinar, "Introducing Enterprise Web Services with WSO2 WSF/PHP 2.0," which will review how to take advantage of the new REST functionality and WSF/PHP Data Services support. The webinar will run from 9:00-10:00 a.m. Pacific on Tuesday, September 23, 2008. Presenting the webinar will be Selvaratnam Uthaiyashankar, a WSO2 software architect and lead developer of the WSO2 Web Services Frameworks. For more information, visit: http://wso2.com/about/news/wsf-php-sep-08-webinar/.
Availability and Support
The WSO2 Web Services Framework for PHP 2.0 is available for download today. As a fully open source solution released under the Apache License 2.0, it does not carry any software licensing or subscription fees. WSO2 offers a range of service and support options for WSF/PHP 2.0. These include support subscriptions, training, consulting, custom development and development support. For information on service and support packages, visit http://wso2.com.
About WSO2
WSO2 is the open source SOA company founded by pioneers in Web services and the Apache Software Foundation Web services community. The company delivers the only tightly integrated, entirely open source middleware stack that is optimized for SOA. The WSO2 products address the core components of SOAs: service creation, connection, composition and governance. The company is backed by Intel Capital and maintains operations in the United States, United Kingdom and Sri Lanka. For more information, visit http://wso2.com.
(1)LAMP: open source Web platform consisting of Linux, Apache, MySQL, and PHP
(2)WAMP: Web server package containing Windows, Apache, MySQL, and PHP
Trademarks and registered trademarks are the properties of their respective owners.
Source: WSO2
WSO2 Web Services Framework for PHP v2.0.0 Released
Friday, September 12, 2008
WSO2 WSF/PHP version 2.0.0 was released today. It comes with a lot of new features. In addition to the that many bug fixes have been done since the previous release.
Following are some of the key features and changes for this release extracted from the release note.
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
* WS-Secure Conversation
6. WS-Reliable Messaging
* Single channel one way and 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
* MTOM is now supported with 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 .
12. Data Services API
PHP Data Services API that enables exposing database queries as web services.
Major Changes Since Last Release
================================
* Added PKCS12 Keystore Support
* Added Secure Conversation Support
* Added Replay Detection Support
* Contract First Web Services support for MTOM
* SWA ( Soap With Attachments ) Support added
* MTOM Attachment caching support added
* HTTP Chunking support added
* REST API Improved to support HTTP verbs GET,DELETE,PUT and POST
* New PHP Data Services Solution
* WS-RM 1.1 added
* Many Bug Fixes
As you can see, A lot of new features have been added since that last release. It is a feature complete and therefore we are calling it version 2.0.0.
We welcome you to try out this latest release of WSF/PHP.
Developing WSF/PHP Webservices With Contract First Approach - 2 Minutes Introduction
Monday, September 8, 2008
PHP DataServices 2 Minutes Introduction
Saturday, September 6, 2008
WSF/PHP WSDL Generation 2 Minutes Introduction
Friday, September 5, 2008
WSF/PHP Articles and Tutorials
Monday, September 1, 2008
Here are some of the tutorials and articles written about WSF/PHP.
Blog from WSO2 WSAS Developers
Sunday, August 24, 2008
Howto Build Custom SOAP Headers in WSDL Using Axis2/C and WSF/PHP
Thursday, August 21, 2008
Next WSF/PHP Release is Almost Ready
Tuesday, August 19, 2008
We are almost done. Today, I had a look into the issue tracker, and there are only about four issues pending. That is covering lots of ground.
We should have the next WSF/PHP pack released by mid of next month.
Send Binary in SOAP with WSF/PHP 1.3.2
Short note for Web Services Security API in WSF/PHP 1.3.2
Sunday, August 17, 2008
REST Frameworks for PHP
Zend Framework has client and server classes for REST. WSO2 WSF/PHP too has comprehensive support for REST, both client and services.
If your requirements are simple and you are just starting to use REST services, Zend Framework would be a good choice to start with. But if you are going form design to implementation and your application is of enterprise grade, then you have to consider WSO2 WSF/PHP. WSF/PHP is designed in such a manner that you can map your resource design, along with HTTP verb mapping and custom URI mapping to business operations with minimal effort.
PHP Data Services - Integration to next level
Saturday, August 16, 2008
Related to my yesterday's post on integration, have a look at this post, to get an understanding on getting data as Web services to really work in the real world.
The right way to Integrate
Friday, August 15, 2008
Do you integrate you PHP application with other applications out there? Is your portal running with PHP and you leverage other third party applications to make your PHP application rich? And what are the technologies you use there?
Web services has been used for some time now to solve integration problems, and PHP can use the same technologies. Most application, including Software as a Service (SaS) applications provide Web services APIs, both SOAP and REST. And WSF/PHP form WSO2 provide a very strong set of APIs for this.
WSO2 itself has an array of PHP based Web applications. The wso2.com corporate Web site, wso2.org developer portal web site as well as an array of other applications that are internal but are integrated to the .com and .org site used an array of PHP applications. And they leverage Web services, and WSF/PHP when it comes to integrate across the various applications. As an example we talks to Jira based support system using Web services API and integrate that to Drupal based developer sites user accounts.
So, not only that WSO2 develop these great products and contribute those to the community, but WSO2 itself use them in production. You can too...
Encrypt and Sign your SOAP messages in PHP
Thursday, August 14, 2008
Make your Wordpress Blog a Web Service in Few Steps
Sunday, August 10, 2008
It doesn't matter what you have is Drupal, Wordpress or Joomla, You can still follow this guide and understand the concept and use of the DataService Library. Without doubt it will assist you to create a web serivce from your existing database strcture without much effort.