2012-12-10 83 views

回答

1

最後,我的一個拼貼找到了答案,謝謝Sandesh和團隊!

您需要添加截獲每個HTTP請求的IHttpModule並解壓縮數據

/// <summary> 
    /// This class Handles various pre-conditions which has to performed before processing the HTTP request. 
    /// @author XXXXX 
    /// </summary> 
    public class PreRequestHandler : IHttpModule 
    { 
     public void Dispose() 
     { 
      throw new NotImplementedException(); 
     } 

     public void Init(HttpApplication httpContext) 
     { 
      httpContext.BeginRequest += DecompressReceivedRequest; 
     } 

     /// <summary> 
     /// Decompresses the HTTP request before processing it. 
     /// </summary> 
     /// <param name="sender"></param> 
     /// <param name="e"></param> 
     void DecompressReceivedRequest(object sender, EventArgs e) 
     { 
      HttpApplication httpApp = (HttpApplication)sender; 

      if ("gzip" == httpApp.Request.Headers["Content-Encoding"]) 
      { 
       httpApp.Request.Filter = new GZipStream(httpApp.Request.Filter, CompressionMode.Decompress); 
      } 

     } 
    } 

此外,需要在web.config文件中

<!-- Configuration setting to add Custom Http Module to handle various pre-conditions which has to performed before processing the HTTP request.--> 
    <system.webServer> 
    <modules> 
     <add name="PreRequestHandler" type="Your service class.PreRequestHandler"/> 
    </modules> 
    </system.webServer> 
+0

見另一個問題添加下面的條目: http://stackoverflow.com/questions/13548220/android-compressed-requests-to-wcf-rest-service-in-iis?rq=1 –