Use ISAPI filter to track and time WCF call?
I am creating a web application using WCF that will be used by other applications as a service. Our application will be installed on a web services farm and load balanced to scale. Sometimes we run into problems specific to one web server and we would like to be able to determine from the response which web server handled the request and possibly the time information. For example, this request was processed by WebServer01 and the request took 200ms to complete.
The first solution that came to mind was to create an ISAPI filter to add an HTTP header that stores this information in the response. It strikes me as something that someone should have done before. Is there a better way to do this, or an out-of-the-box ISAPI filter I can use to do this?
Thanks in advance
a source to share
WCF offers much better extension points than ISAPI filters. You can, for example, create a client-side message inspector that gets called just before the message leaves the server and then also gets called when a response is returned and hence you can quite easily measure the time it takes to invoke the service from the client's point of view ...
Check the interface IClientMessageInspector
- this might be what you are looking for. Also see this excellent blog post on how to use this interface.
Mark
a source to share
I don't have a ready-made solution for you, but I can point you to the IHttpModule . See the code in for example, Tool and Monitor for ASP.NET Applications Using WMI and MOM 2005 .
private DateTime startTime;
private void context_BeginRequest(object sender, EventArgs e)
{
startTime = DateTime.Now;
}
private void context_EndRequest(object sender, EventArgs e)
{
// Increment corresponding counter
string ipAddress = HttpContext.Current.Request.
ServerVariables["REMOTE_ADDR"];
if (HttpContext.Current.Request.IsAuthenticated)
authenticatedUsers.Add(ipAddress);
else
anonymousUsers.Add(ipAddress);
// Fire excessively long request event if necessary
int duration = (int) DateTime.Now.Subtract(
startTime).TotalMilliseconds;
if (duration > excessivelyLongRequestThreshold)
{
string requestPath=HttpContext.Current.Request.Path;
new AspNetExcessivelyLongRequestEvent(applicationName,
duration,requestPath).Fire();
}
}
a source to share