PHPBuilder - Building Web Services Using NuSOAP Toolkit



RSS Twitter
Articles Tricks And Hacks

Building Web Services Using NuSOAP Toolkit

by: Mitja Kramberger
|
December 26, 2003

Introduction

SOAP or "Simple Object Access Protocol" has built his concept on XML-RPC, but provides much richer features sets. In this article we are going to build a simple SOAP server and client which will use our new service.
You should know what SOAP is (SOAP packet structure), but purpose of this article is to show programmers how easy is to build web services (SOAP). Even if you don't know XML, SOAP, WSDL, the only requirement is basic XML knowledge. But if you're interested, you can find some nice tutorials on www.w3schools.com (XML,SOAP), www.xml.com, www.w3.org/TR/SOAP.

PHP and SOAP

PHP (for now) doesn't have a SOAP extension, but there are some nice PHP SOAP toolkits. You can even use XML-RPC PHP extension, where you can, by using optional argument ("version"), specify which protocol to use ("soap 1.1.". However, you need to take care of data transmitting across the network, where PHP toolkit takes care of that.

NuSOAP Toolkit

NuSOAP (formerly SOAPx4) is a toolkit which provides simple API for building web services using SOAP. There are also some other toolkits like PEAR:SOAP (also stable). NuSOAP current version is 0.6.4, which provides simple API for making SOAP server/client applications and also supports features like WSDL generation, building proxy class, using SSL, using HTTP proxy, HTTP authentication. So download current NuSOAP toolkit from cvs.sourceforge.net/viewcvs.py/nusoap/lib/ and lets get started.

The Story

Let's assume the existence of a government department which performs weather measurements. They want their data to be publicly accessible. So basically let's assume that they have for each city (worldwide) a current degrees measurements and a basic weather forecast.
First we create a simple MySQL table (current_data):
  CREATE TABLE current_data (
    id int(10) unsigned NOT NULL auto_increment,
    city varchar(20) default NULL,
    degrees float NOT NULL default '0',
    forecast varchar(255) default NULL,
    PRIMARY KEY  (id),
    UNIQUE KEY city (city),
    KEY city_2 (city)
  ) TYPE=MyISAM;
And let's fill it with some test data:
  INSERT INTO current_data VALUES (1, 'Chicago', '5',  'Partly cloudy.');
  INSERT INTO current_data VALUES (2, 'London',  '15', 
  	'Sun along with patchy clouds.');

1
|
2
|
3
|
4
|
5
|
6
Next Page »

Download: kramberger20031226_code.zip

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Mitja Kramberger

Comment:



Comment:

(Maximum characters: 1200). You have characters left.