Sunday, January 8, 2012

Creating first PHP program (in Windows platform)

Creating a PHP client and consuming WCF service
1) Download PHP for windows and install it.
2) Run” PHP.exe –i “ to see the initialization settings.
3) You ll find PHP expects PHP.ini file to be present in C:\Windows. So first rename PHP.ini development to PHP.ini and copy it to C:\Windows
4) Modify C:\Windows\PHP.ini to include some settings for PHP runtime. Most of the settings are present there but commented with semi-colon (;) prefix. Just uncomment to include that setting.
a) uncomment include_path
b)uncomment extension=php_soap.dll (as we ll be needing to making SOAP calls)
c)uncomment extension_dir = "c:\php\ext" (set your extension dir. Mine is C:\PHP\ext
       5) Create the PHP program as follows and save it in LMSClient.php (Read the program. It ll make sense):

<?php

// Create a new soap client based on the service's metadata (WSDL)
$client = new SoapClient("http://localhost:24802/LMSService.svc?wsdl");

   //echo("<br />Dumping client object:<br />");
   //var_dump($client);
   //echo("<br /><br />");
  
   //echo("Dumping client functions:<br />");
   //var_dump($client->__getFunctions());
   //echo("<br /><br />");

//$result = $client->Test();
$result = $client->GetUserById(1);


//echo $result->TestResult;
echo $result->GetUserByIdResult->Firstname;
echo $result->GetUserByIdResult->Lastname;

?>

6) Run the program by php -f c:\php\MyPHPFiles\LMSClient.php

No comments:

Post a Comment