代码之家  ›  专栏  ›  技术社区  ›  Ian Ringrose

为什么在某些机器上会出现WCF“帧错误”,而在其他机器上却没有

  •  0
  • Ian Ringrose  · 技术社区  · 15 年前

    我们刚刚发现我们正在得到__ 成帧误差 _(根据WCF日志报告)在某些客户测试机上运行系统时。

    在我们的开发机器上一切正常。

    我们有一个抽象基类,它的所有子类都具有knownType属性。其中一个子类缺少IT的datacontract属性。

    然而,这一切都在我们的试验机上工作!

    在客户测试机上,我们得到了__framing error__ 显示WCF日志时,这不是我以前在缺少DataContract属性或KnownType属性时看到的错误消息。

    我想把这件事搞清楚, 因为我们不再有信心 我们之前测试系统的能力 把它给客户直到我们能 让我们的机器表现出 客户的机器。


    试图显示我所说内容的代码(不是真正的代码)

        [DataContract()]
        [KnownType(typeof(SubClass1))]
        [KnownType(typeof(SubClass2))] 
        // other subclasses with data members
        public abstract class Base
        {
            [DataMember]
            public int LotsMoreItemsThenThisInRealLife;
        }
    
        /// <summary>
        /// This works on some machines (not not others) when passed to Contract::DoIt, 
        /// note the missing [DataContract()]
        /// </summary>
        public class SubClass1 : Base
        {
            // has no data members
        }
    
        /// <summary>
        /// This works in all cases when passed to Contract::DoIt
        /// </summary>
        [DataContract()]
        public class SubClass2 : Base
        {
            // has no data members
        }
    
        public interface IContract
        {
            void DoIt(Base[] items);
        }
    
        public static class MyProgram
        {
            public static IContract ConntectToServerOverWCF()
            {
                // lots of code ...
                return null;
            }
    
            public static void Startup()
            {
                IContract server = ConntectToServerOverWCF();
    
                // this works all of the time
                server.DoIt(new Base[]{new SubClass2(){LotsMoreItemsThenThisInRealLife=2}});
    
                // this works "in develperment" e.g. on our machines, but not on the customer's test machines! 
                server.DoIt(new Base[] { new SubClass1() { LotsMoreItemsThenThisInRealLife = 2 } });
            }
        }
    

    更新我被告知.NET 3.5 SP1已打开 全部的 机器,我还没有自己确认。

    2 回复  |  直到 13 年前
        1
  •  2
  •   Kit    13 年前

    我们有一个类似的问题:在我们所有的测试机器上,一个文件是正确的数据契约反序列化。但是,在一台特定的客户机上,它因错误而失败

    类名 无法序列化。考虑用 DataContractAttribute 属性,并用 DataMemberAttribute 属性。

    结果发现Cusotmer运行的是.NET Framework 3.0,而我们所有的测试都是在.NET Framework 3.5 SP1上完成的。

    数据协定序列化程序的行为似乎不同于.NET Framework 3.0和.NET Framework 3.5。在3.5中,如果一个类是XML可序列化的,那么它也自动是数据协定可序列化的。但是,对于.NET Framework 3.0,情况并非如此-类必须用 [DataContract] [Serializable] .

    希望这有帮助!

        2
  •  0
  •   Ian Ringrose    14 年前

    我认为问题是有些机器没有3.5 SP1 在他们身上。

    推荐文章