如何保持会话的基于XML的对象? [英] How to keep in session XML-based objects?

查看:133
本文介绍了如何保持会话的基于XML的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XML接收来自网络服务的数据和我使用的通过对象的数据,建立在接收到的XML。所以,有时我需要存储在会话请求之间的这种用户特定对象。我知道的XMLDocument无法明确(状态服务器),存储...所以我做一个可怕的建设,如:

I'm receiving data from web-services in XML and I'm using that data via objects, build upon received XML. So, sometimes I need to store such user-specific objects between requests in session. I know that XMLDocument couldn't be stored explicitly (state server)... so I'm making a terrible construction like:

private string _data;
public XmlDocument Data
{
    get
    {
        XmlDocument res = new XmlDocument();
        if (!string.IsNullOrEmpty(_data))
        {
            res.InnerXml = _data;
            return res;
        }
        return null;
    }
    set { _data = value.InnerXml; }
}

所以我含蓄地存储XML ...它在开发过程中对我有益的,因为我不知道到底是什么性质,我从整个对象的需要 - 我可以在紧要关头做出使用XPath等简单的实验性...

So i'm implicitly storing xml... it useful for me during development, because I don't know exactly what properties I need from entire object - I can make simple experimental properties with xpath etc in a pinch...

所以它的舒适FO我,但它看起来非常低效的,从字符串每次我需要从类的所有属性得到一些数据构建的XmlDocument。有没有什么办法解决?)谢谢。

so it's comfortable fo me, but it looks very inefficient to construct xmldocument from string each time I need to get some data from any property of that class. Is there any way around?) thanks.

推荐答案

如果您需要跨请求存储数据,真的没有让周围序列,并且每个请求在反序列化数据 - 有一个例外。如果您使用进程的会议,它可以存储你想要的任何对象,包括为XMLDocument对象,甚至(原谅我连提这一点)打开的文件句柄和数据库连接。我不建议让您的应用程序依赖于过程,虽然,因为这将消除把应用程序的Web服务器场中,如果是有史以来必要的可能性会议。

If you need to store data across requests, there's really no getting around serializing and de-serializing the data during each request - with one exception. If you use in-process sessions, it's possible to store any object you want, including XMLDocument objects or even (forgive me for even mentioning this) open file handles and database connections. I wouldn't recommend making your application dependent on in-process sessions though because it will eliminate the possibility of putting the application in a web farm if that ever becomes necessary.

我觉得你最好的选择是优化当前的策略。你要确保每个请求期间的XMLDocument只重建一次?如果不建立一个XMLDocument,也许这将是更有效的为你使用一个XMLReader,这取决于XML数据是如何实际使用。

I think your best option is to optimize your current strategy. Are you making sure that the XMLDocument is only reconstructed once during each request? Instead of constructing an XMLDocument, maybe it would be more efficient for you to use an XMLReader, depending on how the XML data is actually used.

这篇关于如何保持会话的基于XML的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆