Tuizi
Tuizi

Reputation: 1673

Read Global Application property from WCF Service

I'm using in my Global.asax class the object Application to store data.

Application.Set("data", "test");

Now, in my WCF Service, I want to be abble to read this property. How can I do that?

Application["data"];

In debug, I can see my global.asax is called (Begin_Request), but in my webservice's method, how can I access to this Application?

Upvotes: 2

Views: 3673

Answers (2)

Kevin Won
Kevin Won

Reputation: 7186

in order to get the HttpContext.Current working with wcf you gotta turn on compatibility:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

then you can get access as Massimiliano Peluso suggests:

// in the wcf service
var yourData=HttpContext.Current.Application["data"];

Upvotes: 4

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

var yourData=HttpContext.Current.Application["data"];

bear in mind anyway thay if you will deploy the Service on a Server Farm you could have issues as the Application is inProc and each server will have its own Application variable

Upvotes: 4

Related Questions