XML Web Service using PHP and SOAP

July 28, 2009

The basic Web services platform is XML and HTTP. XML provides a language which can be used between different platforms and programming languages. The HTTP protocol is the most used Internet protocol. Web services platform elements are SOAP (Simple Object Access Protocol), UDDI (Universal Description, Discovery and Integration), WSDL (Web Services Description Language).

Here I have talking about SOAP, NuSOAP and how it will use in PHP with example. So now let’s start. Simple Object Access Protocol (SOAP) is a simple XML-based protocol to let applications exchange information over HTTP.  Today’s Web Service (SOAP) is most popular and it provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.

Actually, the SOAP API itself has not been deprecated– just some of the functions. NuSOAP is a PHP library that allows you to send and receive SOAP messages. NuSOAP is a group of PHP classes that allow developers to create and consume SOAP services. It does not require any special PHP extensions. To use NuSOAP You must download NuSOAP library. Click Here to download library first.

Once you have downloaded a library file, you simply need to place it in your code tree so that you can include it from your PHP code. For my examples, I placed it in the same directory as the sample code itself.

I will start with the ubiquitous “Hello, World” example. This will demonstrate the basic coding of NuSOAP clients and servers.

I am going to start with the server code. The server exposes a single SOAP method named “Hello”, which takes a single string parameter for input and returns a string. Hopefully, the comments within the code provide sufficient explanation. For example server.php is a file name.

Now create a client side Script which will save it to the file clients.php. There are a few important things to note. First, when the instance of soap client is created, the parameter specified is the URL to the service. Second, when calling the service, the first parameter is the service name. This must match with the method registered within server.php. Finally, the second parameter in the call is an array of parameters that will be passed to the SOAP service method. Since the hello method of server.php requires a single parameter, this array has one element.

NuSOAP also provides a debug information. Adding the following to the client code will display this  debugging information.

I showed above code how  to display the SOAP request and response. Here is what the request from the client..php looks like.

You can CLICK HERE to download the source for this example as well.

Post a Comment

Your email address will not be published. Required fields are marked *


  • Recent Posts

    • Secure Your CodeIgniter Application using CSRF Token

      by admin
      In this tutorial, we will learn how to make our website more secure & protect from CSRF when we are using CodeIgniter web application framework. We thanks CodeIgniter team who giving in built support Cross Site Rquest Forgery (CSRF or XSRF). To enable CSRF protection CodeIgniter Framework will automatically protect forms or AJAX calls from CSRF when […]
    • Multiple Themes in CodeIgniter like WordPress

      by admin
      Create multiple themes and select one of them from backend like wordpress is drawbacks of a framework. Similar CodeIgniter have not an option to select one theme from multiple theme concept but we can re arrange using CodeIgniter template concept. We are going to handle multiple themes in a very simple way, in this example […]
    • How to create REST API in PHP?

      by admin
      REST (Representational State Transfer) is the standard design architecture for developing web services API. It is simple easy to understand and developing client-server relationship API. REST takes advantage of the HTTP request methods to layer itself into the existing HTTP architecture. We can handle GET, PUT, POST, DELETE operations through it. A REST API allows […]
    • Basic security vulnerabilities in php code

      by admin
      Today I have informed PHP programmers of common security mistakes that can be overlooked in PHP scripts. In the beginning programmers fail to understand about the PHP security issues or how to make secure script. The wise programmer knows that the real question is how secure a site is. Here I have focus how to […]
    • Generating CAPTCHA Image Using PHP

      by admin
      The CAPTCHA is a very very useful test to prevent abuse on the websites. When you create a web form like registration, login, contact us, blog comment etc…, We are suffering day by day with unwanted email or web spam abuse. So if you use CAPTCHA on your website forms, this can help in stopping […]
Copyright © 2012-2013 Sujit Shah. .
Tags: PHP Programmer Nepal, Web Developer Nepal, Website Designer, CodeIgniter Developer, Yii Framework, Wordpres, OpenCart, Drupal, Front End Developer, Responsive Developer, Bootstrap, Foundation, Freelance PHP MySql Programmer Nepal, Expert Programmer Nepal, PHP, MySql, LAMP, Linux, Apache, SVN, JavaScript, Ajax, jQuery, HTML, HTML5, CSS, CSS3, XML, SOAP, PSD to XHTML, Responsive Web Design, Web Development, CMS, E-commerce, Classified, Job portal, Travel & tours, Penny Auction, Lowest Unique Bid Auction, Reverse Auction, Price Reveal Auction, Payment Gateway Integration, Nepal, India, Hong Kong, Australia, UK, USA, Singapore, Germany, Canada, Netherlands, New Zealand, Norway, Italy