0

我知道在使用流时我需要刷新它,以便它会释放与流相关的任何资源,并且刷新流需要任何尚未写入的缓冲数据,并立即将其写出。

我有以下课程:

[XmlRoot("EventList")]
public class EventList
{
    private List<BaseEvent> events_ = new List<BaseEvent>();
    /// Default constructor. Required for serialization
    public EventList() {}

    [XmlElement(ElementName = "Event")]
    public List<BaseEvent> Events
    {
        get 
        {
            return events_;
        }
        set 
        {
            events_ = value;
        }
    }
}

现在在我将它作为对 HTTPRequest 的响应发送之前,我需要刷新它吗?如果是这样,我该怎么办?

我之所以问,是因为我遇到了此处描述的问题: AJAX 响应 - XmlHttp.responseXML 被切断

js客户端激活的方法是:

[WebMethod]
public EventsRequestResult GetEvents(string agentId, int delayedReturnMS)

// EventsRequestResult - return value of the GetEvents method of the EventsService.
public class EventsRequestResult
{
    private EventList events_ = null;
    /// <summary>
    /// List of the events
    /// </summary>
    [XmlElement(ElementName = "Events")]
    public EventList Events
    {
        get
        {
            return events_;
        }
        set
        {
            events_ = value;
        }
    }
    /// Default constructor.
    public EventsRequestResult(){}
    /// <summary>
    /// Constructor used in case of the failure.
    /// </summary>
    /// <param name="errorCode">Numeric error code</param>
    /// <param name="errorDescription">Human readable error description</param>
    public EventsRequestResult(RequestErrorCode errorCode, string errorDescription) : base(errorCode, errorDescription){}
    /// <summary>
    /// Constructor used in case of successful events request.
    /// </summary>
    /// <param name="events">List of the events</param>
    public EventsRequestResult(EventList events) : base()
    {
        events_ = events;
    }
}
4

1 回答 1

0

马克在上面的评论中是对的,但我认为你正在寻找的是类似的东西

    using(var stream = theResponse.OutputStream)
    {
        var ser = new XmlSerializer(typeof(EventList));
        return ser.Deserialize(stream) as EventList;
    }

return从 using 块中将关闭(并刷新)流。

于 2013-03-20T10:30:37.313 回答