Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
285

■ ■ ■


CHAPTER 19


Introduction to Web Services


with SOAP


Web services allow you to share data between server-to-server systems. They represent auto-
mated, machine-readable interactions between machines and typically operate using HTTP.
The Web Services Description Language (WSDL) describes the abilities of the web service.
The SOAP protocol encodes and encapsulates the data you wish to share. The purpose of SOAP
is to exchange packets of data, which are called envelopes, using a common format that is
universally understood. This universal understanding is critical to web services, as they may be
programmed in vastly different programming languages that have very different expectations
and methodologies.
In this chapter, you will learn the basics of WSDL and SOAP, as well as how to create a web
service using the PHP SOAP extension. At the end of the chapter, you will connect to Amazon.com
and find out some information about this book using the Amazon Web Services API.

Introduction to the PHP Web Services Architecture


The PHP web services architecture has a few key components. First, in PHP, SOAP function-
ality is provided by an extension. If you already have this extension, you’ll find soap listed in
your phpinfo() results. If the SOAP extension is not listed, you will need to compile it in, using
the –enable-soap configuration argument when building PHP.
The SOAP extension provides two key classes, SoapClient and SoapServer, which form the
basis of the web services programming interface for PHP. You’ll be introduced to their syntax
later in this chapter.
SOAP clients and servers both need to know which methods a web service will expose. To
describe these methods, you use a description language called WSDL. This is an XML-based
markup language, which you will place in a service WSDL file. Then you will provide this file to
both your SOAP server and clients. The purpose of the WSD L file is to provide some basic infor-
mation about the calling context of your methods, such as the location, method name,
parameters, and return value.
SOAP is used to send data between the client and server. Unlike with WSDL, you are not
responsible for writing SOAP markup yourself, as it will be generated and interpreted for you

McArthur_819-9.book Page 285 Friday, February 29, 2008 8:03 AM

Free download pdf