Service Host User State

The service host enables an application to associate state data that is scoped at the service-host level. This state is is specified by a WS_SERVICE_PROPERTY structure that is passed to the WsCreateServiceHost function when the application creates a service host, as illustrated in the following example.

void* quotePtr = (void*) quotes;
WS_SERVICE_PROPERTY serviceProperties[1] = {0};
serviceProperties[0].id = WS_SERVICE_PROPERTY_HOST_USER_STATE;
serviceProperties[0].value = &quotePtr; // assume this is some state that you want to associate with the service host
serviceProperties[0].valueSize = sizeof(quotePtr);

The state data is available to all service host callbacks and service operations. Callbacks and service operations retrieve the information by calling the WsGetOperationContextProperty function and specifying the context, referenced by the WS_OPERATION_CONTEXT structure, and the context property, as one of the values of the WS_OPERATION_CONTEXT_PROPERTY_HOST_USER_STATE eunumeration, as illustrated in the following example.

QuoteTable* table = NULL;
HRESULT hr = NOERROR;
if (FAILED (WsGetOperationContextProperty (context, WS_OPERATION_CONTEXT_PROPERTY_HOST_USER_STATE, &table, sizeof(table), NULL, error)))
    return hr;