Skip to main content
Skip table of contents

Explicit Request Contexts

Request contexts allow a client to send additional data to the server without having to include this data as input parameters in the operation’s Slice definition. They provide a lightweight mechanism for passing metadata alongside normal request arguments.

The Ice context demo provides a complete example of using request context in C#.

Using the Slice greeter definitions once again:

SLICE
module VisitorCenter
{
    interface Greeter
    {
        string greet(string name);
    }
}

A client application can set a request context to send additional metadata:

C#
// We request a French greeting by setting the context parameter.
string greeting = await greeter.GreetAsync(
    name,
    context: new Dictionary<string, string> { ["language"] = "fr" });

On the server side, the request context is available through the ctx member of the Ice.Current parameter:

C#
public override string Greet(string name, Ice.Current current)
{
    // We retrieve the value for the language entry in the context.
    if (!current.ctx.TryGetValue("language", out string? language))
    {
        language = "";
    }
    ...
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.