Monday, March 26, 2012

Accessing ASP.NET Session object during calls to Web Service Bridge?

Hi there,

Just getting started with the Web Service Bridge, looking at the MSN search example.

I've built my own Atlas enabled ASP.NET web application and created a .asbx file that points to an external Web Service and I can call methods on the Web Service through the class I derived from BridgeHandler, so all looking good.

Now I want to be able to make my BridgeHandler derived class interact with the ASP.NET Session object to set and retrieve session data from within my ASP.NET web application.

I can't see a way I can get at the Session object once I'm in my BridgeHandler derived class? Is this possible, or is there a way the Session or Context object can be passed as a parameter to my BridgeHandler derived class through the .asbx file?

I notice the MSN example uses the following syntax to pass a value stored in the Web.config as a parameter:

<parameter name="appId" value="% appsettings : MSNWalkthroughAppId %" serverOnly="true" /
Is there simlar syntax for passing the Session object? Are the options for what you can do in between the %% tags documented anywhere?

Thanks,

Mark

Hi Mark,

Right now we don't support an expression for session within %%, but we will consider adding it in the future. You can get access to Session thru HttpContext, which you can access thru HttpContext.Current...

In terms of expressions currently supported:

args: request args
appsettings: config
resultschain: see quickstart on chaining bridges declaratively
querystring: useful if you use HTTP get to make your bridge requests

Hope that helps,
-Hao


Doh, actually it turns out you can't access Session thru HttpContext.Current because we aren't emitting the proper interface on the generated class, so we'll definitely need to enable this in a future release, but at this time you unfortunately don't have any way to get to the session data...


Thanks for the response. I've just install the April release of Atlas and it doesn't appear to be in there yet either. Looks like I'll have to wait and in the meantime keep experimenting with other parts of Atlas.

Don't suppose you can give me any idea roughly when this feature will be included? (a bit hopeful I know :-)

BTW - does the current 'Context' object on the BridgeHandler class do anything useful at this stage? I get an exception 'Accessing context too early, it is null' exception when attempting to use that object.

Cheers,

Mark

Unfortunately this came up too late to get into the April CTP, but most likely we will get it in the next CTP...

You should be able to access the BridgeHandler.Context from within any of the bridge pipeline methods, basically the first thing that BridgeHandler.Invoke does is build the Context, so within the other virtual methods that you override, you should be able to access the BridgeContext, where are you trying to use the Context object?

Hope that helps,
-Hao

No comments:

Post a Comment