Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Nested Queries with PHP Data Services

Monday, August 4, 2008

If you have been aware of PHP Data Services, You may be already know that it is going to be a major feature in the WSF/PHP 2.0.0 release. In fact you can download it from here and run it with WSF/PHP older versions as well.

I wrote a little guide/ tutorial on how to do nested queries with PHP Data Services over here. Hope this will be usefull for people who were looking for some documentation on how to use this library in addition to the samples and the online demos.

PHP Web Services with WSDL Tutorial

Wednesday, March 26, 2008

Were you finding a starters tutorial for PHP Web Services with WSDL?. I wrote one for wso2 Oxygen Tank. This is based on the WSO2 WSF/PHP release 1.2.0. But it will be working for newer releases like 1.2.1 without problem. Hope you will be find this really useful.

[ANN] WSO2 WSF/PHP Demo site Launched

Tuesday, March 11, 2008

WSO2 WSF/PHP team is pleased to announce the launch of WSO2 WSF/PHP Demo Site - http://labs.wso2.org/wsf/php

WSO2 WSF/PHP Demo site is a place where users can try out demonstrations powered by WSO2 Web Service Framework for PHP (WSF/PHP) online. In addition to that it gives the facility to study, view the source code and refer related articles, tutorials for each demo.

We invite the WSF/PHP community to login to the site and give feedback on demos by rating and commenting on them.

You can post suggestions and possible improvements to the demo site via WSO2 WSF/PHP mailing list wsf-php-user@wso2.org

Thanks for you interest in WSO2 WSF/PHP Demo site

-- WSO2 WSF/PHP Team --
http://wso2.org/projects/wsf/php

Simple Calculator - Demo of use of WSDL mode

Here are the steps I followed to create a simple Calculator Service + client.

1. Stated with the CalculatorDoc.wsdl found in here, http://svn.apache.org/repos/asf/webservices/axis2/trunk/c/test/resources/wsdl/CalculatorDoc.wsdl

2. Generated server side code using the wsdl2php.php script packed with the WSO2 WSF/PHP 1.2.1.

3. Run the wsdl2php.php script from command prompt with the following arguments.

/my/home/scripts/wsdl2php.php -s CalculatorDoc.wsdl

Here '-s' means for the server side.

4. I redirected output to the service.php in my linux system, so the command was like
/my/home/scripts/wsdl2php.php -s CalculatorDoc.wsdl > service.php
In a case this this doesn't work for you copy and paste the code to the service.php file.

5. Filled the adding/ subtraction/ multiplication/ division algorithm inside method bodies. There are helping comments which guide you what are the types of parameters and return value in the function, here is my way of doing it.

// define PHP functions that maps to WSDL operations 
function add($input) {
// TODO: fill in the business logic
// NOTE: $input is of type add


$a = $input->arg_0_0;
$b = $input->arg_1_0;


$c = $a + $b;
// NOTE: should return an object of type addResponse

$res = new addResponse();
$res->addReturn = $c;


return $res;
}


function sub($input) {

// TODO: fill in the business logic
// NOTE: $input is of type sub

$a = $input->arg_0_1;
$b = $input->arg_1_1;


$c = $a - $b;
// NOTE: should return an object of type subResponse

$res = new subResponse();
$res->subReturn = $c;


return $res;
}


function mul($input) {

// TODO: fill in the business logic
// NOTE: $input is of type mul

$a = $input->arg_0_2;
$b = $input->arg_1_2;


$c = $a * $b;
// NOTE: should return an object of type mulResponse

$res = new mulResponse();
$res->mulReturn = $c;


return $res;
}


function div($input) {

// TODO: fill in the business logic
// NOTE: $input is of type div

$a = $input->arg_0_3;
$b = $input->arg_1_3;


$c = $a / $b;
// NOTE: should return an object of type divResponse

$res = new divResponse();
$res->divReturn = $c;


return $res;
}


6. Now put the service.php in to your web root directory or some sub directory inside the web root and make sure it is correctly deployed by typing the location in the browser. For an example, I put my service.php inside calculator sub directory inside the web root, so I tested in the browser by typing http://localhost/calculator/service.php

Note: that this doesn't test the algorithm of the service, but just it make sulre the service and the operation set are correctly deployed.

7. So now you can write a client to test the service operation, You can generate a client with the following command,

/my/home/scripts/wsdl2php.php CalculatorDoc.wsdl

Note that the '-s' is dropped.

8. Go through the TODO comments and fill the client logic by filling sample input to test the service,

   // create input object and set values
$input = new add();
//TODO: fill in the class fields of $input to match your business logic


$input->arg_0_0 = 3;
$input->arg_1_0 = 4;

// call the operation

$response = $proxy->add($input);
//TODO: Implement business logic to consume $response, which is of type addResponse

echo "3 + 4 = {$response->addReturn}\n";



$input = new sub();
//TODO: fill in the class fields of $input to match your business logic

$input->arg_0_1 = 3;
$input->arg_1_1 = 4;


// call the operation
$response = $proxy->sub($input);
//TODO: Implement business logic to consume $response, which is of type subResponsee


echo "3 - 4 = {$response->subReturn}\n";

$input = new mul();
//TODO: fill in the class fields of $input to match your business logic


$input->arg_0_2 = 3;
$input->arg_1_2 = 4;


// call the operation
$response = $proxy->mul($input);
//TODO: Implement business logic to consume $response, which is of type mulResponsee


echo "3 * 4 = {$response->mulReturn}\n";

$input = new div();
//TODO: fill in the class fields of $input to match your business logic


$input->arg_0_3 = 3;
$input->arg_1_3 = 4;


// call the operation
$response = $proxy->div($input);
//TODO: Implement business logic to consume $response, which is of type divResponsee


echo "3 / 4 = {$response->divReturn}\n"


9. One more thing, The wsdl is coded with it s endpoint, but for you to test you need to change the endpoint to where you have actually test the service, for an example in my case to " http://localhost/calculator/service.php"
You can do the change in the wsdl. But there is an option in the WSClient constructor where you can give the service endpoint.
So my new WSClient constructor looks like this,
   // create client in WSDL mode
$client = new WSClient(array ("wsdl" =>"CalculatorDoc.wsdl",
"to" => "http://localhost/calculator/service.php",
"classmap" => $class_map));



10. That is all I did, And Finally run the client with the following command,
php client.php

And I received the expected output as following,
3 + 4 = 7
3 - 4 = -1
3 * 4 = 12
3 / 4 = 0.75

PHP Amazon Client Demo

Thursday, March 6, 2008

This demo shows you how to consume the Amazon e-commerce SOAP API with PHP. It is a live demo, that you can view online and if you ever wonder how to do that in PHP, the source code is also available.

There is an associated tutorial too, that you can find in the above link. The tutorial explains step-by-step what you have to do to consume the Amazon API.

PHP Web Services: Getting Started

Friday, January 18, 2008

From the article on PHP Web Services:

Service Oriented Architecture (SOA) is popular in the enterprise, as it simplifies connecting systems. One of the preferred technologies used to implement SOA is Web services, other contenders being traditional messaging systems and plain old XML (POX) techniques. Web services technologies are capable of enabling machine-to-machine interactions, ensuring interoperability among heterogeneous systems. This helps realize loose coupling, a key characteristic of SOA. The machine processable interface, defined using WSDL, message based interactions, using SOAP, and the use of other Web related standards such as HTTP and XML, are the key pillars on which Web services are built.

Given the importance of Web services in the SOA era, it is a must that any programming language has provision to leverage the power of this technology and be able to play its role in a SOA implementation. PHP too has several options when it comes to working with Web services, however, one of the problems till recently was that the level of support for Web services in PHP was limited to SOAP interactions with some level of WSDL coverage. There was hardly any support for the full Web services stack, including addressing, binary attachments and security.