1

I've been doing some work extending the WCF pipeline of my service using mainly IOperationInvoker to implement my own functionality.

I am currently using System.Web.HttpContext.Current.Items to store some variables that I want to be be persisted and available throughout the lifetime of my request (pre method invokation, during webserice method, post method invokation).

This works fine when using the HTTP binding, however, I now need to enable TCP and NamedPipes bindings where the System.Web.HttpContext.Current.Items bag obviously isn't available.

Is there a better place to be storing variables that I only want to be in scope for the current request?

Thanks David

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
DavidReid
  • 449
  • 1
  • 5
  • 21

2 Answers2

3

I believe you need to be linked to OperationContext not HttpContext. The answer to similar question is already presented here.

Basically you just need to implement IExtension and plug it into WCF. Step-by-step example can be found for example here.

Community
  • 1
  • 1
milanio
  • 4,082
  • 24
  • 34
0

You can setup your service to be Instance context mode of persession.

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
public class MyService : IMyService
{
    private string sessionVar;         // for each session
}

And then it is up to client to keep the session alive. In your client you can create a proxy at class level and only close it when you are done with it that way you have sessionVar available.

Hakunamatata
  • 1,275
  • 13
  • 18
  • Hi, thanks for this. Unfortunately, I don't think it's quite what I'm after. I only want the variables to be available for the lifetime of the current request, I do not want them to be available in any subsequent requests. Really, I'm asking is there a equivalent of System.Web.HttpContext.Current.Items which works across all bindings (not just HTTP). – DavidReid Jul 02 '15 at 09:20