Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...