I have developed some backend console apps which are supposed to run on the server.

They are called Server Process and Server Agent. The Server Process always create instances of server agents (as a process) time by time, here is the code for calling server agent

private static void CreateUpdatedBookingAgent(UpdatedBooking oUpdatedBooking)
{
    try
    {
        //Run the Console App
        string command = @"C:\ServerAgentConsole.exe";
        string args = ("UpdatedBooking " + oUpdatedBooking.MeetingKey + " " + oUpdatedBooking.ServiceAccountEmail.Trim() + " " + oUpdatedBooking.ServiceAccountPassword.Trim() 
            + " " + oUpdatedBooking.ServiceAccountEmail.Trim()+ " " + oUpdatedBooking.MailBoxOwnerEmail.Trim() + " " + oUpdatedBooking.Method.Trim()
            + " " + oUpdatedBooking.ExchangeURL + " " + oUpdatedBooking.ApiURL + " " +  oUpdatedBooking.Subject + " " + oUpdatedBooking.Location 
            + " " + oUpdatedBooking.StartTime + " " + oUpdatedBooking.EndTime).Trim();

        Process process = new Process();
        process.StartInfo.FileName = command;
        process.StartInfo.Arguments = args;
        process.EnableRaisingEvents = true;
        process.Exited += new EventHandler(processExitedUpdatedBooking);
        process.Start();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

My question is:

  1. Can I use .NET remoting for this, I mean is it a good way of doing this?

  2. If not, is there a better way of passing the data (arguments) to the server agent?

  3. The server and client both must be console application. According to my knowledge, the I can not get a benefit from WCF in that case. Am I correct?

3

There are 3 answers

0
Mr Moose On

While WCF is quite rightly the best way to go, I have recently faced a similar issue to what you are facing. My scenario was the need to call a .NET 4.5 console app from a .NET 2 Winforms app.

The data being passed was trivial and I deemed it easier to simply serialise the data to disk and pass the filename of the serialised data to the .NET 4 app. The .NET 4 app retrieves the data from the filename it receives when it is called, and removes the file.

I'm not saying it's pretty, but it is effective and may be worth considering.

0
usr On

Remoting or WCF are good ways to do this. You probably should choose some of the "IPC" transports because they are restricted to local machine communication. That's a nice security guarantee.

Note, that Remoting is considered obsolete. The .NET Framework source code has the Remoting feature behind an #if FEATURE_REMOTING so they can delete that feature easily from the framework.

Make the parent pass the communication endpoint to the client. There is a security issue in the sense that anything on the local machine might connect to that endpoint. A simple strategy to deal with that is to pass a securely generated Guid on the command line to the child and make the child use that to authenticate. Or, base the endpoint URL on that Guid.

1
d.popov On

It seems is not trivial to do, but using a shared memory between processes should give the best performance.

How to implement shared memory in .NET?

Shared memory between 2 processes (applications)