Thursday, January 31, 2008

Obtaining Soap Fault Information from WSFault Object

WSFault Object encapsulates the information related to SOAP Fault and stores them as properties of the WSFault object.

WSFault object has the following properties.

Reason, Code, Detail and Role. In addition it has a property "str" which contains the entire Fault xml as a string.

So Obtaining the Fault and Getting Information from it is very simple.

All what is required it to catch the exception object, check whether it is actually a WSFault object, and read the fault properties.

For example, to obtain the Soap Fault Reason , one can use the following code sample.
try{
// Some WSClient related code goes here.
}catch (Exception $e) {
if ($e instanceof WSFault) {
printf("Soap Fault: %s\n", $e->Reason);
} else {
printf("Message = %s\n",$e->getMessage());
}
}

Read documentation from full detail.

Wednesday, January 30, 2008

Article on Amazon Online Shoping

Dimuthu has written an article on how to utilize WSF/PHP extension to do amazon online shoping.

It has the source code too.

Implementing a Service using a PHP Class

WSF/PHP supports implementing a service using a php class. One of the advantages of implementing the service Operations with in a class is that is gives the ability to pass arguments to the constructor of the class.

Following is a simple example.

class Bar{

private $value = "";
function __construct($str){
$this->value = $str;
}

function echoValue($inMessage){
$responsePayloadString = <<<XML
<ns1:echostring ns1="<a href=">http://wso2.org/projects/wsf/php</a>">
<value>$this->value</value> </ns1:echoString>
XML;
return new WSMessage($responsePayloadString);
}

}

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

$service = new WSService(
array( "classes" => array("Bar" =>
array("operations" =>$operations,
"args" => array("Hello")
)
)));


$service->reply();

Note that Bar class is just a very simple PHP class. It's constructor takes a string argument and echo that value.

Next you have to define the Operations array with is very simple.
Next you need to tell the WSService class about your class, its defined operations and its arguements.

WSService options array accepts a parameter named "classes" which is an associative array. Its key is the class name and value is another array with contains the "operations" options and "args" options. "operations" are the operations defined in the class. The "args" is an array of arguments to the constructor of the corresponding class. Since the "Bar" class has a single argument constuctor, we are providing an string.

Tuesday, January 29, 2008

Changing the Service Name

WSF/PHP uses the php file location to generate a unique service name which is used to store the service configuration information in the Underlying WSF/C Library. We used "" simple to seperate out the folder paths so that the generated string will be unique for a given file.
This was however causing problems with the generated WSDL file as other WSDL parsers complained of this symbol.

We have now fix this issue by allowing the user to specify a unique service name for a given file. In addition , if the user does not sepcify the "serviceName" option, a service name will be generated using the "_" to separate the folder paths. How ever this may not generate a unique name all the time.
So if you are using WSF/PHP now it is possible to configue your service name.

Eg

WSService(array("serviceName"=>"MyService"));

Friday, January 25, 2008

Accessing Flicker REST API

Accessing Flicker rest API using php is very simple. All what is needed is to construct the arguements array with the url and invoke the query. You can use the file_get_contents function to do the invocation.

For example, to invoke the flicker.photos.getRecent method , you can you the following code sample.

"flickr.photos.getRecent",
'api_key' => "your api key goes here");

foreach ($params as $key => $value) {
$query_string .= "$key=" . urlencode($value) . "&";
}

$url = "$base_string?$query_string";

$output = file_get_contents($url);

echo $output;

?>

you can use the urlencode function to encode the array of parameters and send then use the file_get_contents function to send the reqeust.

Thursday, January 24, 2008

Getting WSF/PHP running on Debian

Dinesh has posted a very comprehensive guide to getting WSF/PHP working on debian.
It will provide all the details you will need.

Building WSF/PHP on Windows

Building WSF/PHP on Windows platform is quite straight forward provided that you have the necessary tools and the dependency software.
For building WSF/PHP you will need Microsoft Visual Studio. Else you can build using Windows platform SDK and Visual Studio Express edition.

I will list down the step by step process to building WSF/PHP on windows.

1. Download the dependencies.
1. Libxml2
2. Iconv
3. OpenSSL ( Download MSI installer )
4. PHP Source
5. PHP Binary
6. PHP Win32 Build tools. (Win32 build)
7. WSF/PHP source zip
8. Sqlite

2. Next Install OpenSSL.
3. Unzip all the binary dependencies.
4. Unzip WSF/PHP source. Eg E:\wso2-wsf-php-1.2.0
5. Go to E:\wso2-wsf-php-1.2.0 and open configure.in file.
6. Now you will see an option set like this.


DEBUG = 1
CRUNTIME=/MT
EMBED_MANIFEST=0
LIBXML2_BIN_DIR = E:\libxml2-2.6.30.win32
ICONV_BIN_DIR = E:\iconv-1.9.2.win32
ENABLE_SSL = 1
OPENSSL_BIN_DIR = E:\OpenSSL
WITH_SQLITE = 1
SQLITE_BIN_DIR = "E:\sqlite-3_3_81
SQLITE_SRC_DIR = "E:\sqlite-3_3_81"

PHP_SRC_DIR = E:\php\php-5.2.5
PHP_BIN_DIR = E:\php\php-5.2.5-Win32
WIN32BUILD_DIR = E:\php\win32build

I have removed the comments in the configure.in file. All you have to do is to edit these directory locations and set your corresponding directory locations.
If you want a debug build , set DEBUG option to 1.

7. open a command line.
Go to "C:\Program Files\Microsoft Visual Studio 8\VC\bin" directory and run the vcvars32.bat file. (Note: depending on your VC version, you might have a different location.)

8. Go to your WSF/PHP extract directory and run the build.bat file.

If you have set the directory paths correctly, WSF/PHP will be compiled and you will get the binary directory "wso2-wsf-php-bin-1.2.0-win32" built to the same directory.

Happy Compiling.