当使用XmlRootAttribute类时,我需要冲洗吗?

本文关键字:XmlRootAttribute 类时 | 更新日期: 2023-09-27 18:04:44

我知道当使用流时,我需要刷新它,这样它就会释放与流相关的任何资源,刷新流会获取任何尚未写入的缓冲数据,并立即将其写出来。

我有以下类:

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

当使用XmlRootAttribute类时,我需要冲洗吗?

Marc的评论是对的,但我认为你要找的是类似

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

return from using block将关闭(并刷新)流

相关文章:
  • 没有找到相关文章