Question

I have an issue with WCF streaming. I have two components in my solution :

  • A WCF service hosted in a Windows Service
  • A client application (console app for now) consuming the service

The WCF service just have one method : RunProcess. This method takes no parameters and is starting a process. It returns a Stream (this is a WCF streaming method) corresponding to the process standard ouptut stream (StandardOutput.BaseStream).

The WCF service exposes a single endpoint with a basicHttpBinding (with transferMode="streamed").

The client code is pretty straightforward, it calls the RunProcess methods and passes the Stream result into a StreamReader calling ReadLine() on it until end of stream (ReadLine() returning null). Each ReadLine() result is sent to the console (Console.WriteLine())

So this is pretty simple ... HOWEVER when I launch the client, the Console is not refreshed immediately as expected. It is waiting for some reason for the process that was launched to end because nothing is displayed in the console for a long time, and once the process is completed it is displaying the output all at once.

I have another console project, not relying on the WCF service, where I launch the process directly, get the standard ouptput stream, and using the exact same algorithm, write the stream to the console, and the issue is not present, the output stream is displayed directly after the process is launched, in real time.

I don't understand this behavior. Any help would be greatly appreciated !

Thanks.

EDIT : Some code / config might help indeed.

--- Config of the binding

<basicHttpBinding>
    <binding name="BasicHttpBindingStreamed" maxReceivedMessageSize="67108864" transferMode="Streamed"/>        
</basicHttpBinding>

--- WCF method

public Stream RunProcess()
    {
        Process p = new Process();
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "XXXXXX";          
        p.Start();            

        return p.StandardOutput.BaseStream;            
    }

--- Client consummer

Stream cmdOutputStream = serviceClient.RunProcess();
string currentLine = null;
using (TextReader reader = new StreamReader(cmdOutputStream))
{                                
   currentLine = reader.ReadLine();
   while (currentLine != null)
   {
      Console.WriteLine(currentLine);
      currentLine = reader.ReadLine();
    }
 }
Was it helpful?

Solution

Solved ... Stupid issue, I specified the transferMode="Streamed" on the WCF server side config but forgot client side .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top