Home > A Basic guide to write a SOAP Client in PHP

A Basic guide to write a SOAP Client in PHP

Page 1
A Basic guide to implement a SOAP Client in PHP
Downloading, installing and configuring PHP
PHP is available to download from
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: v1.1
AddType application/x-httpd-php .php

Page 2
Testing your PHP configuration
Make sure that you have restarted apache after modifying its configuration. Create a PHP file with the following line:
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.
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

Page 3
[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
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.
please refer to the annex A to see the sample code.

Page 4
<?php require_once('lib/nusoap.php'); #if you use https://m2m.oventus.com/LiquidWS/MessageService?WSDL you will need additional cURL extensions for ssl support define ("SERVER_ENDPOINT", " https://m2m.oventus.com/LiquidWS/MessageService?WSDL "); $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);

Page 5
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; }

Page 6
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>"; }

Page 7
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);

Page 8
} } 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; } ?>
Search more related documents:A Basic guide to write a SOAP Client in PHP

Set Home | Add to Favorites

All Rights Reserved Powered by Free Document Search and Download

Copyright © 2011
This site does not host pdf,doc,ppt,xls,rtf,txt files all document are the property of their respective owners. complaint#nuokui.com