简体   繁体   English

WCF序列化问题

[英]WCF Serialization Problem

I'm switching code generators for my business objects. 我正在为我的业务对象切换代码生成器。 I was using SQL Metal, but in moving to the T4 toolbox's generator, serialization seems to have stopped working, and it looks like the two are doing pretty much the same thing. 我使用的是SQL Metal,但在移至T4工具箱的生成器时,序列化似乎已停止工作,并且看起来两者在做的事情几乎相同。

This is the property generated by SQL Metal (which works): 这是SQL Metal生成的属性(有效):

[Association(Name="FK_FamilyConfiguration_Family", Storage="_FamilyConfigurations", ThisKey="FamilyID", OtherKey="FamilyID", DeleteRule="CASCADE")]
[DataMember(Order=4, EmitDefaultValue=false)]
public EntitySet<FamilyConfiguration> FamilyConfigurations
{
    get
    {
        if ((this.serializing 
                    && (this._FamilyConfigurations.HasLoadedOrAssignedValues == false)))
        {
            return null;
        }
        return this._FamilyConfigurations;
    }
    set
    {
        this._FamilyConfigurations.Assign(value);
    }
}

and this is the property generated by the T4 toolbox (which does not work): 这是T4工具箱生成的属性(不起作用):

[DataMember(Order = 4, EmitDefaultValue = false)]
[Association(Name = "Family_FamilyConfiguration", Storage = "familyConfigurations", ThisKey = "FamilyID", OtherKey = "FamilyID")]
public EntitySet<FamilyConfiguration> FamilyConfigurations
{
    get 
    {
        if (this.serializing && !this.familyConfigurations.HasLoadedOrAssignedValues)
        {
            return null;
        }

        return this.familyConfigurations; 
    }

    set 
    { 
        this.familyConfigurations.Assign(value); 
    }
}

As far as I can tell, they seem to generate pretty much the same thing. 据我所知,它们似乎产生了几乎相同的东西。 However, with the latter code, the object and all of its references are correctly populated (FamilyConfigurations contains a non-null entry) on the server side of a WCF call, but by the time it gets to the client, FamilyConfigurations is null. 但是,使用后一代码,该对象及其所有引用都在WCF调用的服务器端正确填充(FamilyConfigurations包含非空条目),但是到到达客户端时,FamilyConfigurations为null。

I'm assuming I have a serialization problem of some sort, but I don't see what the difference between the two generated properties is. 我假设我有某种序列化问题,但是我看不出两个生成的属性之间的区别是什么。 Perhaps there's something else that needs to be done? 也许还有其他事情要做? The generated class of which FamilyConfigurations is a member has a DataContract tag under both generators. 在两个生成器下,FamilyConfigurations是成员的生成的类具有DataContract标记。

Update: FamilyConfigurations is null, it is not a collection containing null, as previously state. 更新:FamilyConfigurations为null,它不是一个包含null的集合,如先前所述。

Has FamilyConfiguration changed? FamilyConfiguration是否已更改? I have seen serialization break because of a changed parent-child relationship. 我已经看到由于更改了父子关系而导致序列化中断。 Specifically, the child can not have an Association to its parent. 具体来说,孩子不能与其父母有关联。 That would be my first guess without being able to see the classes themselves. 那是我无法看到类本身的第一个猜测。

EDIT: You can write a small console app that serializes and deserializes your objects using the DataContractSerializer explicitly to find out if serialization is the problem. 编辑:您可以编写一个小型控制台应用程序,使用DataContractSerializer明确地序列化和反序列化您的对象,以找出序列化是否是问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM