I have 2 apps that I want to make communicate via named pipes on .NET 3.5. Its a request/response paradigm, with the data transmitted as XML to make my life easier. There is a listener app, and an app that posts requests to the pipe. I'm trying to use a bidirectional pipe to do this. The problem i have is that the call to StreamReader.ReadToEnd() doesnt seem to return. What can I do to fix this?
Listener code
public Class Listener
{
private void ThreadFunc()
{
var pipe = new NamedPipeServerStream("GuideSrv.Pipe",PipeDirection.InOut);
var instream = new StreamReader(pipe);
var outstream = new StreamWriter(pipe);
while (true)
{
pipe.WaitForConnection();
var response = ProcessPipeRequest(instream);
outstream.Write(response.ToString());
pipe.Disconnect();
}
}
private XDocument ProcessPipeRequest(StreamReader stream)
{
var msg_in = stream.ReadToEnd(); // << This call doesnt return
var xml_in = XDocument.Parse(msg_in);
// do some stuff here
return new XDocument(....);
}
}
Requester code
public XDocument doIt()
{
var xml = new XDocument(....);
using (var pipe = new NamedPipeClientStream(".", "GuideSrv.Pipe", PipeDirection.InOut))
{
using (var outstream = new StreamWriter(pipe))
using (var instream = new StreamReader(pipe))
{
pipe.Connect();
outstream.Write(xml.ToString());
xml = XDocument.Parse(instream.ReadToEnd());
}
}
return xml;
}