---
title: Create a new web context
summary: Create a brand-new web context via the remote WCF service and cache it in session.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-09-17
library: SAIF.Framework.Web.Mvc
reference_type: package
operation_id: OP-03
trigger: "[BR-04](../business-rules.md#br-04-cross-application-arrival-inherits-the-referring-context) cross-application arrival referenced by OP-01 step 6, or `Get(contextId)` on cache miss"
---

# Create a new web context

Create a brand-new web context via the remote WCF service and cache it in session. Trigger: [BR-04](../business-rules.md#br-04-cross-application-arrival-inherits-the-referring-context) cross-application arrival referenced by OP-01 step 6, or `Get(contextId)` on cache miss.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-03 |
| **Trigger** | [BR-04](../business-rules.md#br-04-cross-application-arrival-inherits-the-referring-context) cross-application arrival referenced by OP-01 step 6, or `Get(contextId)` on cache miss |
| **Inputs** | Optional context id; `serviceUrl` from session key `ContextServiceUrl` |
| **Outputs** | `IWebContext`; session cache updated |
| **Primary components** | `WebContextService.Get()` calling private `CreateContext(string contextId = null)` |
| **Entry point** | `src/Web/WebContextService.cs` |

## Steps

1. Open a `WebContextServiceClient` over `BasicHttpBinding` at `serviceUrl` inside a `using` block (channel disposed on exit).
2. Call `Channel.CreateContext(contextId)` on the remote WCF `IWebContextService` — the remote implementation is not part of this repository.**
3. `items.UpdateOrAdd(context.ContextId, context)` — store the returned context in the session-backed dictionary under session key `WebContextRepository` ([BR-09](../business-rules.md#br-09-every-resolved-context-is-cached-by-id)).
4. Return the context.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([Trigger])
	Open[Open WebContextServiceClient]
	Call[Channel.CreateContext]
	Cache[Cache in session under WebContextRepository]
	EndOk([Return context])
	Start --> Open
	Open --> Call
	Call --> Cache
	Cache --> EndOk
```

## Failure and edge-case behavior

- No unexpected failure paths beyond argument-guard exceptions and delegated dependency behavior were identified for this operation.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts. Statements marked with `**` could not be confirmed; treat
> as unknown until verified.


## Sources
- `src/Web/WebContextService.cs`
- `src/Web/WebContextServiceClient.cs`
