简体   繁体   中英

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 ?

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"];
var yourData=HttpContext.Current.Application["data"];

请记住,如果你要在服务器场上部署服务,你可能会遇到问题,因为Application是inProc,每个服务器都有自己的Application变量

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM