"Talking" with a windows service C# - c#

I need a good and easy way to "Talk" to a windows service in C#
I have been able to create a windows service and start, stop, pause and continue it using a windows forms application.
My question is
Which is better and/or easier to accomplish this? WCF or Named Pipes? Or is it easier to do it using a file and make the service check it after some interval continuously?
I am very unfamiliar with both concepts(wcf and named pipes). So basically what i am asking is:
Which is worth my time? WCF or Named Pipes?
Thank you in advance :)

Ok, just provide a simple interface in c# with the following codes for doing what you wanted start,stop,restart etc
http://www.csharp-examples.net/restart-windows-service/
additionally, you may want to look into
SC commands which are specifically a way to interact with windows services..
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682107(v=vs.85).aspx
or even WMIC for remote access
http://msdn.microsoft.com/en-us/library/ms186146%28v=VS.80%29.aspx

Related

Scheduler program in C#

I am working on a client server project. Client is built in WPF using mvvm pattern and service is built using WCF. I have to perform some action on a specific event which I am able to do by calling some service functions. I will have to do call the same function on a regular basis at a specific time as configured in database. Can somebody suggest a better approach to achieve this. I am thinking of creating a windows service specifically to do such things. Is that a good choice ? Thanks a lot.
Create a console app that calls the service, and add a scheduled task in Windows to run the console app at a specified interval. It is a lot easier and cleaner than creating a service for such a simple application.
I think the best approach is to use an already created (and properly tested) scheduling system or library instead of developing your own. For a Java project I worked on, I used the Quartz library, which handled the job quite nicely and it integrated easily into said project. It has a .NET port here, never used it but I suppose it works similarly.

C# Windows Service With Command Line Access/REPL?

This is my first time dabbling in windows services.
I have a service I would like to manage, I would like to be able to connect to this service via a command line / REPL of sorts to avoid the development time of working on a user interface. I was thinking we could communicate much like attaching to an Asterisk daemon or somewhat like connecting to a MySQL server which to me seems like nothing more than a simple custom shell spawned to handle requests. However, I am always concerned about how efficient my code is and would like to keep to common practices. This will be connecting on the same local machine.
My proposed solution:
I believe I can make simple network stream, to create a simple Read - Eval - Print - Loop.
Another option is to use WCF, however my question would then be, how efficient is this as opposed to packet handling?
My question:
What are some standard practices for communicating with or managing services on the local machine?
I'm trying to learn more about service-oriented design, any resources that could help explain common practice models would be much appreciated.
Of course there are so many ways to do this. The way I would recommend is to make sure you use log4net (or some other logging framework) and log the important info. Create the solution with 3 projects, the first will be the "service logic" or the business service, with the second being the windows service wrapper that starts that service, and the third being a console app that does much the same as the windows service only giving you the ability to interact as you wish. The advantage of the console logging appender is that you still get the console output without actually writing to the console... it give good separation.
I will give another option that I have used in the past, but would give with caution. You can selfhost a WCF service inside a windows service. It gives a nice interface that gets away form the messy self rolled TCP server approach. The caution is that if done wrong it can eat up lots of memory and CPU cycles.

how to expose API from windows service application

I am working on windows service application that is suppose to perform some tasks. Apart from these tasks, I want to make some of the service functionality available on call. Means, totally separated application should be able to create an object of type specified on windows service and can call some of the functions, decalred public, ofcourse.
Let me know if is there any way to expose the functionality through API or something. if yes, kindly guide me to any tutorial or example of that.
Thanks in advance.....
I think what you are looking for is a windows service using WCF to communicate with other applications.
Here's a pretty neat tutorial you can work through:
http://tech.pro/tutorial/855/wcf-tutorial-basic-interprocess-communication

How to create a failover window service?

i have an requirements where i need to have two instances of the custom window service code running at the same time but only one should be doing the work until the other one fails or die.
i'm trying to come up with the clean and simple design to do this.
one way:
create a temp table
and have this two service talk to each other via the table
and if the running one goes down, using probably last modified date
time on the table
then the other one will start
but this is very manual. i'm using c# 4.0.
are there better ways to achieve this?
i saw there's something like EventWaitHandle but not sure if it would be simple to use it.
thanks
~m
Implement a kind of lock/mutex using a common database (as you mentioned)
If the instances on the different servers know of each other (config?), they can chat with each other and decide who's boss.
If the instances do not know of each other try using an UDP broadcast to announce themselves to each other and then decide who's boss.
If you are able to do #1 and do it generic exposing it through a web service that solution would be reusable for other applications as well. I use such a solution myself.
Consider exposing a ping api endpoint (simple Rest API ping method) on both services so that each can monitor the other service state.

how to create a vpn software

I want to create an application which creates a VPN between some endpoints, something like hamachi and i do not have a starting point. I haven't found any resource to explain how to create such a network application.I want to use c# because i have some experience with it.
I really need some help, anything that can put me on the right way. Thanks.
There are a number of distinct elements of VPN software that you'll have to figure out:
What technology/standard will your program use to provide the privacy? Some common ones are IPSEC, L2TP, PPTP, SSH, and SSL. Web searches ought to turn up rich information (including RFCs) on all of these. If you're doing this as a learning exercise, rather than needing actual security, you could also design your own.
Are you implementing a client, a server, or both?
What operating system(s) will you support? This affects what you need to do to convince it to route packets through your application.
Do you plan to interoperate with software implementing some standard?
You might want to take a look at SSH tunneling and see if it solves your needs.

Categories

Resources