I have written a program in C# using Visual Studio 2010. At current it is a Console Application and what I ideally want is to have this program running on a server. It logs messages in a SQL database that I can view via a website no problem, but what I want is to be able to control the C# program and call methods remotely via the website in the browser too. I have defined these methods that contain calls to other methods in the program such as 'ArticleOrganizer.reprocessArticle(a, 0)':
[ServiceContract]
public interface IRemotePrimeService
{
[OperationContract]
void ProgramRestart();
[OperationContract]
void ProcessArticleAgain(Article a);
}
public class RemotePrimeService : IRemotePrimeService {
public void ProgramRestart() {
Console.WriteLine("Restart requested remotely. Program restarting.");
Application.Restart();
}
public void ProcessArticleAgain(Article a) {
// Log the activity
a.MessageLog = "Reprocessing requested remotely. Article sent to Stage 0 of pipeline.";
// start the article through the processing again
ArticleOrganizer.reprocessArticle(a, 0);
}
}
These are what I want to be able to call remotely. It seems Services in WCF is how one would do this, but can I put this C# Console Application on the server as it is somehow without having to rewrite it as a Web Application? I have read A LOT of the documentation, particularly on MSDN but would appreciate a simple step-by-step of my best course of action. I have installed and set up IIS开发者_JAVA技巧 on my computer to test as a localhost.
Many thanks in advance for your advice
Keep it simple, and use a simple async event-driven system.
For example: Introduce a queue where messages to the application can be stored. The application (whether it's console or service) can read the queue when it has time and execute the requests. The queue can be f.e. MSMQ or a SQL table. Works great as long as you won't need instant feedback, which is the case most of time in these kind of systems.
精彩评论