In this post i explain you how to create SOAP web service in PHP. Most of trinity follower request for this post, so here it is :). In my last post i explain how to create REST service in php.

What is SOAP?

SOAP (Simple Object Access Protocol) is a messaging protocol that allows programs that run on disparate operating systems (such as Windows and Linux) to communicate using Hypertext Transfer Protocol (HTTP) and its Extensible Markup Language (XML).

Now before start creating SOAP service we need NUSOAP Library. You can easily  download that from here.

Live Preview:

Create Your First SOAP service

I share some basics of SOAP service step by step.

Step 1. Download NUSOAP and extract into your server root directory or any folder inside your server or local server.

Step 2. Create new php file name it whatever you like i name my file index.php and include nusoap.php.

Step 3. Now create your first method which we are going to use later in SOAP service.

Step 4. Now we create instance of soap_server because we are creating a server file which handle request and response to user.

Step 5. Now we configure or soap service by calling a method configWSDL as shown bellow

WSDL:  Web Services Description Language (WSDL) is an XML-based language used to describe the services a business offers and to provide a way for individuals and other businesses to access those services electronically.

Step 6. Now this is important step where i register my created method which i create in beginning.

You can register any number of function you want according to your need.

Step 7. This is last step in this we can return data to user

All done now we can check this in our browser open your page in your browser or you can go to this link to preview.

Now to send data to server i add tool or extension in my browser. I am using SOA Client for Mozilla for this.

SOAP Client

Paste your URL: and click on Parse WSDL. Select function using radio button you also use radio button to select different program, add your data inside field and click on invoke, if your data submit successfully you get your response as shown bellow image

SOAP Rest Client

Complete code

That’s it. Now you can create your own SOAP service in PHP, You can easily add your functionality inside function or create class and call its function etc.

Hope this help you understand and create web service in SOAP using PHP.

Thank you 🙂