开发者

ASP.NET WebService response compression

How do I compress the output data from a web service (web method). The output is XmlDocument type.

Here is the code.

[WebMethod]
public XmlDocument GetPersonalInfo(int CustomerID)
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(new CustomersXML().GetPersonalInfo(CustomerID));
    return doc;
}

How do I Gzip this response. Please remember that it is not a page (HTTP call) its a web service that is being cal开发者_如何学运维led from a Flex client.

Thanks


This answer references an ancient article explaining how to implement this programmatically using SharpZipLib.

Another answer demonstrates use of the System.IO.Compression classes which could be substituted for SharpZipLib.

Rick Strahl put together an article reviewing potential issues to be aware of when implementing compression which do not appear to be addressed in the examples provided above. He also links to an article providing more details on usage of IIS7 built-in compression.


go to your iis or whatever config file, and add the following line in the appropriate place:

<add mimeType="application/json" enabled="true" />

i've had the same problem - my IIS was able to GZIP any http response, except for json responses (which where needed a gzip compression the most on my app).

hope that helps

Update: the application host config file should be located here: %windir%\System32\inetsrv\config


I don't have time to look for code but there is a namespace System.IO.Compression that has several classes for both Gzip and Deflation-based compression schemes. Gzip is probably a safer bet for cross-language communication as I'm not certain as to how widespread deflation compression is.

However, you shouldn't have any trouble in the communication so long as there is a header with the SOAP packet telling the client server to decompress the stream.

Note: Double check your server settings before doing this though, as some hosts have Gzip turned on by default and you don't want to do it twice.


This is nothing to do with .NET.

GZIP is an HTTP feature in Web Server - provided the client supports it which generally notifies the server by sending GZIP in the ACCEPT headers when sending the request.

You need to set it up in IIS. Depending on the version, it can be different. In IIS 7 it is very easy, just a flag to set. See here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜