【问题标题】:Why are we getting a WCF "Framing error" on some machines but not others为什么我们在某些机器上出现 WCF“框架错误”,而在其他机器上却没有
【发布时间】:2011-10-27 12:38:06
【问题描述】:

我们刚刚发现在某些客户测试机器上运行我们的系统时出现“帧错误”(由 WCF 日志报告)。

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

我们有一个抽象基类,它的所有子类都有 KnownType 属性。它的一个子类缺少它的 DataContract 属性。

但是这一切都在我们的测试机器上运行了!

在客户测试机器上,我们在 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 在所有机器上,我还没有亲自确认。

【问题讨论】:

    标签: .net wcf datacontract known-types


    【解决方案1】:

    我们遇到了类似的问题:一个文件在我们所有的测试机器上都正确地反序列化了数据合约。但是,在一台特定的客户机器上,它失败并出现错误

    ClassName 无法序列化。考虑使用DataContractAttribute 属性对其进行标记,并使用DataMemberAttribute 属性标记您想要序列化的所有成员。

    原来客户运行的是 .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】:

      我认为问题在于某些机器上没有 3.5 SP1

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-01
        • 1970-01-01
        • 2015-05-05
        • 1970-01-01
        相关资源
        最近更新 更多