Currently, I have 2 solutions in Visual Studio 2017:
- A Windows forms application
- A Windows service application hosting a WCF service class library (.dll)
And I need to communicate between them, in a cyclic way, as followed by the image below. The numbers represent the order.
The problem is, I'm actually able to communicate between WF and WCF application by using the request-replay operation contract (represented by numbers 1 and 4). But I'm not sure how to acomplhish steps 2 and 3.
Code for WCF interface:
namespace SmithWcfService {
[ServiceContract]
public interface ISmithWcfService {
[OperationContract]
void SendRequest( ); //Operation called by Windows Forms
}
}
Code for WCF interface implementation
namespace SmithWcfService {
public class SmithWcfService : ISmithWcfService {
public void SendRequest( ) {
//Ok, now I need to call Windows service application
}
}
}
Code for Windows service
namespace SmithWindowsService {
static class Program {
static void Main( ) {
ServiceBase[ ] ServicesToRun;
ServicesToRun = new ServiceBase[ ] {
new SmithWindowsService( )
};
ServiceBase.Run( ServicesToRun );
}
}
}
namespace SmithWindowsService {
public partial class SmithWindowsService : ServiceBase {
private ServiceHost host;
public SmithWindowsService( ) {
InitializeComponent( );
}
protected override void OnStart( string[ ] args ) {
host = new ServiceHost( typeof( SmithWcfService.SmithWcfService ) );
host.Open( );
}
}
}
