Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
299

■ ■ ■


CHAPTER 20


Advanced Web Services


In the previous chapter, you created a basic web service and made a call to the Amazon Web
Services API, which involved passing simple arrays and values. For real-life applications, however,
you may need to send objects between two back-end systems. To do this, you will need to use
some of the advanced features of WSDL and the SOAP extension to encode and decode objects
properly. In this chapter, you will learn about complex types, which enable this functionality
by defining the elements in the object in a universal format.
You are probably familiar with how to track sessions and authenticate users for your web
applications. When working with web service clients and servers, the syntax for these tasks can
be slightly different and sometimes more complicated. In this chapter, you will learn how to
create session-based services and use the SOAP API to track session identifiers between requests.
You will also learn about persistent objects, which can maintain a server state during a web
services session. Finally, you will discover how to transmit binary data, such as images and
video, to your web services. To demonstrate, you will send a photo to a web service by encoding
it using base64 encoding.

Complex Types


Complex types are the way objects are represented in WSDL. While you don’t declare methods
in a complex type, you can declare any number of member variables as being part of the structure.
Let’s look at an example of using complex types.

A Complex Type Example


Suppose you work for a phone company with a lot of resellers who are responsible for billing
their clients directly. You need to provide a way for your resellers to get access to their subscribers’
call records, and you need to do it in a universal way because your resellers use different program-
ming languages in their systems. Enter WSDL and complex types.
The data you want to provide is all the calling information for a specific subscriber: start
time, duration, caller (the phone number from which the call was placed), and the callee (the
dialed number). You could just provide a generic array type as a return value in your WSDL, but
then your resellers wouldn’t know which key names to expect and would need to do extra iter-
ations to convert the result to an object format. With complex types, you can provide an object-
mappable data type, as well as an array of records of that type.

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

Free download pdf