1
我們有一個WCF-REST服務,客戶端使用Content Encoding = gzip發送數據並以gzip格式壓縮數據。但是,我們無法從WCF服務中收到的請求中解壓縮表單數據。WCF REST服務 - 如何使用gzip解壓縮表單數據?
我們有一個WCF-REST服務,客戶端使用Content Encoding = gzip發送數據並以gzip格式壓縮數據。但是,我們無法從WCF服務中收到的請求中解壓縮表單數據。WCF REST服務 - 如何使用gzip解壓縮表單數據?
最後,我的一個拼貼找到了答案,謝謝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>
見另一個問題添加下面的條目: http://stackoverflow.com/questions/13548220/android-compressed-requests-to-wcf-rest-service-in-iis?rq=1 –