C# webservice可以';无法获取gzip请求数据

C# webservice可以';无法获取gzip请求数据,c#,wcf,web-services,gzip,content-type,C#,Wcf,Web Services,Gzip,Content Type,我试图解码一个gzip请求,该请求被发送到内容类型为application/x-gzip的webservice 我已经实现了一个HttpHandler,它添加了一个GZip解压缩过滤器,它似乎正在工作。代码如下: void context_BeginRequest(object sender, EventArgs e) { HttpApplication app = sender as HttpApplication; HttpContext ct

我试图解码一个gzip请求,该请求被发送到内容类型为application/x-gzip的webservice

我已经实现了一个HttpHandler,它添加了一个GZip解压缩过滤器,它似乎正在工作。代码如下:

    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication app = sender as HttpApplication;
        HttpContext ctx = app.Context;

        if (!ctx.Request.Url.PathAndQuery.ToLower().Contains(".asmx"))
            return;

        // test
        if ("gzip" == ctx.Request.Headers["Content-encoding"])
        {
            app.Request.Filter = new GZipStream(app.Request.Filter,
               CompressionMode.Decompress);
        }

        if (IsEncodingAccepted("gzip"))
        {

            app.Response.Filter = new GZipStream(app.Response.Filter,
      CompressionMode.Compress);
            SetEncoding("gzip");
        }
        else if (IsEncodingAccepted("deflate"))
        {
            app.Response.Filter = new DeflateStream(app.Response.Filter,
      CompressionMode.Compress);
            SetEncoding("deflate");
        }
    }
    private bool IsEncodingAccepted(string encoding)
    {
        return HttpContext.Current.Request.Headers["Accept-encoding"] != null &&
          HttpContext.Current.Request.Headers["Accept-encoding"].Contains(encoding);
    }
    private void SetEncoding(string encoding)
    {
        HttpContext.Current.Response.AppendHeader("Content-encoding", encoding);
    }
不幸的是,我一直都会遇到这样的错误:

System.ServiceModel.ProtocolException: Content Type application/x-gzip was not supported by service https://127.0.0.1/ModuloWS.asmx.  The client and service bindings may be mismatched. ---> System.Net.WebException: The remote server returned an error: (415) Unsupported Media Type.
在System.Net.HttpWebRequest.GetResponse()中 位于System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时) ---内部异常堆栈跟踪的结束---

我一整天都在为此发疯


另外,请求正在使用从MSDN网站上的WCF示例项目中提取的GZipMessageEncoder进行GZip编码。

此错误远远超出了您的代码。它在WCF框架级别反弹,表示您的服务未配置为接受内容类型“application/x-gzip”。要解决此问题,请将WCF配置为允许所述内容类型。关于如何做到这一点的信息分散在整个网络中,但是。从MSDN获得示例代码的地方可能也有启用gzip的示例配置。

我认为问题在于该服务是常规的.NET web服务,但客户端是WCF客户端。我需要找到一种在服务器端(常规Web服务)上配置它的方法。。。你有什么想法吗?