.NET Framework Bookmark and Share   
 index > Windows Communication Foundation > Exchange Data Between 2 Applications On One Computer
 

Exchange Data Between 2 Applications On One Computer

Using VS2008 C#, I need to write an application to publish data (string less than 200 characters), and an application to subscribe to this data and write it to a database. These applications will run on the same computer (not sure if this criteria will change). Some forums say that I can use named pipes, windows sockets, or WCF.

Questions:
1) Is it correct that named pipes are mainly for applications to communicate on one computer and windows sockets are for applications to communicate between two computers?
2) I understand that I can use different protocols for WCF (e.g. named pipes, TCP, etc.). Is it the same as named pipes and windows sockets but a new version and more transparent?
3) Is IIS required for any of these options (prefer not to have it installed)?
4) Any recommendation on which option I should go for?

Thanks in advance!
ElizaY
1) Named pipes provide the most secure communication since it cannot accept calls from outside the machine. Having said that, it is not the "only" way to communicate between applications on the same machine.
2) not sure if I understand your question here. Is your question about WCF Bindings?
3) If you don't want to use IIS, you can use a self-hosted WCF service
4) You can have many endpoints, using different bindings, for the same service. Currently, if communication is only restricted to the same machine then you can expose the service on named pipes. Later when your plans change, you just have to expose another endpoint with the suitable binding for communicating with clients/services on other machines.
Amit Sharma
Amit Sharma R
Hi ElizaY,

Which options you select based on your real scenario and preference.

NamePipe and System.Net.Sockets can be used for interprocess communication locally or over a network, but in this scenario we need to handle how to pass the data(the communication ends use the pre-determined format to parse the data, what security mechanism is used for data transferring, how to notify the error to other ends, etc.

WCF is one communication framework and is one of Service-Oriented-Architecture implementations. It supplies many features: session, transaction, security, data serialization/deserialization, Interoperabilty(between different platforms, one key functionality).

If you don't need so many features in your scenario, just have a look at managed NamePipe in this scenario. It is easy to use. You can have a look at out team's project: All-In-One Code Framework. There are many IPC code samples for your reference.

Of course you can use WCF to implement this issue. Just have a look at Basic WCF Programming: http://msdn.microsoft.com/en-us/library/ms731067.aspx

Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Riquel_Dong
1) Named pipes provide the most secure communication since it cannot accept calls from outside the machine. Having said that, it is not the "only" way to communicate between applications on the same machine.
2) not sure if I understand your question here. Is your question about WCF Bindings?
3) If you don't want to use IIS, you can use a self-hosted WCF service
4) You can have many endpoints, using different bindings, for the same service. Currently, if communication is only restricted to the same machine then you can expose the service on named pipes. Later when your plans change, you just have to expose another endpoint with the suitable binding for communicating with clients/services on other machines.
Amit Sharma
Amit Sharma R
So, do you recommend using self-hosted WCF (named pipes binding) instead of System.Net.Sockets and kernel32's named pipes?

Thanks a lot!
ElizaY
I am more familiar with WCF named pipe
Amit Sharma
Amit Sharma R
Hi ElizaY,

Which options you select based on your real scenario and preference.

NamePipe and System.Net.Sockets can be used for interprocess communication locally or over a network, but in this scenario we need to handle how to pass the data(the communication ends use the pre-determined format to parse the data, what security mechanism is used for data transferring, how to notify the error to other ends, etc.

WCF is one communication framework and is one of Service-Oriented-Architecture implementations. It supplies many features: session, transaction, security, data serialization/deserialization, Interoperabilty(between different platforms, one key functionality).

If you don't need so many features in your scenario, just have a look at managed NamePipe in this scenario. It is easy to use. You can have a look at out team's project: All-In-One Code Framework. There are many IPC code samples for your reference.

Of course you can use WCF to implement this issue. Just have a look at Basic WCF Programming: http://msdn.microsoft.com/en-us/library/ms731067.aspx

Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Riquel_Dong
Do you have sample code for WCF using named pipes binding?

Thanks a lot!
Eliza
ElizaY
Hi ElizaY,

There is one simplest sample about namedpipeBinding.

using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    [ServiceContract]
    public interface ISimpleService
    {
        [OperationContract]
        string SimpleMethod(string msg);
    }

    class SimpleService : ISimpleService
    {
        public string SimpleMethod(string msg)
        {
            Console.WriteLine("The caller passed in " + msg);
            return "Hello " + msg;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost svcHost = new ServiceHost(typeof(SimpleService), new Uri[] 
            { new Uri("http://localhost:8006/MetadataSample"), new Uri("net.pipe://localhost/MetadataSample") });
            try
            {
                // Check to see if the service host already has a ServiceMetadataBehavior
                ServiceMetadataBehavior smb = svcHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
                // If not, add one
                if (smb == null)
                    smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                svcHost.Description.Behaviors.Add(smb);
                // Add MEX endpoint
                svcHost.AddServiceEndpoint(
                  ServiceMetadataBehavior.MexContractName,
                  MetadataExchangeBindings.CreateMexHttpBinding(),
                  "mex"
                );
                // Add application endpoint
                svcHost.AddServiceEndpoint(typeof(ISimpleService), new NetNamedPipeBinding(), "");
                // Open the service host to accept incoming calls
                svcHost.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                svcHost.Close();
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message);
                Console.Read();
            }

        }
    }
}


Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Riquel_Dong

You can use google to search for other answers

Custom Search

More Threads

• customizing the .svc page
• Migration of WSE (with Soap filters) to WCF
• iTunes podcasts with the SyndicationFeed class
• NetTCP vs netPipe ???
• how to consume wcf service implemented with wsFederationBinding
• SVCUtil gives a lot of errors
• running Peer Channel Custom Authentication
• about svcutil general namespace
• WCF much slower than remoting
• WCF Logging in code