【问题标题】:Apache Ignite .Net Store ComplexType in SessionApache Ignite .Net 在会话中存储 ComplexType
【发布时间】:2018-09-03 10:42:44
【问题描述】:

我想使用 apache ignite 作为集中式会话服务器。我的问题是 ignite 无法存储没有可序列化属性的对象。例如我的对象就是这样。但是由于 PersonDetail 实体,它不能序列化 Person 对象。有人可以分享使用 .net 的 ignite 示例来使用会话,而无需添加每个嵌套实体可序列化属性。

[Serializable]
    public class Person
    {
        public string Name { get; set; }
        public int MyProperty2 { get; set; }

        public PersonDetail PDetail
        {
            get
            {
                return pDetail;
            }

            set
            {
                pDetail = value;
            }
        }

        private PersonDetail pDetail;

    }


    public class PersonDetail
    {

        private int Salary { get; set; }
        public int Age { get; set; }
    }

我的网络配置...

 <sessionState mode="Custom" customProvider="IgniteSessionStateProvider">
          <providers>
            <add name="IgniteSessionStateProvider"
               type="Apache.Ignite.AspNet.IgniteSessionStateStoreProvider, Apache.Ignite.AspNet"
               igniteConfigurationSectionName="igniteConfiguration"
               applicationId="myUI"
               gridName="mysessiontest"
               cacheName="myWebCache" />
          </providers>
        </sessionState>

【问题讨论】:

    标签: .net serialization ignite


    【解决方案1】:

    Ignite.NET 使用BinaryFormatter 来序列化会话状态数据,因此拥有所有嵌套类[Serializable] 的要求来自那里。

    没有与 Ignite 相关的解决方法。您可以使用不同的序列化程序对数据进行序列化,并将byte[] 置于会话状态。

    【讨论】:

    • 你有像我们这样的场景吗?我们有这么多嵌套类和不同的项目?我们无法将每个类都添加到可序列化属性中......
    • @Bilgehan 为什么不按照 Pavel 的建议去做呢?只需自己预序列化所有内容并在 Ignite 中存储一个字节数组。这样,您可以在将任何内容放入 Ignite 之前处理所有序列化。
    【解决方案2】:

    我认为你有两个选择:

    1. 正如 Pavel 所说,您可以 choose a different way to serialise the whole, nested structure
    2. 或者,您可以选择not to serialise the nested objects

    我没有要测试的 .net 环境,但理论上应该可以:

    [Serializable]
    public class MyObject 
    {
      public int n1;
      [NonSerialized] public int n2;
      public String str;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-07-04
      • 2019-11-04
      • 1970-01-01
      • 2016-08-10
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多