A simple data contract class to be passed:
[DataContract]
public class MyData
{
[DataMember]
public float Value1 {get;set;}
[DataMember]
public float Value2 {get;set;}
[DataMember]
public float Value3 {get;set;}
}
Server code:
var serializer = new DataContractSerializer(typeof(MyData));
using (var pipe = new NamedPipeServerStream("testpipe", PipeDirection.InOut))
{
pipe.WaitForConnection();
var data = new MyData
{
Value1 = 200,
Value2 = 456,
Value3 = 10234.33f
};
serializer.WriteObject(pipe, data);
}
Client code:
var serializer = new DataContractSerializer(typeof(MyData));
using (var client = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut))
{
client.Connect();
var data = (MyData)serializer.ReadObject(client);
}
The call to ReadObject
above just hangs without throwing any exceptions.
Using XmlSerializer is the exact same.
Can these serializers even be used directly on the named pipes streams or is one forced to use manual string/byte messages parsing?