first, I hope I provide enough information to make things clear, if not please ask for more.
I have a working WCF communication using Duplex Channel and OneWay method calls. The ServiceHost is located inside a managed WPF application using NetPipeBinding, the client lives in a AppDomain inside that application. Everything is working as expected as long as all types are primitive (string, DateTime, ...) or specified as known type (List<object>
, List<string>
). But I need to send other types, for which I can´t add a known type attribute because I don´t know them at compile time.
As I read here (http://msdn.microsoft.com/library/ms731923(v=vs.100).aspx) all public types with public properties are supported, and so are types decorated with SerializableAttribute.
I tried to transfer a very simple class:
public class ADT
{
public string Name { get; set; }
}
and as a second try
[Serializable]
public class SerializableADT
{
public string Name { get; set; }
}
and as suggested by Herdo
[DataContract]
public class DataContractADT
{
[DataMember]
public string Name { get; set; }
[DataMember]
public object Value { get; set; }
}
but the deserialization fails for all three types.
There was an error while trying to serialize parameter _http://tempuri.org/:returnValue. The InnerException message was 'Type 'TestLibraries.SeriablizableADT' with data contract name 'SeriablizableADT:_http://schemas.datacontract.org/2004/07/TestLibraries' is not expected. Consider using a DataContractResolver or 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.
How can I marshal any type that meets the MSDN rules (e.g. decorated with Serializable) without any compile time changes?
DataContract
attribute forSerializeableADT
? – Herdo