In this article by Malinda Kaushalye Kapuruge, he demonstrates how WSO2 WSF/PHP can be used to implement a typical business solution.
Applies To
| WSO2 WSF/PHP | 1.2.0 |
| Environment | Linux - Debian, Ubuntu, Fedora |
Table of Contents
- Background [0]
- In This Tutorial [0]
- The Scenario [0]
- Requirements Identification [0]
- WSO2 WSF/PHP as the Solution [0]
- WS-Security Features in WSO2 WSF/PHP [0]
- The implementation [0]
- Implementing the Client [0]
- Implementing the Service [0]
- Deploy the Service [0]
- Conclusion [0]
- References [0]
download [0] and extract the complete source code. Then open the store_client.php file.
The main class we will be using to implement our client is WSClient. We will create a new client object in the following manner.
$client = new WSClient(array("useWSA" => TRUE,
"useMTOM" => FALSE,
"policy" => $policy,
"securityToken" => $sec_token));
While creating the instance, we will pass certain parameters. In the above line we use WS-Addressing and do not need to send the image as a binary attachment. We would rather send the image as a base64 encoded attachment since we need the image too to be encrypted and signed. Then, we have two more parameters, policy and securityToken, that provides message-level security. In order to provide security, one needs to pass a security token as well as a policy in order to define the required security behavior.
- WSPolicy : Defines the security behavior. In other words, this defines whether a message needs to be encrypted and/or signed, tokens to be included and algorithms to be used etc.
- WSSecurityToken : Provides configuration parameters that are required to perform security operations. Such as certificates/keys, passwords etc.
So, we need to provide both these at the point of creating the client. Apart from this, we need to load the image and build the message. For this, we will create an instance of the class WSMessage.
$file = file_get_contents("./design.jpg"); /*Load the file*/
$requestMessage = new WSMessage($requestPayloadString,
array("to" => "http://localhost:9090/samples/security/store/manuf_service.php",
"action" => "http://www.back_packers.com/purchaseOrder",
"attachments" => array("myid1" => $file)));
Here, we provide the address of the service and the SOAP action to be set. As the last parameter we set file content loaded, as an attachment. There we will give an ID(myid1) to the content loaded, and later refer it from the payload or the SOAP body we build.
$requestPayloadString = <<<XML
<po:Order xmlns:po="http://www.back_packers.com/ws/purchaseorder">
<po:OrderId>po-98765</po:OrderId>
<po:Date></po:Date>
<po:Design>
<po:FileName>design.jpg</po:FileName>
<po:Image><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:myid1"></xop:Include></po:Image>
</po:Design>
</po:Order>
XML;
When everything is in place, all we have to do is to fire the message.
$responseMessage = $client->request($requestMessage);
this [0].
Download the demo [1]
Author
Malinda Kaushalye Kapuruge is a Senior Software Engineer, WSO2 Inc. kaushalye at wso2 dot com