PHP SOAP and WSDL | Lessoncup Programming Blog

Monday, 23 December 2013


Hi, today i am going to tell you about how to create a SOAP Object with PHP, before that we must know about what is SOAP, a SOAP is ( SIMPLE OBJECT ACCESS PROTOCOL ) which is used for creating a Web Service, the advantage of SOAP is we can communicate with multiple and different operating system and work with multiple programming platforms on HTTP request, we can write the SOAP in XML based language, let's see how to create a simple soap server and soap client using php


is a Constructor and provide a server to access the WSDL file and you can use this with WSDL or without WSDL service discretion, you can create the soap server in php using new keyword see this code new SoapServer("some.wsdl");


 is a Constructor and provide a client to access the WSDL file and you can use this with WSDL or without WSDL service discretion, you can create the soap client in php using new keyword see this code new SoapClient ("some.wsdl"); 

What is WSDL ?

WSDL is Web service Description Language and it is written in XML based language to describe the web services, it is a place where we write the php function names to access the SoapServer and in same wsdl file we also use the php file name with that wsdl file access the given function from php file, see the bellow XML code which i have wrote to access the users data from database
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='Users' 

<message name='getUsersRequest'> 
  <part name='symbol' type='xsd:string'/>
<message name='getUsersResponse'> 
  <part name='Result' type='xsd:string'/> 

<portType name='UsersPortType'> 
  <operation name='getUsers'>
    <input message='tns:getUsersRequest'/> 
    <output message='tns:getUsersResponse'/>   

<binding name='UsersBinding' type='tns:UsersPortType'> 
  <soap:binding style='rpc' transport=''/> 
  <operation name='getUsers'> 
    <soap:operation soapAction='urn:localhost'/> 
      <soap:body use='encoded' namespace='urn:localhost' encodingStyle=''/> 
      <soap:body use='encoded' namespace='urn:localhost' encodingStyle=''/> 

<service name='UsersService'> 
  <port name='UsersPort' binding='UsersBinding'> 
    <soap:address location=''/> 

users.php (Creating Soap Server)

in this file create the function and write the query to fetch the users data from database and using json_encode() method convert the php array to json object,  remind when ever you work with soap and wsdl you must set the cache of wsdl in server using ini_set("soap.wsdl_cache_enabled","0");

now create the Soap Server using new SoapServer('users.wsdl') and keep the wsdl file inside the constructor now we need to provide the function name to Soap Client with that the client access the data, use addFunction("getUsers") method it is predefined function of SOAP Class and inside the function assign the php function name like getUsers, now use handle() method to handle the SOAP request


function getUsers(){

   $ss= mysql_query("select * from users");

   $data = array();
   while ($row=mysql_fetch_array($ss)){
   $data[] = $row['uid'] . " " . $row['username'] . " " . $row['email'] . " " . $row['gender'].'<br/>';

   $fabdata = json_encode($data);

   return $fabdata;

$server = new SoapServer("users.wsdl");


index.php (Creating Soap Client)

here first turn off the wsdl cache, now create the soap client using new SoapClient("users.wsdl") and give the wsdl file inside the function now call the function name which is written in users.wsdl file like getUsers() now decode the JSON encoded data which is coming from function using json_decode() method, now just print or loop the elements you can able to see the result..
// turn off the WSDL cache
ini_set ("soap.wsdl_cache_enabled", "0");

$client = new SoapClient("users.wsdl");

$us = $client->getUsers();

$users= (array) json_decode($us);

while (list($key, $val) = each($users)) {

echo "$key => $val\n";



Download Script


  1. can i access getUsers method in android App environment.
    Let me know if you know how to use it with cross platform

  2. is getUsers is default function of wsdl ?
    how can i declare custom function with this environment?

    1. ok i got it. Thanks for initiating me to learn webservice with SOAP and PHP.
      Thanks a lot.
      but i didn't got my first question answer.plz let me know how to use it with android.

  3. confusing tutorial but gud effort :)
    try to elaborate more

  4. Such developers with solid fundamental information and experience acknowledge a wide range of challenges and targets profiting the purchasers and no more. Top Expert Cakephp Developers

  5. Arranged in a straightforward manner, PHP gives more versatility than C, C++ and ASP and general causes in growing development to the site. It has a clear and viably reasonable semantic structure.Why use Laravel

  6. The first is about the instrument of patent itself and whether the way of security it gives is fit to the software business. The second is the idea of software and whether it ought to be liable to protecting. itools 4 crack license key free download

  7. A backlink is a link created when one website links to another. Backlinks are important to SEO & impact for higher ranking. In my 7+ years seo Career i see, without backlinks a website doesn't rank higher on google SERP.

    Get Your 300+ High Quality DoFollow Backlinks Here!

    Order Now with Full Confidence & 100% satisfaction.

  8. With Brandsoo, it’s never been easier or more convenient to shop high quality domain names and professional logos brands for sale that’ll instantly give your brand a leg up and resonate with your audience! With many different domain sellers all competing for your business, you need to know where your business and brand will see.

  9. Forex Signals, MT4 and MT5 Indicators, Strategies, Expert Advisors, Forex News, Technical Analysis and Trade Updates in the FOREX IN WORLD

    Forex Signals Forex Strategies Forex Indicators Forex News Forex World

  10. Forex Signals, MT4 and MT5 Indicators, Strategies, Expert Advisors, Forex News, Technical Analysis and Trade Updates in the FOREX IN WORLD

    Forex Signals Forex Strategies Forex Indicators Forex News Forex World

  11. Situs judi bola online UFA88 Terpercaya, juga memiliki casino online seperti, baccarat, roulette, Judi slot online, sabung ayam dan dadu online.

  12. Adam the alien - Animated films A close encounter with a likable robot from another solar system leads to a star-crossed friendship Do aliens exist and an impossible intergalactic mission to save Extraterrestrial life the robot’s friends— despite overwhelming New cartoon movies odds.

  13. - Adalah Situs data hk Khusus yang menyediakan Daftar keluaran hk Result Nomor Togel dan Data hasil keluaran live draw hk seperti hk sgp sydney yang sudah terpercaya keluaran togel hk.

  14. Shield Security Solutions Provides Ontario Security Training, Security Guard License or Security License in Ontario. Get Started Today

  15. Vince Offer is and actor, producer and infomercial star. He is the best known infomercial star in the world. His products the SHAMWOW, InVINCEable, SlapChop, Schticky and more have sold millions. Vince Offer has also produced and starred in the films Underground Comedy Movie and The Inappropriate Comedy with Adrian Brody, Dante and Michelle Rodriguez.

  16. Website laten maken? Onze professionals bouwen een omzetverhogende, professionele én unieke website of webshop! Een website laten maken kan vandaag nog

    Website laten maken | webdesigner | website freelancer | webdeveloper | webdesigner

  17. Discover antimicrobial protection that’s built-in right into the finish of select TikTok Locksmith Services.

  18. We are a full service internet marketing company in the Pittsburgh area, that specializes in providing affordable internet marketing solutions for small businesses.
    Our Pittsburgh SEO companies team builds and enhances local business listings and seo search engine optimization. This service drives lead generation and brand recognition.
    Our goal is long term mutual relationships with small business owners, providing customized internet marketing services.

  19. Insurance Claim Adjuster - We specialize in helping families with their property damage claim. Take comfort knowing I will do everything I can to help you. Ask for Mike

  20. Keeping up with Brilyent Kelly. Get Exlcusive offers and see the latest Music and news & Follow me on instragram Celebrity.

  21. Thank you for this important information about PHP SOAP and WSDL.
    online classified ads platform

  22. Royal Moving Co. is an affordable Los Angeles Moving Company for both local moving, Movers near me long distance moving and packing services throughout Los Angeles county. We Moving company near me offer professional, affordable service.

  23. It can be used with or without a WSDL service description.

  24. This language is so difficult. But it's known that there is nothing to hard work and will. I will do my best to learn this language.

    JK Gypsum Decoration has been serving all over Bangladesh for seven years as a Gypsum Board Supplier and Distributor in BD. We are highly skilled and experienced in interior design. We provide services all over the country as the largest Gypsum Decoration and Interior Design Company.

  25. I am learning sql and php language. I think it will help me to understand that easily.

    The main goal of eco technology is to conserve nature, and to remedy the negative impact that humans have on it. It offers a lot of benefits to not only nature itself but also for a clean and greener human lifestyle. Human beings need Earth to stay alive. This technology ensures that the Earth remains healthy for all life to continue existing. Eco technology is committed with these and they are the best environmental Engineering Company in Bangladesh.

  26. Thanks for sharing such a informative blog with us thank you.Gotham Knights Robin Jacket

  27. Keep the ball rolling you have done the great job here.
    logo creation company

  28. You can do very creative work in a particular field. Exceptional concept That was incredible share. RPD Vest

  29. Our the purpose is to share the reviews about the latest Jackets,Coats and Vests also share the related Movies,Gaming, Casual,Faux Leather and Leather materials available Yankees Jacket

  30. I love to recommend you Where can crawl Exciting Products latest Jackets, Coats and Vests Click Here Slim Fit Jackets

  31. Thanks for sharing this informative post. We are selling online leather products at an affordable price & free shipping.
    Men Aviator Leather Jacket
    MotoGP Leather Jackets
    MotoGP Leather Suits
    V Bomber Leather Jacket

  32. İnstagram takipçi satın al! İnstagram takipçi sitesi ile takipçi satın al sende sosyal medyada fenomen olmaya bir adım at. Sende hemen instagram takipçi satın almak istiyorsan tıkla:

    1- takipçi satın al

    2- takipçi satın al

    3- takipçi satın al

  33. We are looking for an informative post it is very helpful thanks for sharing it. We are offering all types of leather jackets with worldwide free shipping.

  34. Thank for sharing this post. We were looking for this type of informative post to enhance our knowledge. We hope you will continue to share similar posts.
    Flying Leather Jacket
    Shearling Coat Men
    Shearling Jacket Men
    Bomber Leather Jacket
    V Bomber Leather Jacket

  35. We are looking for an informative post it is very helpful thanks for sharing it. We are offering all types of leather jackets with worldwide free shipping.
    Harley Davidson Jacket
    Western Leather Jackets
    Studded Leather Jacket
    Leather Motorcycle Jackets


Mohammad Khasim
Blogger | Web Developer
Hyderabad - INDIA

Web Development Tools | CMS | Frameworks | SEO

Get my Latest Lessons