asp.net web服务处理gzip的COM pressed要求 [英] asp.net webservice handling gzip compressed request

查看:153
本文介绍了asp.net web服务处理gzip的COM pressed要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.asmx web服务的书面处理来自第三方工具请求一个asp.net。第三方工具发出HTTP POST请求的web服务,以获取用户信息。我使用的IIS7

与删除所有编码签跑提琴手,我可以看到Web服务调用和一切工作正常。如果我取消选中删除所有编码中,Web服务调用失败,出现400错误的请求。我看到的不同的是,报头。内容编码:gzip正在被拉琴除去内容正在DECOM pressed

所以,当content-encoding头被删除,内容DECOM pressed,我的web服务的功能完好。当标题为present和内容为com pressed,web服务失败。

我怎样才能既:


  1. 配置我的web告诉客户端,它不会接受COM pressed请求(希望第三方工具尊重的)

  2. DECOM preSS在asp.net年初该内容的处理

  3. 修改我的web服务与COM pressed数据进行工作

更新:要清楚,我并不需要配置gzip编码的响应,我需要处理一个请求,我的web服务是gzip的EN codeD

更新2 :第三方工具是Salesforce.com的Outlook插件。所以,我没有获得修改它,它是由许多其他公司没有的麻烦。它有要的东西我做(或不做)

更新3 :我发现一个职位这里说,IIS不支持与COM $ p $传入POST请求pssed数据,它只支持COM pressed回应。这仍然可以是真的吗?


解决方案

我已经找到了部分答案的这里

 类DECOM pressStream:流
{
    ...    公共覆盖INT读(字节[]缓冲区,诠释抵消,诠释计数)
    {
        GZipStream测试=新GZipStream(_sink,COM pressionMode.Decom preSS);        INT C = test.Read(缓冲区,偏移数);        返回℃;
    }    ...
}

然后我就可以指定这样的请求对象上的过滤器:

 无效的Application_BeginRequest(对象发件人,EventArgs的发送)
    {
        字符串contentEncoding = Request.Headers [内容编码];
        流prevCom pressedStream = Request.Filter;        如果(contentEncoding == NULL || contentEncoding.Length == 0)
            返回;        contentEncoding = contentEncoding.ToLower();        如果(contentEncoding.Contains(gzip的))
        {
            Request.Filter =新DECOM pressStream(Request.Filter);
        }
    }

我说的部分答案,因为即使我现在可以处理传入的请求,响应得到一个内容编码:gzip头即使响应不带codeD。我可以小提琴手验证内容不带codeD。

如果我不带code的响应,为Web服务客户端失败。看来,即使它正在发送接受编码:gzip,但事实上并不接受gzip的COM pressed响应。我可以确认的小提琴手响应是COM pressed和提琴手将DECOM preSS它成功。

所以,现在我卡试图让流浪内容编码:gzip头从响应中删除。我已经从应用程序的web.config文件,并删除IIS的所有引用我可以找到COM pression。

I have an asp.net .asmx webservice written to handle requests from a third party tool. The third party tool makes an http POST request to the webservice to get user information. I'm using IIS7

Running Fiddler with "Remove All Encodings" checked, I can see the webservice call and and everything functions properly. If I uncheck "Remove All Encodings", the webservice call fails with a 400 Bad Request. The difference I see is that the header "Content-Encoding: gzip" is being removed by Fiddler and the content is being decompressed.

So, when the Content-Encoding header is removed and the content is decompressed, my webservice functions perfectly. When the header is present and the content is compressed, the webservice fails.

How can I either:

  1. Configure my webservice to tell the client that it won't accept compressed requests (and hope that the third party tool respects that)
  2. Decompress the content early in the asp.net handling
  3. Modify my webservice to work with compressed data

Update: To be clear, I don't need to configure gzip encoding in the Response, I need to deal with a Request TO my webservice that is gzip encoded.

Update 2: The third-party tool is the Salesforce.com Outlook plugin. So, I don't have access to modify it and it is used by many other companies without trouble. It's got to be something I'm doing (or not doing)

Update 3: I found one post here that says that IIS does not support incoming POST requests with compressed data, it only supports compressed Responses. Can this still be true?

解决方案

I've found a partial answer here.

class DecompressStream : Stream
{
    ...

    public override int Read(byte[] buffer, int offset, int count)
    {
        GZipStream test = new GZipStream(_sink, CompressionMode.Decompress);

        int c = test.Read(buffer, offset, count);

        return c;
    }

    ...
}

I can then specify the filter on the request object like this:

void Application_BeginRequest(object sender, EventArgs e)
    {
        string contentEncoding = Request.Headers["Content-Encoding"];
        Stream prevCompressedStream = Request.Filter;

        if(contentEncoding == null || contentEncoding.Length == 0)
            return;

        contentEncoding = contentEncoding.ToLower();

        if(contentEncoding.Contains("gzip"))
        {
            Request.Filter = new DecompressStream(Request.Filter);
        }
    }

I say partial answer because even though I can now process the incoming request, the response is getting a "Content-Encoding: gzip" header even though the response is not encoded. I can verify in Fiddler that the content is not encoded.

If I do encode the response, the client for the webservice fails. It seems that even though it is sending "Accept-Encoding: gzip", it does not in fact accept gzip compressed response. I can verify in Fiddler that the response is compressed and Fiddler will decompress it successfully.

So, now I'm stuck trying to get a stray "Content-Encoding: gzip" header removed from the response. I've removed all references I can find to compression from the application, the web.config, and IIS.

这篇关于asp.net web服务处理gzip的COM pressed要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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