How to write SOAP web service using PHP?

     How to write web service using SOAP in PHP?
             In my previous post I had shown you “how to read gmail inbox using PHP”. Today I am writing my web service using SOAP. If you are wondering “How to create SOAP service?” , Then solution is here. Here I have created web service. All you need to do is, you just have to call service and function to perform particular task.

So let’s follow steps to do this stuffs.

 [NB: If you are facing trouble with below code then please do visit my latest updated post "SOAP web service using PHP". ]

Step 1 : Download nusoap zip file from here.  And paste it inside your www folder if you are using wamp, for xampp user paste it inside htdocs/xampp folder.
Step 2:  create two file call server.php and client.php.
Step 3 :  Inside server.php write below lines of code.
$server = new nusoap_server;
//$server ->configureWSDL('server', 'urn:server');
//$server ->wsdl->schemaTargetNamespace = 'urn:server';
//$server ->register('pollServer', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server#pollServer');

//register a function that works on server
$server ->register('getfeedDetails', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server# getfeedDetails');

// create the function to fetch Data’s from Database
function getfeedDetails ()
              $conn = mysql_connect('localhost','root','');
                mysql_select_db('news', $conn);
                $sql = "SELECT * FROM user_story";
                $q = mysql_query($sql);
                       $items = array();
                while($row = mysql_fetch_array($q)){

                                $items [] = array(
                      return $items;


$server ->service($HTTP_RAW_POST_DATA);
         That’s it you have created your server file to access and fetch details from database.
Step 4:    Now create client.php and inside it just  write below code. Create client object and call your server function to retrieve details.
$url = "http://localhost/testserver/server.php?wsdl";
$client = new nusoap_client($url);
//Call server function
$response = $client ->call(' getfeedDetails ');

                echo "FAULT: <p>Code: (".$client ->faultcode.")</p>";
                echo "String: ".$client->faultstring;
                $result = $response;
                $count = count($result);
    <table >
                <th>Story Url</th>
                <th>Story Title</th>
                <th>Story Description</th>
                <th>Story Image</th>

    for($i = 0;$i < $count-1;$i++) {
                  $rowtype = ($i % 2) ? "style='background:#88DAEB'": "style=background:#FFF";
    <tr <?php echo $rowtype; ?>>
                <td><?php echo $result[$i]['story_url']?></td>
                <td><?php echo $result[$i]['story_title']?></td>
                <td><?php echo $result[$i]['story_description']?></td>
                <td><img src="<?php echo $result[$i]['story_image']?>" type="photo"></td>
<style type="text/css">
    th {

Step 5:   That’s it you have done. Now run your client.php in your browser. It will call server and fetch the details from database.  
So today I have shown you how to use simple SOAP webservice and to get details from database.  
    Thats all run the code and enjoy.Hope this post will help you tocreating simple webservice using SOAP. Post your queries if you have or anything  please share. Keep visiting for new posts here.
All the best. Have a good day. 

You also can join my group for latest technology updates in below link,
To join in LinkedIn :

To Join in Google+ :

To follow us in twitter :!/myinfoplace1 

google-site-verification: google32bdc2edc89dff15.html

Announcement from APPSNTECH.COM

                                    Hi Guys I am little busy with my work these days and unable to post articles. I will try to post some interesting and real time apps. I have drafted few articles and about to post. Currently I am busy with own PHP MVC Framework. It is almost done with basic functionality and about to add few more features to make it much more enjoyable.

Hope you all like my posts, If so please posts your comments here and share, if you want me to explain any specific topic and also you are welcome to share your ideas here. Just write an email to me I will post it with your name.

                                                 Thank you all my visitors,
                                            You will see my new post soon.

Follow Us On Facebook Open Source Web Developers by Appsntech facebook group Twitter Open Source Web Developers by Appsntech twitter group Google+ Open Source Web Developers by Appsntech Google group Linkedin Open Source Web Developers by Appsntech, LinkedIn group
Copyright @2011-2015 All rights reserved. Powered By- Sanjoy Dey Productions