hello
I'm running into Serialization problem with WCF again and I'm not sure if it arise from namespace problem or KnownType/interface...
Now all seems good initially up until I added Parents/Children (from IHierarchProp) - i.e. Person class serialize/deserialize successfully BEFORE I added Parents/Children (which are also of type Person) ... I checked SrvTraceViewer, the message was:Code:[DataContract(Name = "Person")] public class Person : IHierachicalPropOwner { ... IHierarchProp HierarchicalProp { get {...} set {...} } ... } public interface IHierarchicalPropOwner { ... IHierarchProp HierarchicalProp; ... } [KnownType(typeof(Person))] // Because List<IHierarchicalPropOwner> is actually List<Person>, I include Person as KnownType as well. [DataContract()] public class HierarchicalProp : IHierarchProp { ... [DataMember()] public List<IHierarchicalPropOwner> Parents { get ... set ... } [DataMember()] public List<IHierarchicalPropOwner> Children { get ... set ... } ... }
I don't know why I must add a namespace but I did change Person's DataContract attrib:Code:Type 'PersonProxy84be8e34abd44adf9c275dce3b694daf' cannot have DataContractAttribute attribute Namespace set to null.
I then fired it up again, and ran into a different error messageCode:[DataContract(Name = "Person", Namespace="Util")] public class Person : IHierachicalPropOwner { ... }
Adding to service contract ServiceKnownType didn't help it but I made sure I have...Code:There was an error while trying to serialize parameter http://tempuri.org/:AuthenticateUserResult. The InnerException message was 'Type 'PersonProxy9ae63f0c5e1b403881f64f08908cf759' with data contract name 'Person:Util' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details
Now I was suspecting perhaps DataContractSerializer need Person's namespace as specified in [DataContract] namespace attib be same as that of "Service Reference" when you "Add Service Reference" from Visual Studio (you set service namespace at that time). So I go ahead and make the change:Code:[ServiceKnownType(typeof(Person))]
The error did NOT go away,Code:[DataContract(Name = "Person", Namespace="SecurityServiceRef")] public class Person : IHierachicalPropOwner { ... }
Any idea? Many Thanks!Code:There was an error while trying to serialize parameter http://tempuri.org/:AuthenticateUserResult. The InnerException message was 'Type 'PersonProxyebe18eee73cd41db908097f0886b787e' with data contract name 'Person:ServiceServiceRef' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
REF:
http://msdn.microsoft.com/en-us/library/ms730167.aspxvv




Reply With Quote