服务引用忽略了知识类型

时间:2012-09-19 15:10:29

标签: wcf .net-4.0 known-types

[CollectionDataContract(Namespace = "CISICPD")]
[KnownType(typeof(List<CISICPD.LeeDictionary>))]
public class LeeDictionary : Dictionary<string, object> 
{
}

[DataContract(Namespace = "CISICPD")]
[KnownType(typeof(List<CISICPD.LeeDictionary>))]
public class TestResponse
{
    [DataMember]
    public List<LeeDictionary> Results;

    public TestResponse() { Results = new List<LeeDictionary>(); }
    [OnDeserializing]
    private void OnDeserialize(StreamingContext c) { Results = new List<LeeDictionary>(); }
}

如果在服务引用中使用了上述内容,则生成的reference.cs将忽略上面指定的已知类型。

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="TestResponse", Namespace="CISICPD")]
[System.SerializableAttribute()]
public partial class TestResponse : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

我指定了LeeDictionary所以我可以设置自己的命名空间(认为它可能是命名空间问题),将其更改为Dictionary<string,object>也是一样的。当字典本身包含另一个字典并抱怨该类型未知时,就会出现问题。

如果我将知识类型行添加到reference.cs它然后一切正常但我不知道为什么它在生成引用时不会放入它?

0 个答案:

没有答案