Issue in exposing custom generic entities in WCF proxy code.
Hi All
I have following custom generic entity
[Serializable]
[CollectionDataContract(Name = "{0}EntityCollection", Namespace = "http://himanshu.org/Entities")]
[KnownType(typeof(EmployeeBE))]
[KnownType(typeof(EmployeeLookupBE))]
public class EntityCollection<T> : CollectionBase
{
.....
}
I use it to create collections of types "EmployeeBE" and "EmployeeLookupBE".
When I generate proxy for my service it creates two separate types for "EmployeeBE" and "EmployeeLookupBE"
as follows:[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="EmployeeLookupBEEntityCollection", Namespace="http://himanshu.org/Entities", ItemName="anyType")]
[System.SerializableAttribute()]
public class EmployeeLookupBEEntityCollection : System.Collections.Generic.List<object>
{
......
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="EmployeepBEEntityCollection", Namespace="http://himanshu.org/Entities", ItemName="anyType")]
[System.SerializableAttribute()]
public class EmployeeBEEntityCollection : System.Collections.Generic.List<object>
{
......
}
Issue:
I am expecting the type argument of Generic List for these classes to be "EmployeeLookupBE" and "EmployeeBE" respectively, making the code look like below:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="EmployeeLookupBEEntityCollection", Namespace="http://himanshu.org/Entities", ItemName="anyType")]
[System.SerializableAttribute()]
public class EmployeeLookupBEEntityCollection : System.Collections.Generic.List<EmployeeLookupBE>
{
.......
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="EmployeeLookupBEEntityCollection", Namespace="http://himanshu.org/Entities", ItemName="anyType")]
[System.SerializableAttribute()]
public class EmployeeBEEntityCollection : System.Collections.Generic.List<EmployeeBE>
{
.......
}
Not sure why it is not taking the exact types, it should take.
Answers
Hi,
Can you post a bit more code as I didn't reproduce your issue.
This is what I defined:
// [DataContract]
public class Parent
{
public string test = "this is parent test";
}
//[DataContract]
public class Child : Parent
{
public string test1 = "this is child test";
}
[CollectionDataContract]
[KnownType(typeof(Parent))]
[KnownType(typeof(Child))]
public class CustomCollection<T> : CollectionBase
{
public CustomCollection()
: base()
{
}
}
The generated proxy will be:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="CustomCollectionOfParentRkK6MCnv", Namespace="http://schemas.datacontract.org/2004/07/WcfService4", ItemName="anyType")]
[System.SerializableAttribute()]
public class CustomCollectionOfParentRkK6MCnv : System.Collections.Generic.List<object> {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Parent", Namespace="http://schemas.datacontract.org/2004/07/WcfService4")]
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(Client.ServiceReference1.Child))]
public partial class Parent : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Child", Namespace="http://schemas.datacontract.org/2004/07/WcfService4")]
[System.SerializableAttribute()]
public partial class Child : Client.ServiceReference1.Parent {
}
Thanks
Binze
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byBin-ze ZhaoMSFT, ModeratorFriday, November 06, 2009 3:15 AM
All Replies
Hi,
Can you post a bit more code as I didn't reproduce your issue.
This is what I defined:
// [DataContract]
public class Parent
{
public string test = "this is parent test";
}
//[DataContract]
public class Child : Parent
{
public string test1 = "this is child test";
}
[CollectionDataContract]
[KnownType(typeof(Parent))]
[KnownType(typeof(Child))]
public class CustomCollection<T> : CollectionBase
{
public CustomCollection()
: base()
{
}
}
The generated proxy will be:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="CustomCollectionOfParentRkK6MCnv", Namespace="http://schemas.datacontract.org/2004/07/WcfService4", ItemName="anyType")]
[System.SerializableAttribute()]
public class CustomCollectionOfParentRkK6MCnv : System.Collections.Generic.List<object> {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Parent", Namespace="http://schemas.datacontract.org/2004/07/WcfService4")]
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(Client.ServiceReference1.Child))]
public partial class Parent : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Child", Namespace="http://schemas.datacontract.org/2004/07/WcfService4")]
[System.SerializableAttribute()]
public partial class Child : Client.ServiceReference1.Parent {
}
Thanks
Binze
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byBin-ze ZhaoMSFT, ModeratorFriday, November 06, 2009 3:15 AM
- Hi
You have reproduced the problem partially. The first class in your proxy code which is as below:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="CustomCollectionOfParentRkK6MCnv", Namespace="http://schemas.datacontract.org/2004/07/WcfService4", ItemName="anyType")]
[System.SerializableAttribute()]
public class CustomCollectionOfParentRkK6MCnv : System.Collections.Generic.List<object> {
}
should have the type argument for the generic list to be 'Parent' and not 'object'.
This is the issue I am trying understand.
Thanks
Himanshu.


