Introduction to RPC on Windows, Part II - Types of Handles
(Page 2 of 5 )
There are two types of handles that we use while we program using RPC: Binding handles and Context handles. As an extension to the Standard RPC, Microsoft also provides a third type of handle: the serialization handle. These are used to encode or decode data. Just remember that these are used for serialization on a local computer only and do not involve any remote bindings. Here, we’re going to discuss the Binding and Context handles only and look at their usage.
Binding Handles
Binding handles come into the picture when we try to establish a logical connection between a client program and a server program. In fact the information that is needed to create a binding between a client and server is represented by a structure called a binding handle. Thus the binding handle is analogous to any other handle in the Win32 world: it just hides the binding information from the programmer and allows the RPC runtime to use it in an orderly fashion. The programmer is allowed to use and manipulate this information through a set of APIs that RPC runtime provides in the Windowing API that allows us to change the behavior or appearance of a window, if we have its handle. This way the run-time libraries access and manipulate the data appropriately on the programmer’s invocation.
Context Handles
Context handles, on the other hand, are needed to maintain a state between a client and a server. Consider the case of an Internet session where a user visits a publishing company’s Web page and orders a few books. Next he chooses to pay online and in this process he reaches a page to input his credit card information. At this point is the information about books to be purchased lost? No, certainly not. Then how is this information moved from page to page? The browser maintains a session with the Web server and sends the state information to the Web server with each request to maintain the session, regardless of whether that information is about a book's title or the credit card details. In the case of RPC, context handles manage the state in a similar fashion. The state information is usually termed server’s context, which clients can use to identify a server for their individual RPC sessions.
It’s important to note that the context handle always represents information relevant to the sever side of the communication, but the client can always use it to pass some information to the server. Let’s say a server manages a number of files at the request of several clients. In this case, the server may use the file handle (which is unique on the server side) as the context handle. When a client sends a request, it also needs to send a context handle to tell the server which file to operate on -- which is, in fact, a valid file handle on the server side. In essence the client does not actually get the file handle itself; it gets an opaque token that the server RPC run time can uniquely associate with the file handle. Mostly, a context handle points to a block of memory on the server where the server keeps any management information.
Next: Types of Binding Handles >>
More .NET Articles
More By Digvijay Chauhan