Showing posts with label WSF/PHP. Show all posts
Showing posts with label WSF/PHP. Show all posts

Sunday, February 17, 2008

Important things about WSF/PHP

In this blog entry Dinesh is talking about 5 important things about WSF/PHP. They are,

1. Open source Apache license
2. WS-* suppoort
3 Attachment capability
4 REST support
5. Interoperability

I like to add another thing. That is the various types of distributions WSF/PHP supports. Select the most suitable distribution from WSF/PHP dpwnloads page.

Monday, January 28, 2008

What is more flexible ?

Here is a Hello world Service with PHP SOAP extension , NuSOAP and WSF/PHP . Those are the 3 most popular PHP Web Services framework. So which is more flexible.

Monday, January 21, 2008

Why We need a Timestamp in a SOAP message

A common concern in message-oriented systems relates to the timeliness of data. If the data is too old, it may get thrown out. If two contradicting messages arrive, the related timestamps may be used to decide which message gets executed and which one is ignored. To handle the time-related issues that showed up in WS-Security the wsu:Timestamp element, along with a few helper elements, was defined.

By knowing the creation and expiration time, a receiver can decide if the data is new enough for its own use or if the data has become so stale that the message should be discarded. Following elements are used in a Timestamp.

wsu:Created: Contains the time that the message was created.
wsu:Expires: Set by a sender or intermediary, this identifies when the message expires.

Adding a timestamp to your SOAP message using Web Services framework for PHP is really easy.You only need to add following lines to your PHP script.

/*sec array is the array in which you specify security options*/

$sec_array = array("includeTimeStamp" => TRUE );

/*The valid time period of the message in seconds.*/
$sec_token = new WSSecurityToken(array("ttl" => 300));

Saturday, January 19, 2008

WS-Addressing with WSF/PHP

Web Services addressing is one of the fundamental specifications which drives Web Services platform. There are lot of reasons why you need Web Services Addressing. For a detailed description see this.

WSO2 WSF/PHP fully support WS-Addressing. It inherits this from Axis2/C Web Service engine. Adding Addressing support in WSF/PHP is really simple.

You only need to add following lines to your PHP script when you are invoking a Web Service.

Assuming some one want to set Addressing action and endpoint uri using addressing. Then first add the following.

$reqMessage = new WSMessage($requestPayloadString,
array( "to" => "http://localhost/samples/echo_service_addr.php",
"action" => "http://php.axis2.org/samples/echoString"));

Then enable WS-Addressing.

$client = new WSClient(array("useWSA" => TRUE));

Similarly you can set FaulTto, ReplyTo and other addressing parameters as well.

Wednesday, January 16, 2008

WSF/PHP interop with .net

WSF/PHP has passed many interop testing. Specially with .net web services and Axis2 web services. Specially WSF/PHP security stuff and MTOM stuff are well tested in most of .net interop testing events. For more details on this see WSF/PHP Road Map.

Monday, January 14, 2008

WS-Policy support in WSF/PHP

Web Services Policy is the standard way of publishing non functional requirements of a Web Service. For an example the only way of telling that a service needs all the incoming messages to it be signed is through Web Service Policy. WSO2 WSF/PHP is the only Web Services framework for PHP which suppoorts WS-Policy in an easy to use way.

You don't need to understand complex policy grammar. It is just PHP scripting. Follwing is an easy approach.

/*The Payload to be sent*/
$reqPayloadString = Hello World!

try {
/*The certificates need for security*/

/*Reciever's Public Key*/
$rec_cert = ws_get_cert_from_file("../keys/bob_cert.cert");

/*Sender's Private Key*/
$pvt_key = ws_get_key_from_file("../keys/alice_key.pem");

/*construction of Message using the endpoint Address*/
$reqMessage = new WSMessage($reqPayloadString,
array("to" => "http://localhost/samples/security/encryption/service.php",
"action" => "http://php.axis2.org/samples/echoString"));

/*The configurations need for security. Actually these are assertions found in Security Policy*/
$sec_array = array("encrypt" => TRUE,
"algorithmSuite" => "Basic256Rsa15",
"securityTokenReference" => "IssuerSerial");

/*construction of actual Policy object.*/
$policy = new WSPolicy(array("security" => $sec_array));
$sec_token = new WSSecurityToken(array("privateKey" => $pvt_key,
"receiverCertificate" => $rec_cert));

/*construction of WSClient to Send the message*/
$client = new WSClient(array("useWSA" => TRUE,
"policy" => $policy,
"securityToken" => $sec_token));

/*sending the message*/
$resMessage = $client->request($reqMessage);

printf("Response = %s \n", $resMessage->str);

If you have policy file instead of options , you just need to construct the policy object as follows.

$policy_xml = file_get_contents("policy.xml");
$policy = new WSPolicy($policy_xml);

So WS-Policy are now not complex things for PHP users willing to do Web Services.

Sunday, January 13, 2008

Authenticating Users in PHP Web Services.

User authentication is very important in Web services. Web Services Security Username token profile is the widely used standard used in Web Services for client authentication. WSO2 WSF/PHP provides Username token based authentication really easy. You may have a MYSQL based user details with their passwords. By just providing a callback function as following It is really easy to authenticate users before invoking the business logic.

/* The business logic */

function echoFunction($inMessage) {

$returnMessage = new WSMessage($inMessage->str);

return $returnMessage;
}


/*Password Callback function
function get_my_password_function($username)
{
//logic to get password from any source (ex: using mysql database
// etc)

}

$operations = array("echoString" => "echoFunction");
$actions = array("http://php.axis2.org/samples/echoString" => "echoString");
$sec_array = array("useUsernameToken" => TRUE);

$policy = new WSPolicy(array("security"=>$sec_array));
$sec_token = new WSSecurityToken(array("passwordCallback" => "get_my_password_function",
"passwordType" => "Digest"));

$svr = new WSService(array("operations" => $operations,
"actions" => $actions,
"policy" => $policy,
"securityToken" => $sec_token));

$svr->reply();

?>

For more clarification see WSF/PHP user manual