Krishna Yadav
Krishna Yadav

Reputation: 33

How to Serialize httpcontext Object and passing through webservice from an asp.net server control?

I want to pass httpcontext object through webservice by serializing it from an asp.net server control . but it is not working with server control. It is working with webapplication. Please help me in finding the solutions.

Upvotes: 0

Views: 1215

Answers (1)

Davide Piras
Davide Piras

Reputation: 44605

It does not make sense to pass that HttpContext.Current object from the web application to the web service or any other combinations of such communication.

The HttpContext class and its static member Current are supposed to be available and initialized for you in web application or web services running inside IIS.

if your web services are configured to run inside another app pool or another application in IIS from there your current will return something different than the Current of the web front end.

if you need to pass some properties like User name, Response or Request headers and so on pass a bunch of parameters or create your own class to host all you need but do not pass the context directly.

In some cases if you are unable to retrieve the context, or the session, could be that you are coding something wrong; for example HttpHandlers properly use the Session only when implementing IRequireSessionState and the HttpContext object is passed to an handler as parameter of the ProcessRequest method.

I think in general there is always a way around or your design and architecture are not proper but without need to pass the context by yourself from one layer to the other.

Upvotes: 1

Related Questions