大网数据广告活动
网络与域名解析

Maintaining State on the Server Between Calls

· 52CE 我爱测

It is often necessary to maintain state on the server between separate RPC calls \ 8212;using context handles is the best way to do so. A few words about how context handles operate internally helps in understanding when context handles work best.

It is often necessary to maintain state on the server between separate RPC calls—using context handles is the best way to do so. A few words about how context handles operate internally helps in understanding when context handles work best.

The client never receives the state kept on the server. Most often the state on the server is a pointer to a memory block, and the client has no information about it. All the client receives is a large unique number, with other information associated with it, that the server sends to the client and which represents the context handle in all subsequent operations. Whenever the client refers to an opened handle, it sends the large number it received from the server when that context handle was opened.

The server keeps track of all large numbers it sends to a client. When the server receives a large number representing a context handle, it looks up the number in the collection of valid, outstanding context handles for that client, and finds the server-side context corresponding to a given large number. This is passed to the server routine. If the large number is not found, an RPC_X_SS_CONTEXT_MISMATCH exception is raised and propagated to the client.

The corollaries of this design are as follows:

  • A context handle is valid only in the context of the existing client/server session. It cannot be passed to another client.
  • A context handle becomes invalid if the server is rebooted, or otherwise loses its connection to the client.
  • The client cannot interpret what the context handle represents on the server. To a client, all context handles are simply large numbers.

If the client fails, the server will get a notification and will clean up its context handles using the run-down mechanism.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。