Using AMF Message Headers

The data access is automated, and the data gets transferred over the AMF protocol, which, as you may remember, is built on top of HTTP. The next goal is to continue minimizing the amount of coding that application programmers need to do in the client/server communication. For this, we’ll try to modify the existing communications layer by adding to it application-specific information.

Sometimes, certain information needs to be passed from the client without introducing additional arguments to the application function calls. For example, if the user ID needs to be passed to the server-side function getEmployee(), you may avoid adding a parameter userId to the function signature. Instead, it can be added to the AMF message on the protocol level. Besides the user ID, you may need to pass some security restrictions, application tokens, or the client context—think of HTTP cookies. Although you might need to add these parameters at certain execution points, you may not pass them as part of the API.

Though the AMF payload is located in the bodies of the messages that are being sent, you can still add headers to these messages. Here is a quick five-step process:

  1. Define a class to store the data you want to be passed in the message headers—sort of like your own cookies—for example, some operation context (Example 6-18).

    Example 6-18. OperationContext.as

    package com.farata.rpc.remoting { import flash.utils.Dictionary; import mx.messaging.messages.IMessage; public final ...

Get Agile Enterprise Application Development with Flex now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.