如何知道何时响应已完成被发送到客户端? [英] How to know when a response has finished being sent to the client?

查看:144
本文介绍了如何知道何时响应已完成被发送到客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回XML的事件列表一个Web API,Web方法:

I have a Web API web method which returns a list of Events in xml:

public IList<Event> GetAllEvents()
{
...
}

public class Event
{
    public string Name { get; set; }

    public int Id { get; set; }
}

客户端可能会发送一个GET请求和接收将被序列化100事件,以便发生的事情是:

The client may send a GET request and receive 100 events which will be serialized so what happens is that:


  • 请求被GetAllEvents方法获得

  • 的数据由方法中提供

  • 的Web API引擎序列化对象到XML

  • 的Web API引擎发送序列化的数据(这可能是例如5MB)给客户端

整个过程可能需要例如5秒。

The whole process may take e.g. 5 seconds.

我希望能够在网页API引擎完成序列化的数据发送到客户端登录的时间。

I'd like to be able to log the time when Web API engine finishes sending the serialized data to the client.

如何实现这一点?

推荐答案

什么是你想在这里实现?

What are you trying to achieve here?

,网络API创建了一个名为ObjectContent含量
使用格式化程序序列化反应。

Based on the return type of your action, Web API creates a content called ObjectContent which uses formatters to serialize the response.

有关ObjectContents,默认情况下的Web API托管层'缓冲'的开始通过电线发送此缓冲的数据之前,整个响应。

For ObjectContents, by default, Web API hosting layers 'buffer' the entire response before its starts sending this buffered data over the wire.

这篇关于如何知道何时响应已完成被发送到客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆