2010-06-15 26 views

回答

8

這裏是一段代碼來創建命名管道客戶,它是從一個答案,一個previous question我在使用命名管道

using System; 
using System.Text; 
using System.IO; 
using System.IO.Pipes; 

namespace CSPipe 
{ 
    class Program 
    { 
    static void Main(string[] args) 
    { 
     NamedPipeClientStream pipe = new NamedPipeClientStream(".", "HyperPipe", PipeDirection.InOut); 
     pipe.Connect(); 
     using (StreamReader rdr = new StreamReader(pipe, Encoding.Unicode)) 
     { 
     System.Console.WriteLine(rdr.ReadToEnd()); 
     } 

     Console.ReadKey(); 
    } 
    } 
} 
0

最簡單的方法是使用WCF:

變種結合=新System.ServiceModel.NetNamedPipeBinding(System.ServiceModel.NetNamedPipeSecurityMode.None)

+0

C++和C#之間的通信回答是否會WCF服務使用解除命名管道綁定與任何使用命名管道的應用程序工作?如果我有一個使用它們的遺留應用程序會怎麼樣?我試圖弄清楚在這種情況下是否只有WCF-WCF。 – jlafay 2011-02-10 21:45:02

+0

這取決於!命名管道的當前實現不允許它們在整個網絡中使用。此外,如果您想使用它們與傳統應用程序進行通信,您可能需要實施自己的協議,WCF不會知道這一點。在這種情況下,使用一些較低級別的方法將更容易,例如, win32(見http://www.switchonthecode.com/tutorials/interprocess-communication-using-named-pipes-in-csharp)或http://stackoverflow.com/questions/244367/c-3-5-connecting-命名管道,跨網絡。 – 2011-02-14 16:01:27