1

给定来自 RssXmlHelper.cs 中 RssToolkit 的以下代码:

    /// <summary>
    /// Returns XML of the Generic Type.
    /// </summary>
    /// <param name="rssDocument">The RSS document.</param>
    /// <typeparam name="T">RssDocumentBase</typeparam>
    /// <returns>string</returns>
    public static string ToRssXml<T>(T rssDocument) where T : RssDocumentBase
    {
        if (rssDocument == null)
        {
            throw new ArgumentNullException("rssDocument");
        }

        using (StringWriter output = new StringWriter(new StringBuilder(), CultureInfo.InvariantCulture))
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            serializer.Serialize(output, rssDocument);
            return output.ToString();
        }
    }

在我的 WCF 服务中调用 serializer.Serialize() 时,需要花费大量时间。

我有这个坐在我从我的项目中调用的 WCF 服务中。我踏入其中,果然,这就是问题所在。

然后我在我的解决方案中引用该项目,没问题。

在 WCF 服务中使用它时,我应该做些什么不同的事情吗?

- 更新 -

好的,所以我安装了适用于 Windows 7 和 .NET Framework 4 的 Microsoft Windows SDK,运行 sgne.exe RssToolkit.dll 并收到以下错误:

Error:  An attempt was made to load an assembly with in incorrect format [path to rsstoolkit.dll]
- Could not load file or assemply [path to rsstoolkit.dll] or one of its dependencies.  This assembly was build by a runtime newer than the currently loaded runtime and cannot be loaded.

我的 RssToolkit 项目的目标框架设置为 4.0,与 .Net 4 的 Windows SDK 匹配。这不正确吗?

4

1 回答 1

3

您可以使用sgen.exeWindows SDK 附带的 XML 序列化程序生成器工具生成序列化程序集。通过在大型课程中使用它,我已经看到了巨大的改进。

它基本上会生成知道如何序列化和反序列化域中每个对象的代码。生成 DLL 后,您可以将其作为程序集引用包含在项目中,然后使用其中的类而不是XmlSerializer您现在使用的类。

于 2011-12-07T01:01:22.407 回答