I have a WCF 4.0 restful application hosted on Windows Azure cloud service and I need to know the size of the outgoing HTTP message before it's sent back to the client.
I need that because I want to bill my service customers by bandwidth consumption.
I have two methods as shown below and both have the token parameter that identifies the client. So, when the client calls any method, I need to discover the size of the response and register the bandwidth consumption for that client and method.
That way I'll be able to send an invoice for each customer.
Note that the response may return as XML/JSON and compressed by Gzip either.
Could somebody give me a hand?
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single, Namespace = "")]
public class ZipCodeService
{
[WebGet(UriTemplate = "/GetAddressByZipCode?token={token}&zipcode={zipcode}")]
public GetAddressByZipCodeContract GetAddressByZipCode(string zipCode, string token)
{
// ...
}
[WebGet(UriTemplate = "/GetZipCodeByAddress?token={token}&keywords={keywords}")]
public GetZipCodeByAddressContract GetZipCodeByAddress(string keywords, string token)
{
// ...
}
}
When I try to get the http response, but it is compressed by Gzip, the content-length header returns null, otherwise it returns normally. How can I get the content-length even if the response is compressed? Anyway the content-length does not express the total size of the outgoing message, so how can I get the total size of the outgoing message?
public class Global : HttpApplication
{
protected void Application_EndRequest(object sender, EventArgs e)
{
var response = this.Response;
var str = response.Headers["Content-Length"];
}
}
Any help will be really appreciated.
Regards,
Fernando Môra