Instead of passing a context explicitly with an invocation, you can also use a per-proxy context. Per-proxy contexts allow you to set a context on a particular proxy once and, thereafter, whenever you use that proxy to invoke an operation, the previously-set context is sent with each invocation.
On this page:
Configuring a Per-Proxy Request Context Programmatically
The proxy methods
ice_getContext set and retrieve the context, respectively. The Slice definitions of these methods would look as follows:
ice_context creates a new proxy that stores the given context. Calling
ice_getContext returns the stored context, or an empty dictionary if no per-proxy context has been configured for the proxy.
Here is an example in C++:
As the example illustrates, once we have created the
p2 proxy, any invocation via
p2 automatically sends the configured context. The final line of the example shows that it is also possible to explicitly send a context for an invocation even if the proxy is configured with a context — an explicit context always overrides any per-proxy context.
Note that, once you have set a per-proxy context, that context becomes immutable: if you subsequently change the context you have passed to
ice_context, such a change does not affect the per-proxy context of any proxies you previously created with that context because each proxy on which you set a per-proxy context stores its own copy of the dictionary.
Configuring a Per-Proxy Request Context using Properties
You can also configure a context with proxy properties when you use the communicator operation
propertyToProxy. Suppose we obtain a proxy like this:
We can statically configure a context for this proxy using the following properties:
The proxy returned by
propertyToProxy already contains the context key/value pairs specified in the configuration properties. To make any modifications to the context at run time, you'll need to retrieve the proxy's context dictionary using
ice_getContext, modify the dictionary as necessary, and finally obtain a new proxy by calling
ice_context, as we described above.