如何序列化 httpcontext 对象并从 asp.net 服务器控件通过 webservice 传递?
我想通过 webservice 传递 httpcontext 对象,方法是从 asp.net 服务器控件序列化它。但它不适用于服务器控制。它正在与网络应用程序一起使用。请帮助我找到解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
HttpContext.Current
对象从 Web 应用程序传递到 Web 服务或此类通信的任何其他组合是没有意义的。HttpContext
类及其静态成员Current
应该在 IIS 内运行的 Web 应用程序或 Web 服务中可用并已初始化。如果您的 Web 服务配置为在另一个应用程序池或 IIS 中的另一个应用程序内运行,您的
current
将返回与 Web 前端的Current
不同的内容。如果您需要传递一些属性,例如用户名、响应或请求标头等,请传递一堆参数或创建您自己的类来托管您需要的所有内容,但不要直接传递上下文。
在某些情况下,如果您无法检索上下文或会话,则可能是您编码错误;例如,HttpHandler 仅在实现 IRequireSessionState 且将 HttpContext 对象作为 ProcessRequest 方法的参数传递给处理程序时才正确使用 Session。
我认为一般来说总有一种解决方法,或者您的设计和架构不正确,但不需要您自己将上下文从一层传递到另一层。
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 memberCurrent
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 theCurrent
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 theHttpContext
object is passed to an handler as parameter of theProcessRequest
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.