WebOperationContext.current和HttpContext.Current的区别 [英] Difference between WebOperationContext.current and HttpContext.Current

查看:879
本文介绍了WebOperationContext.current和HttpContext.Current的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我developps的web应用程序,并为我的客户提供移动应用程序。在我的木构建筑很多都ressources网络接入和移动接入之间共享。一个aspx页面可以显示在网络和打电话的移动应用程序的Web视图。我的问题是:

I developps a web app and a mobiles apps for my customers. In my architecure many ressources are shared between the web access and mobile access. An aspx page can be shown on web and called to a web view in mobile app. My question is :

什么是WebOperationContext.current和HttpContext.Current对象之间的区别?
从我的理解是相同的对象,但我注意到,WebOperationContext.current等于在某些情况下空,但我不知道为什么。

What is the difference between WebOperationContext.current and HttpContext.Current object ? from my understanding it was the same object, but i noticed that WebOperationContext.current equal to null in some cases but i don't know why

推荐答案

WebOperationContext 典型地在WCF休息方法使用,因此该方法可以在传入请求和输出响应

WebOperationContext is typically used in a WCF REST method so that method can access the incoming request and outgoing response.

的HttpContext 通常是在ASP.NET WebForms的页面或web方法ASMX Web服务,当传入请求和传出响应可以访问使用。

HttpContext is typically used in an ASP.NET WebForms page or web method for ASMX Web Service, when incoming request and outgoing response can be accessed.

它们是针对不同的项目类型(WCF REST / ASP.NET WebForms的),所以你不应该在一个错误的项目类型中使用它们。

They are designed for different project types (WCF REST/ASP.NET WebForms) so you should not use them in a wrong project type.

关于在 .Current 的值为,这是更加复杂。即使你是调用正确的项目类型此属性,您需要确保呼叫在一个适当的线。仅在处理该请求(其还发送出响应)线程可以访问当前上下文。任何其他线程(后台线程,或创建新的线程),你得到。这已经相识多年,但入门者却搞错了,有时。

About when the value of .Current is null, that's even more complicated. Even if you are calling this property in the correct project type, you need to make sure the call is made on a proper thread. Only on the thread that handles the request (which also sends out the response) you can access the current context. On any other threads (background threads, or new threads created by you) you get null. This has been known for years but beginners still get it wrong sometimes.

这篇关于WebOperationContext.current和HttpContext.Current的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆