Using SOAP with PHP Soap Server | Soap Client
  • XML: XML is the Extensible Markup Language. It is designed to improve the functionality of the Web by providing more flexible and adaptable information identification. XML is a method for describing your data. The libraries and protocols we will use will handle the XML manipulation.
  • SOAP: Simple Object Access Protocol. "SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses. I've developed both a client and a server for our SOAP service using the NuSOAP library.
  • WSDL: WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information." The NuSOAP library will generate WSDL documents. WSDL is a document that describes a Web Service. It tells a client how to interact with the Web Service and what interfaces that Web Service provides.
  • Client: Client is defined as a script that uses a Web Service.
  • Server: Conversely, a Server will be defined as a script that provides a Web Service.

Sample Web Service that will return a stock price given a particular stock symbol.

Building a Web Service allows other applications easy access to the same data in the future. It also separates the data extraction from the data source from the application itself. Say you were storing the data in a MySQL database but later decided to move it to a SQLite database... in this scenario your application wouldn't know the difference. Its calls to the Web Service remain unchanged.

MySql table schema and some sample data to work with

CREATE TABLE `stockprices` (
`stock_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`stock_symbol` CHAR( 3 ) NOT NULL ,
`stock_price` DECIMAL(8,2) NOT NULL ,
PRIMARY KEY ( `stock_id` )
);
INSERT INTO `stockprices` VALUES (1, YUKU', '75.00');
INSERT INTO `stockprices` VALUES (2, 'DELOY', '45.00');
INSERT INTO `stockprices` VALUES (3, 'IBM', '12.00');
INSERT INTO `stockprices` VALUES (4, MSFT', '34.00');

 

SERVER

 

At this point I have a fully functioning SOAP Server. Clients can connect to it and request data. Click here to bring up the script in your browser and see what you get. You should get a page giving you a link to the WSDL document for the Server. Click on it and you should see the resulting WSDL document... in XML! If you read over this document, you will see that it describes what happens for a request and as a response for your particular SOAP Service.

CLIENT: Click here to connect and request sample stock data