none
What's the best way to set up WCF (using named pipes) between 2 apps? RRS feed

Answers

  • Hi,

    WCF supports interprocess and intraprocess communication scenarios with the netNamedPipeBinding binding. The netNamedPipeBinding binding leverages a named pipes transport. This is a great binding to use for doing interprocess communication (IPC) because it provides a significant performance increase over the other standard bindings available in WCF.
    This type of communication called Local machine communication.
    Address format: net.pipe://{hostname}/{service location}

    netNamedPipeBinding Service Configuration

    <system.serviceModel>
        <services>
          <service
               name="NorthwindServices.CustomerService"
               behaviorConfiguration="ServiceBehavior">
    
            <host>
              <baseAddresses>
                <add baseAddress="net.pipe://localhost/NorthwindServices/" />
              </baseAddresses>
            </host>
    
            <endpoint address="CustomerService"
                      binding="netNamedPipeBinding"
                      contract="NorthwindServices.ICustomer" />
            
            <endpoint address="CustomerService/mex"
                      binding="mexNamedPipeBinding"
                      contract="IMetadataExchange" />
            
          </service>
        </services>
        
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="False"  />
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        </system.serviceModel>

    Then use the net.pipe://localhost/NorthwindServices/CustomerService/mex to discover the service in the client side.

    For more information, please try to refer to the following articles:
    #How to set that up to use WCF (using named pipes):
    http://dotnetmentors.com/wcf-by-example-on-netnamedpipebinding.aspx .

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.





    Monday, September 30, 2013 6:19 AM
    Moderator
  • Following links may help

    http://netnamedpipebinding.codeplex.com/
    http://dotnet-experience.blogspot.in/2012/02/inter-process-duplex-communication-with.html


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Sunday, September 29, 2013 3:25 PM
  • http://weblogs.asp.net/ralfw/archive/2007/04/14/a-truely-simple-example-to-get-started-with-wcf.aspx

    I made the console application project. I made a classlib project called Server  and put the server code in it.

    namespace WCFSimpleConsole
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("WCF Simple Demo");

                // start server

                var thServer = new System.Threading.Thread(WCFSimple.Server.Program.Main) {IsBackground = true};

                thServer.Start();

                System.Threading.Thread.Sleep(1000);  // wait for server to

                // run client

                ChannelFactory<WCFSimple.Contract.IService> scf;

                //scf = new ChannelFactory<WCFSimple.Contract.IService>(
                //          new NetTcpBinding(),
                //            "net.tcp://localhost:8000");


                scf = new ChannelFactory<WCFSimple.Contract.IService>(
                         new NetNamedPipeBinding(),
                           "net.pipe://localhost/Pipe");

                WCFSimple.Contract.IService s;

                s = scf.CreateChannel();

                while (true)
                {
                    Console.Write("CLIENT - Name: ");

                    string name = Console.ReadLine();

                    if (name == "") break;

                    string response = s.Ping(name);

                    Console.WriteLine("CLIENT - Response from service: " + response);
                }

                (s as ICommunicationObject).Close();

                // shutdown server

                WCFSimple.Server.Program.Stop();

                thServer.Join();

            }
        }
    }

     I was able to use NetNamedPipeBinding or NetTcpBinding. I was able to go to a Windows form project on the client side and call the service using named pipe or tcp.  So I don't  see what you can't do it from a Web app.

    namespace TestNotification
    {
        public partial class Form1 : Form
        {
            private NotifyIcon notifyIcon1;
            private ContextMenu contextMenu1;
            private MenuItem menuItem1;
            private IContainer components;
           
            [STAThread]
            static void Main()
            {
                Application.Run(new Form1());
            }

            public Form1()
            {

                this.components = new System.ComponentModel.Container();
                this.contextMenu1 = new System.Windows.Forms.ContextMenu();
                this.menuItem1 = new System.Windows.Forms.MenuItem();

                // Initialize contextMenu1
                this.contextMenu1.MenuItems.AddRange(
                            new System.Windows.Forms.MenuItem[] { this.menuItem1 });

                // Initialize menuItem1
                this.menuItem1.Index = 0;
                this.menuItem1.Text = "E&xit";
                this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

                // Set up how the form should be displayed.
                this.ClientSize = new System.Drawing.Size(292, 266);
                this.Text = "Notify Icon Example";
               
                // Create the NotifyIcon.
                this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

                // The Icon property sets the icon that will appear
                // in the systray for this application.
                notifyIcon1.Icon = new Icon("appicon.ico");

                // The ContextMenu property sets the menu that will
                // appear when the systray icon is right clicked.
                notifyIcon1.ContextMenu = this.contextMenu1;

                // The Text property sets the text that will be displayed,
                // in a tooltip, when the mouse hovers over the systray icon.
                notifyIcon1.Text = "Form1 (NotifyIcon example)";
                notifyIcon1.Visible = true;

                // Handle the DoubleClick event to activate the form.
                notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
                this.WindowState = FormWindowState.Minimized;


                // start server

                var thServer = new System.Threading.Thread(WCFSimple.Server.Program.Main) { IsBackground = true };

                thServer.Start();

                System.Threading.Thread.Sleep(1000);  // wait for server to

                // run client

                ChannelFactory<WCFSimple.Contract.IService> scf;

                //scf = new ChannelFactory<WCFSimple.Contract.IService>(
                //          new NetTcpBinding(),
                //            "net.tcp://localhost:8000");


                scf = new ChannelFactory<WCFSimple.Contract.IService>(
                         new NetNamedPipeBinding(),
                           "net.pipe://localhost/Pipe");

                WCFSimple.Contract.IService s;

                s = scf.CreateChannel();

                var rtbStatus = new RichTextBox();
                    this.Controls.Add(rtbStatus);
                    this.WindowState = FormWindowState.Normal;

                string name = "Hello from Me";
                   
                rtbStatus.Text = s.Ping(name);
            }

            protected override void Dispose( bool disposing )
            {
                // Clean up any components being used.
                if( disposing )
                    if (components != null)
                        components.Dispose();           

                base.Dispose( disposing );
            }

            private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
            {
                // Show the form when the user double clicks on the notify icon.

                // Set the WindowState to normal if the form is minimized.
                if (this.WindowState == FormWindowState.Minimized)
                    this.WindowState = FormWindowState.Normal;

                // Activate the form.
                this.Activate();
            }

            private void menuItem1_Click(object Sender, EventArgs e)
            {
                // Close the form, which closes the application.
                this.Close();
            }

        }  
    }

    Sunday, September 29, 2013 8:21 PM

All replies

  • Following links may help

    http://netnamedpipebinding.codeplex.com/
    http://dotnet-experience.blogspot.in/2012/02/inter-process-duplex-communication-with.html


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Sunday, September 29, 2013 3:25 PM
  • http://weblogs.asp.net/ralfw/archive/2007/04/14/a-truely-simple-example-to-get-started-with-wcf.aspx

    I made the console application project. I made a classlib project called Server  and put the server code in it.

    namespace WCFSimpleConsole
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("WCF Simple Demo");

                // start server

                var thServer = new System.Threading.Thread(WCFSimple.Server.Program.Main) {IsBackground = true};

                thServer.Start();

                System.Threading.Thread.Sleep(1000);  // wait for server to

                // run client

                ChannelFactory<WCFSimple.Contract.IService> scf;

                //scf = new ChannelFactory<WCFSimple.Contract.IService>(
                //          new NetTcpBinding(),
                //            "net.tcp://localhost:8000");


                scf = new ChannelFactory<WCFSimple.Contract.IService>(
                         new NetNamedPipeBinding(),
                           "net.pipe://localhost/Pipe");

                WCFSimple.Contract.IService s;

                s = scf.CreateChannel();

                while (true)
                {
                    Console.Write("CLIENT - Name: ");

                    string name = Console.ReadLine();

                    if (name == "") break;

                    string response = s.Ping(name);

                    Console.WriteLine("CLIENT - Response from service: " + response);
                }

                (s as ICommunicationObject).Close();

                // shutdown server

                WCFSimple.Server.Program.Stop();

                thServer.Join();

            }
        }
    }

     I was able to use NetNamedPipeBinding or NetTcpBinding. I was able to go to a Windows form project on the client side and call the service using named pipe or tcp.  So I don't  see what you can't do it from a Web app.

    namespace TestNotification
    {
        public partial class Form1 : Form
        {
            private NotifyIcon notifyIcon1;
            private ContextMenu contextMenu1;
            private MenuItem menuItem1;
            private IContainer components;
           
            [STAThread]
            static void Main()
            {
                Application.Run(new Form1());
            }

            public Form1()
            {

                this.components = new System.ComponentModel.Container();
                this.contextMenu1 = new System.Windows.Forms.ContextMenu();
                this.menuItem1 = new System.Windows.Forms.MenuItem();

                // Initialize contextMenu1
                this.contextMenu1.MenuItems.AddRange(
                            new System.Windows.Forms.MenuItem[] { this.menuItem1 });

                // Initialize menuItem1
                this.menuItem1.Index = 0;
                this.menuItem1.Text = "E&xit";
                this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

                // Set up how the form should be displayed.
                this.ClientSize = new System.Drawing.Size(292, 266);
                this.Text = "Notify Icon Example";
               
                // Create the NotifyIcon.
                this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

                // The Icon property sets the icon that will appear
                // in the systray for this application.
                notifyIcon1.Icon = new Icon("appicon.ico");

                // The ContextMenu property sets the menu that will
                // appear when the systray icon is right clicked.
                notifyIcon1.ContextMenu = this.contextMenu1;

                // The Text property sets the text that will be displayed,
                // in a tooltip, when the mouse hovers over the systray icon.
                notifyIcon1.Text = "Form1 (NotifyIcon example)";
                notifyIcon1.Visible = true;

                // Handle the DoubleClick event to activate the form.
                notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
                this.WindowState = FormWindowState.Minimized;


                // start server

                var thServer = new System.Threading.Thread(WCFSimple.Server.Program.Main) { IsBackground = true };

                thServer.Start();

                System.Threading.Thread.Sleep(1000);  // wait for server to

                // run client

                ChannelFactory<WCFSimple.Contract.IService> scf;

                //scf = new ChannelFactory<WCFSimple.Contract.IService>(
                //          new NetTcpBinding(),
                //            "net.tcp://localhost:8000");


                scf = new ChannelFactory<WCFSimple.Contract.IService>(
                         new NetNamedPipeBinding(),
                           "net.pipe://localhost/Pipe");

                WCFSimple.Contract.IService s;

                s = scf.CreateChannel();

                var rtbStatus = new RichTextBox();
                    this.Controls.Add(rtbStatus);
                    this.WindowState = FormWindowState.Normal;

                string name = "Hello from Me";
                   
                rtbStatus.Text = s.Ping(name);
            }

            protected override void Dispose( bool disposing )
            {
                // Clean up any components being used.
                if( disposing )
                    if (components != null)
                        components.Dispose();           

                base.Dispose( disposing );
            }

            private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
            {
                // Show the form when the user double clicks on the notify icon.

                // Set the WindowState to normal if the form is minimized.
                if (this.WindowState == FormWindowState.Minimized)
                    this.WindowState = FormWindowState.Normal;

                // Activate the form.
                this.Activate();
            }

            private void menuItem1_Click(object Sender, EventArgs e)
            {
                // Close the form, which closes the application.
                this.Close();
            }

        }  
    }

    Sunday, September 29, 2013 8:21 PM
  • Hi,

    WCF supports interprocess and intraprocess communication scenarios with the netNamedPipeBinding binding. The netNamedPipeBinding binding leverages a named pipes transport. This is a great binding to use for doing interprocess communication (IPC) because it provides a significant performance increase over the other standard bindings available in WCF.
    This type of communication called Local machine communication.
    Address format: net.pipe://{hostname}/{service location}

    netNamedPipeBinding Service Configuration

    <system.serviceModel>
        <services>
          <service
               name="NorthwindServices.CustomerService"
               behaviorConfiguration="ServiceBehavior">
    
            <host>
              <baseAddresses>
                <add baseAddress="net.pipe://localhost/NorthwindServices/" />
              </baseAddresses>
            </host>
    
            <endpoint address="CustomerService"
                      binding="netNamedPipeBinding"
                      contract="NorthwindServices.ICustomer" />
            
            <endpoint address="CustomerService/mex"
                      binding="mexNamedPipeBinding"
                      contract="IMetadataExchange" />
            
          </service>
        </services>
        
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="False"  />
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        </system.serviceModel>

    Then use the net.pipe://localhost/NorthwindServices/CustomerService/mex to discover the service in the client side.

    For more information, please try to refer to the following articles:
    #How to set that up to use WCF (using named pipes):
    http://dotnetmentors.com/wcf-by-example-on-netnamedpipebinding.aspx .

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.





    Monday, September 30, 2013 6:19 AM
    Moderator