1

I have created a C# WPF project. I have two exe's running, both are created by me. One exe has a Window and another doesn't.

Now I want to communicate from the exe to the other . I want to send a small message from exe (no window) to the other.

I really confused about this IPC in Windows C#, can anyone suggest me which one will be good for this problem

user2431170
  • 151
  • 2
  • 11
  • @sthotakura. Could you please share any links or samples . – user2431170 Nov 21 '13 at 07:15
  • 9
    @user2431170 Could you please use a search engine? – Jonathon Reinhart Nov 21 '13 at 07:15
  • @user2431170 http://tech.pro/tutorial/855/wcf-tutorial-basic-interprocess-communication – Suresh Nov 21 '13 at 07:17
  • @JonathonReinhart. As I have already metioned, I was confused to implement IPC in C#. Sorry that I am not a Genius like you to find out everthing I need. And FYI, I have posted this question after googling for almost 1 hr – user2431170 Nov 21 '13 at 07:50
  • @sthotakura. Thank you so much. The tutorial which you shared is really useful. – user2431170 Nov 21 '13 at 07:50
  • @user2431170 He said "Use WCF named pipes". If you google that term, you'll find tons of examples, like [this one](http://stackoverflow.com/questions/7353670/wcf-named-pipe-minimal-example). – Jonathon Reinhart Nov 21 '13 at 07:51
  • Hi @JonathonReinhart. I have used the named pipe, but getting error in the endpoint. Could you help me ? Server Code : http://pastebin.com/n16zCMbZ CLient : http://pastebin.com/n0N2CChW – user2431170 Nov 21 '13 at 09:36
  • @user2431170 If you have a question with a specific piece of code like you've linked to, *that* is the kind of questions we want! Post that as a new question, showing what you've tried, what you expected, and the error messages that you're getting. – Jonathon Reinhart Nov 21 '13 at 22:31

1 Answers1

2

You should not be rude in your comments.

Now try this:

On the client: create a client side proxy with the following few lines

// Create  the proxy:
EndpointAddress ep = new EndpointAddress("net.pipe://localhost/SomeAddress/PipeEndpoint/");
IMyinterface instance = ChannelFactory<IMyinterface>.CreateChannel(new NetNamedPipeBinding(), ep);

// now use it:
instance.SendMessage();

On the server side, run the server and register the object to do the work:

ServiceHost host = new ServiceHost(new MyClass(), new Uri("net.pipe://localhost/SomeAddress"));
host.AddServiceEndpoint(typeof(IMyinterface), new NetNamedPipeBinding(), "PipeEndpoint");
host.Open();

The MyClass code on the server side too:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MyClass : IMyinterface
{

    public void SendMessage()
    {
        // do something here
    }

}

And the interface should be in separate project referensed by both, client and server projects:

[ServiceContract]
interface IMyinterface
{
     [OperationContract]
    void SendMessage();
}

Remark: when I say "Client", I mean the one who sends the message. Server is the one who receives the message. I think in your architecture is the opposite, so I wanted to be clear with my terminology.

I hope it helps

000
  • 26,951
  • 10
  • 71
  • 101
Rami Yampolsky
  • 465
  • 4
  • 12