进行服务调用时,Request.InputStream为空

Bev*_*vin 3 c# asp.net iis .net-4.5

我正在使用ASP.NET 4.5应用程序,我遇到了一个非常烦人的问题.迁移到VS2012后,我们遇到了与此处相同的问题.给定的解决方案有效,但我现在发现另一个问题正在发生.由于某种原因,报告包含HTTP请求的正文内容的InputStream为空.Content-Length标头声称存在数据,但我无法访问它.

奇怪的是,数据似乎存在于上面链接问题中指定的变通方法模块中,但在模块和API调用之间的某个点处,流被替换为空的流.请参阅以下示例:

public class WcfReadEntityBodyModeWorkaroundModule : IHttpModule
{
    public void Dispose() { }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += context_BeginRequest;
    }

    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication app = sender as HttpApplication;
        //This will force the HttpContext.Request.ReadEntityBody to be "Classic" and will ensure compatibility..

        Stream stream = app.Request.InputStream;
        // This stream has data...
    }
} 

...

    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml)]
    public Dictionary<string,string> SaveAudioFile()
    {
        Stream s = HttpContext.Current.Request.InputStream;
        // ...but this one does not. Request.ContentLength is nonzero, but
        // the InputStream.Length property is zero.
        ...
    }
Run Code Online (Sandbox Code Playgroud)

从配置中删除模块只会在访问流时导致异常,就像之前一样.

有任何想法吗?

Sea*_*ean 5

在其他答案上找到了这个:

Request.InputStream.Position = 0;
Run Code Online (Sandbox Code Playgroud)