Communication between two winform applications using WCF?

I have two different winform applications, App1 and app2. App1 calls exe app2 (using a DOS Command Prompt window) and sends a message to run app2. Application2 starts up, and as soon as it finishes its task, it sends a message to application1 that the execution was successful. How can I get this functionality using WCF. previously the same code was written in foxpro and this final was achieved with memory management.

+3


source to share


3 answers


I think what you want is peer-to-peer communication where 2 applications (which may or may not run on the same computer) send messages to each other asynchronously. This is how chat programs like MSN Messenger work.

There's a "simple" tutorial on peer- to -peer communication using WCF on MSDN .



Remember, this is not as easy as it sounds. You may prefer to just send messages using WindowsSendMessage

.

+1


source


This is just conceptually how to do it:

You need to implement a WCF service. There are many ways to accomplish this task. One of them should be like this.

App1 calls the service method and tells app2 to execute. App1 can wait for a response.

App2 pings a service from time to time to see if it needs to run. App2 exited and called a service method to signal that it was done.



App1 will receive a response when it is complete.

Another option is not to implement a request / response, but a ping service from App1 to see if App2 has done its job.

How to implement WCF service see for example: http://wcftutorial.net/WCF-Getting-Started.aspx

0


source


Basically:

on the one hand manages the "server"

UIIServiceHost = new ServiceHost(typeof(UIInterop));
UIIServiceHost.Open();

      

where UIInterop is a class that implements IUIInterop, which is a service contract

using System.ServiceModel;

[ServiceContract]
public interface IUIInterop {
    [OperationContract]
    void SetControlValue (UIControl c);
}

[DataContract]
public class UIControl {        
    [DataMember]
    public String Name { get; set; }

    [DataMember]
    public String Value { get; set; }
}

      

Create proxy class => UIInteropClient

on the other hand, implement the client using the proxy class

using ( UIInteropClient proxy = new UIInteropClient("nameDependingOfAppConfig") ) {
    proxy.SetControlValue(new UIControl {});
}

      

===== EDIT =====

the name of the classes and interfaces only reflects my lack of imagination

0


source







All Articles