Passing custom headers from the client to the server is made very easy using RemoteObjects and WebORB for .NET.
1. Initially during the construction of the RemoteObject in the client-code, we add an eventlistener for the Invoke event on the RemoteObject:
this.service.addEventListener( InvokeEvent.INVOKE, ServiceDelegateCallManager.handleInvoke );
2. In the handler we add the header:
public static function handleInvoke( event:InvokeEvent ) : void
var message:AbstractMessage = event.message as AbstractMessage;
message.headers.MBUserID = User.current.userId;
3. On the server its really easy to retrieve the custom headers side by side with the default Flex DataServices headers. In the respective method called on the server we are now able to retrieve the added header with a mere 3 lines of code:
using Weborb; // to import ORBConstants
using Weborb.Util; // to import ThreadContext
Hashtable props = ThreadContext.getProperties();
Hashtable headers = (Hashtable)props[ ORBConstants.REQUEST_HEASDERS ];
String mbUserID = (String)headers[ “MBUserID” ]
Thanks to Mark Pillar from MidnightCoders for providing the insight in WebORB to do this.
If you are interested in reading more about Flex and .NET security, please check out Mark’s article on Adobe.com – its and excellent primer on this topic (http://www.adobe.com/devnet/flex/articles/net_security.html)