Search code examples
c#c++wcfnamed-pipesnetnamedpipebinding

NetNamedPipeBinding between C# and C++


I've seen that NetNamedPipeBinding exists in C# and in C++ (source) and I would like to know if it's possible to use it to transmit datas between a C++ program and a C# application?


Solution

  • If your C++ compiler is a recent version of Visual C++, with all the extensions to support writing managed code, then you can use WCF easily to pass data between a C++ program and a C# application.

    If your C++ compiler doesn't support managed code extensions, you can still do it but it is a lot of work, because the WCF channel stack uses some layered proprietary protocols for message framing, security negotiation and message encoding, which you would need to reimplement on the C++ side if you can't use the managed implementation provided by WCF. See for example this question for the kind of issues which arise.

    If you can't do managed C++ it is often much easier to forego some of the benefits provided by WCF and, depending on your requirements, either to:

    • use a managed COM-visible wrapper around a C# WCF service, consumed as a COM server in the C++ code; or
    • roll your own IPC mechansim using a named pipe directly, calling the WIn32 APIs on the C++ side and using the System.IO.Pipes types on the C# side.