Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^286) CHAPTER 19 ■ INTRODUCTION TO WEB SERVICES WITH SOAP
by the SOAP extension. However, it is important to be able to understand SOAP, because any
problem in the automatic encoding of the SOAP data can result in frustrating and time-consuming
errors. In developing any reasonably complex web service, you are likely to experience a problem
at least once, so you will want to know how your data should look in encoded form.


Introduction to WSDL


WSDL, an XML format, has its own set of elements and attributes. The WSDL file for your PHP
applications will provide information about the service, including the URL of your service, the
XML namespace, which methods and parameters are exposed, and the return values you expect
to receive.

WSDL Terminology.


WSDL documents are no more difficult to write than HTML documents; they just follow a
different syntax that tends to be a little less concise. WSDL is designed to be really extensible,
so a lot of the concepts will seem to overlap, but each does actually have a slightly different
purpose. The following are some WSDL terms that you can expect to encounter when you’re
working with web services. Just as you know what divs and spans are, you’ll want to recognize
these WSDL equivalents of common tags.

Types: These represent a format of data, like a string or an integer, or even an object with
properties. There are built-in types for most things like integers and strings, and these are
inherited from the XML Schema Definition (XSD) language. In the next chapter, you will
learn how to create complex types that represent custom objects. In this chapter, we’ll
stick with the standard, simple data types.

Messages: These provide a definition, or collection, of data that will be transferred. Think
of a message as a representation of a parameter list and a description of the return values
for a function. There are generally two messages for every method: a request and response
message. The request message will define the parameters for the method, and the response
message will define what data is returned. Due to the behavior of some SOAP implemen-
tations, the name attribute for messages should always end in Request or Response. The
names of the parameters and return values in a message are called parts.

Operations: These are a way of describing methods. Each operation will define an input
message for its parameters list and an output message for its return values. The key infor-
mation provided by an operation element is a name and what input and output messages
are associated with the method. In WSDL jargon, a method is called an operation and is
sometimes referred to as an action.

Port types: These are a way of grouping a set of operations. This step allows you to define
one WSDL file that might have operations implemented on multiple servers. A port-type
collection is the list of operations that will be implemented on one endpoint URL.

Bindings: These define how the port type will communicate data—in your case, using the
SOAP-encoding method and using Remote Procedure Call (RPC) as the style of messaging.
Other types of encodings and styles are available, but we won’t cover them here.

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

Free download pdf