使用 ISAPI 过滤器来跟踪和计时 WCF 调用?

发布于 2024-07-20 20:41:39 字数 341 浏览 8 评论 0原文

我正在使用 WCF 构建一个 Web 应用程序,该应用程序将作为服务被其他应用程序使用。 我们的应用程序将安装在 Web 服务场上,并出于可扩展性目的进行负载平衡。 有时,我们会遇到特定于某个 Web 服务器的问题,我们希望能够从响应中确定请求是由哪个 Web 服务器处理的,以及可能的计时信息。 例如,此请求由 WebServer01 处理,该请求花了 200 毫秒才能完成。

我想到的第一个解决方案是构建一个 ISAPI 过滤器来添加一个 HTTP 标头,该标头将该信息存储在响应中。 我觉得这肯定是有人以前做过的事情。 有没有更好的方法来做到这一点,或者我可以使用现成的 ISAPI 过滤器?

提前致谢

I'm building a web application using WCF that will be consumed by other applications as a service. Our app will be installed on a farm of web services and load balanced for scalability purposes. Occasionally we run into problems specific to one web server and we'd like to be able to determine from the response which web server the request was processed by and possibly timing information as well. For example, this request was processed by WebServer01 and the request took 200ms to finish.

The first solution that came to mind was to build an ISAPI filter to add an HTTP header that stores this information in the response. This strikes me as the kind of thing somebody must have done before. Is there a better way to do this or an off-the-shelf ISAPI filter that I can use for this?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒尘 2024-07-27 20:41:39

WCF 提供了比 ISAPI 过滤器更好的扩展点。 例如,您可以创建一个客户端消息检查器,该检查器在消息发送到服务器之前被调用,然后在响应返回时也被调用,因此您可以相当轻松地测量来自客户端的服务调用所需的时间看法。

查看 IClientMessageInspector 接口 - 这可能就是您正在寻找的。 另请参阅这个优秀的 博客条目 如何使用这个界面。

马克

WCF offers much nicer extension points than ISAPI filters. You could e.g. create a client side message inspector that gets called just before the message goes out to the server, and then also gets called when the response comes back, and thus you could fairly easily measure the time needed for a service call from a client perspective.

Check out the IClientMessageInspector interface - that might be what you're looking for. Also see this excellent blog entry on how to use this interface.

Marc

一向肩并 2024-07-27 20:41:39

我没有现成的解决方案供您使用,但我可以向您指出 IHttpModule
请参阅使用 WMI 和 MOM 2005 检测和监视 ASP.NET 应用程序

    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();
        }
    }

I don't have a ready-made solution for you but I can point you towards IHttpModule.
See code in Instrument and Monitor Your ASP.NET Apps Using WMI and MOM 2005 for example.

    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();
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文