2

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?

John Gates
  • 96
  • 10
  • 2
    What are your metrics for a 'good' solution? – Patrick Hofman Jun 15 '15 at 07:33
  • 2
    Remoting is a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using WCF or ASP.NET Web API. See the note at the top of http://msdn.microsoft.com/en-us/library/vstudio/xws7132e.aspx for proof. – John Saunders Jun 15 '15 at 07:33
  • Why not just use WCF? – John Saunders Jun 15 '15 at 07:33
  • 2
    I agree that WCF with net pipe is the way to go. – Larry Jun 15 '15 at 07:35
  • 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? – John Gates Jun 18 '15 at 04:41
  • You are incorrect. You can host a WCF service in any application, and consume one from any application. – John Saunders Jun 18 '15 at 04:48

3 Answers3

1

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
usr
  • 168,620
  • 35
  • 240
  • 369
0

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.

Mr Moose
  • 5,946
  • 7
  • 34
  • 69
0

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)

Community
  • 1
  • 1
d.popov
  • 4,175
  • 1
  • 36
  • 47
  • I note that the OP did not express a concern about high performance. In this case, the additional difficulty of implementing shared memory may not be warranted. – John Saunders Jun 18 '15 at 04:49