How to know when a response has finished being sent to the client?

我与影子孤独终老i 提交于 2020-01-16 19:05:14

问题


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

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

  • Request is received by GetAllEvents methods
  • Data is provided by the method
  • Web API engine serializes the object to xml
  • Web API engine sends the serialized data (it might be e.g. 5MB) to the client

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

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

How to achieve this?


回答1:


What are you trying to achieve here?

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

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



来源:https://stackoverflow.com/questions/16359485/how-to-know-when-a-response-has-finished-being-sent-to-the-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!