Visual Studio 2012 安装破坏了我的 2010 WCF 项目 [英] Visual Studio 2012 install broke my 2010 WCF project

查看:65
本文介绍了Visual Studio 2012 安装破坏了我的 2010 WCF 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 VS 2012 并且在一些 Web 项目中成功使用了它,但是它的某些功能导致我的 Web 服务项目中断.我在web服务项目上还在用VS 2010,2012年还没开过.

一切都可以编译并正常工作,除非它尝试在我引用的博客项目中创建类的实例,然后抛出此错误:

调用 HttpRequest.GetBufferlessInputStream 后不支持此方法或属性.

我在项目中找不到任何明确使用 GetBufferlessInputStream 的地方.

如果我跳过博客代码,一切都会正确执行.

我找不到其他收到此错误的人来尝试缩小范围,有什么想法可以从哪里开始吗?

堆栈

 在 System.Web.HttpRequest.get_InputStream()在 OAS.Web.Log.WebEvent..ctor(EventType type, HttpContext context, String applicationName)在 OAS.Web.Log.WebTrace..ctor(HttpContext context, String applicationName)在 OAS.Web.AdvisorServices.Extensions.OperationLoggerParameterInspector.BeforeCall(String operationName, Object[] 输入) 在 C:\SourceControl\OAS\IM.NET3.0\Web\AdvisorServices\OAS.Web.AdvisorServices.Extensions\OperationLogger\OperationLoggerParameterInspector.cs:第 54 行



**编辑 - 额外问题

为什么这些 Framework 4.5 属性会影响我的 4.0 解决方案?

解决方案

注意: 此问题已在 .net 4.5.1 中修复.你可以看到 4.5.1 的修复.拥有 .net 4.5.1 后,添加以下 appSetting 以切换回旧行为.

<预><代码><配置><应用设置><add key="wcf:serviceHostingEnvironment:useClassicReadEntityBodyMode" value="true"/></appSettings></配置>

以下是创建 HttpModule 以强制 ReadEntityBodyMode 为经典"的方法:http://blogs.msdn.com/b/praburaj/archive/2012/09/13/accessing-httpcontext-current-request-inputstream-property-in-aspnetcompatibility-mode-throws-exception-this-method-or-property-is-not-supported-after-httprequest-getbufferlessinputstream-has-been-invoked.aspx

回答您的另一个问题(为什么这些 Framework 4.5 属性会影响我的 4.0 解决方案?):.net 4.5 是 .net 4.0 的就地升级.因此,即使您的项目以 4.0 为目标,由于 VS 2012 安装了 4.5 运行时,4.5 的某些行为会生效.

编辑

博客条目:

在 .net 4.5 WCF 中利用无缓冲输入流来获得可扩展性优势.因此,当您尝试访问 HttpContext.Current.Request.InputStream 属性时,您可能会遇到以下异常,因为 InputStream 属性试图让您处理经典流,因为它们都不兼容.

<块引用>

之后不支持此方法或属性HttpRequest.GetBufferlessInputStream 已被调用."

如果您有一个运行良好的 WCF 4.0 应用程序,但在将您的 .net 框架升级到 4.5 时,您会注意到该服务无法访问此属性,以下是解决此问题的方法:

  • 在同一个 WCF 项目中添加一个简单的 HttpModule,它将在 WCF 读取每个请求之前访问 InputStream 属性,以便它强制 HttpContext.Request.ReadEntityBody 为经典"并确保兼容性.

    公共类 WcfReadEntityBodyModeWorkaroundModule : IHttpModule{公共无效处置(){}公共无效初始化(HttpApplication上下文){context.BeginRequest += context_BeginRequest;}void context_BeginRequest(对象发送者,EventArgs e){//这将强制 HttpContext.Request.ReadEntityBody 为经典"并确保兼容性..流流 = (发送方为 HttpApplication).Request.InputStream;}}

  • 通过在 设置中添加这些行,在您的 web.config 中注册此模块.

    <模块><!-- 注册托管模块--><add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly"/></模块>

  • 如果您在经典模式下使用应用程序池,则需要将该模块添加到 web.config 中的此部分:

    <http模块><add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly"/></httpModules>

如果你的项目不能修改,那么你可以把这个Http模块写在一个单独的程序集中,单独GAC并在web.config中注册这个模块.

现在尝试访问它应该为您成功的服务!

I've installed VS 2012 and am successfully using it on some web projects, but something with it has caused my web service project to break. I'm still using VS 2010 on the web service project and have not opened it in 2012.

Everything compiles and works correctly except when it tries to create an instance of a class in my referenced weblog project, then it throws this error:

This method or property is not supported after HttpRequest.GetBufferlessInputStream has been invoked.

I can not find anywhere in the project where GetBufferlessInputStream is used explicitly.

If I jump over the weblog code, everything executes correctly.

I can't find anyone else who has received this error to try and narrow it down, any ideas where to start?

Stack

   at System.Web.HttpRequest.get_InputStream()
   at OAS.Web.Log.WebEvent..ctor(EventType type, HttpContext context, String applicationName)
   at OAS.Web.Log.WebTrace..ctor(HttpContext context, String applicationName)
   at OAS.Web.AdvisorServices.Extensions.OperationLoggerParameterInspector.BeforeCall(String operationName, Object[] inputs) in C:\SourceControl\OAS\IM.NET3.0\Web\AdvisorServices\OAS.Web.AdvisorServices.Extensions\OperationLogger\OperationLoggerParameterInspector.cs:line 54



**EDIT - Bonus Question

Why are these Framework 4.5 properties affecting my 4.0 solution?

解决方案

Note : This issue has been fixed in .net 4.5.1. You can see the fix with 4.5.1. Once you have .net 4.5.1 add the following appSetting to switch back to the old behavior.

<configuration>      
<appSettings>
      <add key="wcf:serviceHostingEnvironment:useClassicReadEntityBodyMode" value="true" />
</appSettings> 
</configuration>

Here is how you can create a HttpModule to force ReadEntityBodyMode to be "classic" : http://blogs.msdn.com/b/praburaj/archive/2012/09/13/accessing-httpcontext-current-request-inputstream-property-in-aspnetcompatibility-mode-throws-exception-this-method-or-property-is-not-supported-after-httprequest-getbufferlessinputstream-has-been-invoked.aspx

To answer your other question (Why are these Framework 4.5 properties are effecting my 4.0 solution?): .net 4.5 is an in-place upgrade of .net 4.0. So even if your project is targeting 4.0, since VS 2012 installs 4.5 runtime, some of the 4.5 behaviors take effect.

EDIT

Blog Entry:

In .net 4.5 WCF leveraged the buffer less input stream for scalability benefits. As a result when you try to access the HttpContext.Current.Request.InputStream property you may end up with the below exception, as the InputStream property tries to get you handle to the Classic stream as they both are incompatible.

"This method or property is not supported after HttpRequest.GetBufferlessInputStream has been invoked."

If you had a WCF 4.0 app which worked perfectly but on upgrading your .net framework to 4.5 you notice the service failing on accessing this property, here is the way to work-around the issue:

  • Add a simple HttpModule in the same WCF project which will access the InputStream property for each request before WCF reads it so that it will enforce the HttpContext.Request.ReadEntityBody to be "Classic" and will ensure compatibility.

    public class WcfReadEntityBodyModeWorkaroundModule : IHttpModule    
    {    
        public void Dispose() { }
    
        public void Init(HttpApplication context) {    
            context.BeginRequest += context_BeginRequest;    
        }    
    
        void context_BeginRequest(object sender, EventArgs e) {
            //This will force the HttpContext.Request.ReadEntityBody to be "Classic" and will ensure compatibility..    
            Stream stream = (sender as HttpApplication).Request.InputStream;    
        }    
     } 
    

  • Register this module in your web.config by adding these lines in <configuration> <modules> setting.

    <system.webServer>
        <modules>
            <!-- Register the managed module -->
            <add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly" />
        </modules>
    

  • If you are using an app pool in classic mode, you will need to add the module to this section in the web.config:

    <system.web>
        <httpModules>
            <add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly" />
        </httpModules>
    

If your project cannot be modified, then you can write this Http module in a separate assembly, GAC it separately and register this module in the web.config.

Now try accessing the service it should succeed for you!

这篇关于Visual Studio 2012 安装破坏了我的 2010 WCF 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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