问题
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