0% found this document useful (0 votes)
63 views

A Basic Guide To Implement A SOAP Client in PHP: Downloading, Installing and Configuring PHP

This document provides instructions for setting up a SOAP client in PHP to communicate with a SOAP web service. It describes downloading and configuring PHP and Apache, enabling necessary PHP extensions like cURL for SSL support, obtaining the nusoap library for SOAP support, and includes an example PHP script that calls SOAP methods to log in and send a message.

Uploaded by

Ng Meried
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

A Basic Guide To Implement A SOAP Client in PHP: Downloading, Installing and Configuring PHP

This document provides instructions for setting up a SOAP client in PHP to communicate with a SOAP web service. It describes downloading and configuring PHP and Apache, enabling necessary PHP extensions like cURL for SSL support, obtaining the nusoap library for SOAP support, and includes an example PHP script that calls SOAP methods to log in and send a message.

Uploaded by

Ng Meried
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

A Basic guide to implement a SOAP Client in PHP

Downloading, installing and configuring PHP

PHP is available to download from

http://www.php.net/downloads.php

If you are using the installer, the setup will automatically configure apache and other
settings for you.

If you are installing from binaries you will need to perform the following extra steps.

After installation, copy php.ini-dist to your windows directory and rename it to


php.ini

Configuring PHP with Apache

Edit the file httpd.conf in your Apache directory.

Search for the section of the file that has a series of commented out "LoadModule"
statements. Add the following line after all the LoadModule statements: (This line
may vary depending on your PHP version)

LoadModule php5_module "<php root>/php5apache2.dll"

If you are using Apache 2.X, remember to use "c:/php/php4apache2.dll" instead of


"c:/php/php4apache.dll".

For, for Apache 1.3.X users, search for the block of "AddModule" statements. Add
the following line after the last "AddModule" statement: If you're using Apache 2.X,
you do not have to insert the AddModule directive. It's no longer needed in that
version. Apache 2.X has its own internal method of determining the correct order of
loading the modules.

AddModule mod_php4.c

Finally, search for "AddType" in the file, and add the following line after the last
"AddType" statement:

AddType application/x-httpd-php .php


Testing your PHP configuration

Make sure that you have restarted apache after modifying its configuration.

Create a PHP file with the following line:


<?phpinfo()?>

Make sure that your apache httpd.conf document root to point to htdocs. Place the
above file (say phptest.php) in you apache/htdocs folder.

The sample php program can be run on the following url.

http://localhost/phpinfo.php

This sample program helps you find important settings in your PHP.

Additional (optional) settings

It is very helpful to see errors (if any) on the browser during run time, especially when
debugging. To enable this feature you need to configure additional settings.

Edit your php.ini, which you moved to c:/Windows as follows at the start. Change
display_errors to On if its Off.

Enabling Curl extensions for SSL support

When you need to access URL with https, you need to install/enable cURL
extensions. Since PageOne’s endpoint for soap stats with https, this has to be
configured as described below.

1. Edit your php.ini file as follows:


- set extensions_dir to <your php directory>\ext
- set register_globals to On
set sessions.save_path to <your php directory>\temp (you need to create that directory
first)

2. Copy php5ts.dll (located in <your php directory>\) to your Apache bin folder
3. Copy libeay32.dll and ssleay32.dll (located in <your php directory>) to
c:\windows\system32
4. Download cURL SSL version for Windows at: http://curl.haxx.se/download.html
5. Download OpenSSL for Windows from
http://curl.haxx.se/download.html
6.
[Windows XP Install Only] Check to see if you have the following file:
c:\windows\system32\msvcr70.dll. If not, search for it in Google and download it to
system32. You may get error messages without it.
7. Uncomment the curl line in your php.ini file to enable curl: extension=php_curl.dll

Additional libraries required for SOAP support -(nusoap)

This can be obtained on http://sourceforge.net/projects/nusoap/

Writing your first SOAP client

One you have configured your environment as described in the previous sections, you
can run your PHP scripts.

The following code illustrates writing a simple PHP script to


Login to PageOne SOAP Services and sending a message.

The wsdl that is used in this example is

https://soap.oventus.com/LiquidWS/MessageService?WSDL

However, we are using a non-wsdl approach to write the PHP


client.

We use the following endpoint to connect to PageOne. This is


the endpoint defined in the above WSDL.

https://soap.oventus.com/LiquidWS/MessageService

please refer to the annex A to see the sample code.


TestPageOne.php

<?php

require_once('lib/nusoap.php');

#if you use https://soap.oventus.com/LiquidWS/MessageService


you will need additional cURL extensions for ssl support

define ("SERVER_ENDPOINT", "


https://soap.oventus.com/LiquidWS/MessageService ");

$ns2 = "http://jaxb.liquidsoap.pageone.com";

#create login request and get sessionID

#enter a user name and password in get_login_body method


call

$sessionID = send_soapLoginRequest("login",
get_login_body('enter user name here','enter password'));

#create sendMessage request

#enter a valid mobile number and a message

send_message_request('sendMessage',get_sendMesssage_body('enter
a valid mobile number','enter your message here'),$sessionID);

function send_soapLoginRequest($method, $body)

echo "<h3>Performing '".$method."' test</h3>";

$client=new nusoap_client(SERVER_ENDPOINT);

if (check_error($client, "Constructor error"))

return;

$soapxml = $client->serializeEnvelope($body, "",


array(), 'document', 'literal');

$result = $client->send($soapxml, $method);


printRequestResponse($client, $result);

return get_session_id($client, $result);

function send_message_request($method, $body,$sessionID)

echo "<h3>Performing '".$method."' test</h3>";

$client=new nusoap_client(SERVER_ENDPOINT);

if (check_error($client, "Constructor error"))

return;

$soapxml = $client->serializeEnvelope($body,
get_header($sessionID), array(), 'document', 'literal');

$result = $client->send($soapxml, $method);

printRequestResponse($client, $result);

$info = $client->response;

$parts = explode("transactionID",$info);

$lpart = ltrim($parts[1], ">");

$session_info = rtrim($lpart, "</");

echo '<h2>transactionID is :: </h2><pre>';

echo $session_info;

echo '</pre>';

return;

}
function get_login_body($userid,$pwd)

echo "<h3>Getting Login body</h3>";

return "<m:loginRequest
xmlns:m=\"http://jaxb.liquidsoap.pageone.com\" service-id=\"0\"
vezrsion-id=\"\">\n"

."<user-id>".$userid."</user-id>\n"

."<pwd>".$pwd."</pwd>\n"

."</m:loginRequest>\n";

function get_sendMesssage_body($destination,$message)

echo "<h3>Getting Send message body</h3>";

return "<m:sendMessageRequest
xmlns:m=\"http://jaxb.liquidsoap.pageone.com\"
flashSMS=\"false\">\n"

."<destinationAddress>".$destination."</destinationAddres
s>\n"

."<message>".$message."</message>\n"

."</m:sendMessageRequest>\n";

function get_header($sessionID)

return "<m:pageoneHeader
xmlns:m=\"http://jaxb.liquidsoap.pageone.com\"><session-id>".
$sessionID."</session-id></m:pageoneHeader>";

}
function get_session_id($client, $result)

$info = $client->response;

$parts = explode("session-id",$info);

$lpart = ltrim($parts[1], ">");

$session_info = rtrim($lpart, "</");

echo '<h2>sessionid is :: </h2><pre>';

echo $session_info;

echo '</pre>';

return $session_info;

function printRequestResponse($client, $result)

echo '<h3>Sending</h3><textarea cols="100"


rows="20">'.$client->request.'</textarea><br />'.

'<h3>Response</h3><textarea cols="100"
rows="20">'.$client->response.'</textarea><br />';

if ($client->fault)

echo '<h2>Fault</h2><pre>';

print_r($result);

echo '</pre>';

else

check_error($client);
}

function check_error($client)

$err = $client->getError();

if ($err)

echo '<h2>'.$message.'</h2><pre>'.$err.'</pre>';

return true;

else

echo "<p>No errors</p>";

return false;

?>

You might also like