I have a WCF Service that I already mention in another question here. As I have read here host WCF in Windows service is the best solution for all reasons. So that's why I select this option. But windows service hosting doesn't allow any visual process communication (before we used self-hosted service, that have hosted in console application and report any problems just into console). How can I get similar way for hosting service? My thoughts is about using another named pipes binding for visual "communication" between service and human.
I would be very nice for me if somebody recommend me something useful.
Thanks very much in advance guys!
In case you need the "Screen" just so that the service can report the problems, the I would suggest that you use windows event to log such events from the service and then you can create any UI/back ground process that can look for such events in window event log and report them appropriately (ex: sending email etc)
I tend to agree with #Ankur's answer, but figured I'd give you an alternative option. You could consider using WMI provide visual feedback to a running service. I attended an interesting ALT.NET talk on the subject (not WCF specific) a while back (full video is available here) and it should be relatively straightforward to instrument your application with WMI to allow you system state to be queried
Related
to put it in a nutshell:
I need to write some kind of windows service that collects data via a simple tcp/ip protocol
the collected data should be displayed on other computers inside the local area network using html/webbrowser
it should be possible to send commands/data from the viewer/webbrowser to the service
data displayed at the viewer should be refreshed if it changes. if that's not possible, polling would be also ok.
I'm using C# Visual Studio 2015.
By now the data is collected by a windows forms application (exe) and I think I can reuse some of the code (i.e. the classes for the simple tcp/ip protocol).
I already tried 'this and that', but the more I try, the more confused I am: should I use a WCF serive? WebService? REST? SOAP? Which concept is up to date, which one is outdated?
I would be very thankful if someone could give a direction what way would be good to go.
Thanks a lot in advance!
You can use selfhosted ASP .NET WEB API in your WindowsService.
This works fine and is easy to implement.
I'm working on a project that consists of a web application where users can start long process of generating different types of files.
User wont be able to download the files, only can start the process and the files will be located on the server and this process could take several hours.
My Idea to solve this its a MVC App that is communicate with a windows service and this service start the file generation process.
I have some concerns about this.
based on your experience, do you think that is the best way to solve the problem?
What is the best and easiest way to communicate the web app and the windows service? this is a one way communication, web to service.
About the windows services; should the service do all the processes? or maybe its better if the service only execute console applications that do the generation o the different type of files.
I really appreciate your help.
Since Web API can be self-hosted in any process and a Windows service isn't an exception, I would recommend hosting both HTTP API and the long process thing in the same Windows service.
Use OWIN/Katana to host your Web API.
Use Topshelf to create your Windows service.
If you design and implement this Windows service using best practices, it should be a good solution, and you should think about how easy will be the deployment of your solution since you don't need IIS anymore.
I would go still with the IIS. This is because of its support. Have been using Web webservice to host long running background service for long time without issues. Only concern is to remove the default application recycling.
Of course your application will need to handle properly start/stop events.
I have a requirement where I want to implement a WCF Service which checks a status from a Database column after a certain time interval lets say 20 minuets, if this status is true I want to execute some operation else some other operation.
So is it possible to implement the desired functionality using WCF Service, If yes please guide me how should I implement, As I have no idea how to do it.
If its is not possible, then please suggest me some good options like (Web Services, windows service etc.).
Please provide me sample code or some good links where I can find the way to approach this problem.
I want this service to run on my PC always and check status after 10-20 minuets.
I am more comfortable with C#, So If it could be done in C# its well and good.
Otherwise also not an issue.
I have windows PC
What you describe is a Windows Service. A Task running in the background, even without an active user login, that executes code periodically. Look up a tutorial on Windows Services, maybe start with the Visual Studio template for building one.
I think you miss the idea of WCF and only see word "service". WCF service is used to call some code on the server from remote machine. It is not supposed to do any work on its own. Only when called.
By your description, you should create a Windows Service, which should have a loop. It will look how much time has passed and execute your action.
There are two common options:
1) windows service
2) long running service in AppFabric
Depending on production environment, second one might be not acceptable. But it have real benefits:
1) you don't need admin access to server
2) you can use FTP/Web Deploy publishing
3) you run service in IIS with all it cons and pros
I've been away from web development for 6/7 years now and I'm completely lost in regards to how to do things. I'm going through some tutorials on HTML5 and whatnot, but I was hoping to get a helping hand here.
I'm trying to build a (POC) website which would have the "server" monitor it's running applications and when a certain application is running change the content of a hosted page. I don't want the model to be PageLoad->Application Check, I'd rather have something like ServerStart->ApplicationHook->Callback->Model->PageLoad->CheckModel, so a hook is put in place when the server starts and the callback of the hook updates a model which the page uses to update. Although this architecture may not be the best way, in general I'm just looking for a way to have a long running process which starts when the server starts up. Eventually I'l move this to a Windows service which calls a webservice when changes are made, but for a POC I'd rather keep away from multiple applications interacting, as the Windows Service would need to be "called" by the server too and I can't think of an easy implementation of that at the moment.
So, if you were building a page which relied on events on the server and needed to be able to interact with an application on the server separately to an individual page, but the page needs to be able to "post" information back to that application what would you do?
My explanation has been a bit all over the place, so I hope at some point my question has come across clearly! :)
Maybe there're alternatives but I think your only option for this kind of setup is a Windows service. If you need to talk to it from other components, have it use sockets or listen for HTTP requests on a known port. Doing what you described from a web application is not impossible but it'd be certainly very hard since it's the web server (app pool executable) that controls what happens in the process, not your code. In a Windows service, you're in control.
Edit: here's an article about the different options for hosting a web service - it seems to me that using a Windows service is, indeed, your best choice. You may be able to use a WCF service but you'll have to talk to a local application on the server and that part may be easier to do just using a Windows service.
suppose i have a windows service which does some work and developed by c#. now i want to develop a another win apps with c# which control & interact with my win service. suppose i want to start/stop my win service from my win apps or i want to run a specific method of my win service from my win apps. how to develop this type of win apps which can interact with my win service. please discuss in detail.
thanks
You may find the following article useful.
For starting and stopping see ServiceController class
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx
You can also pass parameters on start.
For controlling use the ServiceController class as stated by the other.
Do make your service to do something special controlled by your app you have to set up a kind of communication. I would suggest your service listens on a certain port for http request which can be handled fairly easy and so your service might be controlled by any kind of app even javascript ajax. If unwanted add some security like authorization.
For communication between a Windows service and a Windows application, I use Windows Communication Foundation (WCF). In my Windows service, I host a WCF service that "listens" for incoming requests. My Windows application creates a WCF client that communicates with the WCF service hosted in the Windows service. From a programmatic point of view, the WCF client invokes methods on the WCF service. All of the behind-the-scenes complexity is hidden, so from a programmer's perspective, it looks like you are simply making a function call.
To start and stop the service, I use the ServiceController class. Note that this class has certain security requirements. A user with limited system privileges will be unable to use this class directly.
You need to be aware of security.
Using the ServiceController class gives you some limited ability to control a service (start/stop/pause/resume and send simple commands), and has the advantage of being secure. Typically only Administrators (and maybe Power Users) will be able to control the service although you can configure permissions.
If you need something more flexible, you need some form of inter-process communication to communicate with the service - and WCF is a good option in the .NET world as described in Matt Davis' answer.
However in this case you need to implement your own security, assuming you don't want to allow just anyone to interact with your service.