Workflow application in c# - c#

I have a workflow application hosted (for now) in a Console Application, using WorkflowServiceHost to host an activity. This was based on a MS example, and works fine.
I'd like to add another 'WebMethod' to this application. This method has nothing to do with the workflow being hosted - it will simply be a 'ping' service so that clients can tell that the application is alive and running.
Is this even possible? If so, how would I go about adding this new method?
Thanks

Don't create a new method inside the Console Application as that would be poor practise (1 thing should do 1 job)
Instead create a new WCF project inside your solution.
Reference this project in your Console app and start the WCF host when the Console app initializes.
The WCF project can then be written to respond to 'ping' requests.
This is a handy primer in WCF
http://www.codeproject.com/Articles/406096/A-beginners-tutorial-for-understanding-Windows

Richard,
Thanks for your answer. I was able to add a new endpoint to the Console App but defining the service interface, and adding another host and starting it.
This is fine for the proof-of-concept code, but wouldn't be acceptable for release.
Dave

Related

Difference between a console application and Web application in asp.net core

I am trying to run a background service which just writes to a file on a specified interval.
There are two methods that I tried
1) Created the project with the Console application template
2) Created the project with Web Application as template
When I run the app from visual Studio, both of them run fine. But when I deploy them to IIS, only the web application version works. It must be noted that there is absolutely no difference between the code of the two projects. I have used the WebHost as a hosting strategy in both the projects as well as well as installed all the dependencies in case of Console application as there are in the Web Application version.
I must also inform that I have used the preloadEnabled="true" option in IIS as IIS needs a web request to start the application.
I am wondering what is the difference between both the project types as the code is the same? I don't want the Web Application template.
Edit 1: I forgot to mention that the service will also need to expose an api endpoint for healthcheck purposes. Will the windows service approach listen for http requests?
I used the following article for implementing my background service.
https://learn.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/background-tasks-with-ihostedservice
After years of building background services, I learned that Windows services are the best tools to implement these applications. While there are different techniques to keep an IIS application up and running in the background and prevent it from getting recycled, in practice, the applications on IIS are not meant to be executed forever.
If you had an intention to build your app in the cloud, I would have suggested using something like Azure WebJobs or Azure Functions Timer-Triggered functions, but for on-premise, even using something like Hangfire in the web is not sustainable. The worst happens when you need backward compatibility on Windows servers that don't have the "Application Initialization" module.
My suggestion is to move your application to a simple Windows Service if you control your environment. Windows services consume less memory, are easier to manage, and can run forever without getting recycled.
WebApplications are plain the wrong tools for this.
Being always on and always reachable, WebServers are primary targets for hacking. To compensate for that, they are usually run under the most restrictive user rights you can imagine: Read rights to their programm and this instances content directory. While I do not know why it worked at all, it propably will stop working in Production.
What you wanted to write was eitehr a Service or something executed by the Windows Task Sheduler. Personally I advise for the Task Sheduler as Services have their own set of restrictions. Unless of coruse there is some detail of the requirements that you did not told us.
This article could be helpful. It's a step by step tutorial on how to convert a console application to a web application.

.Net Architecture suggestion; Start process from web

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.

Start/stop self-hosted WCF data service programmatically

HI I have a solution with a couple of projects.
One of them is a self-hosted WCF Data service.
This service is running fine on his own, but I want to start it from my main method.
This way I can control wether is should start or stop.
Why I need to do this is that I can run my main method and let the service start, but when the program exits, the service is still running.
Anybody know how to fix my problem?
--EDIT--
This service thing is new to me. So I'm not even sure it's possible.
Let's say I have 2 projects. One contains my main method and the other is a WCF Service Application project.
I want to be able to stop my service from within the main project whenever I want to.
--EDIT2--
I am creating a system that can provide data to clients through an API (WCF Data services). When my system starts, I want to start the service. When my system shuts down, my service have to stop existing or at least providing data.

WCF Client Not working when outside solution

I have created a WCF service hosted in a windows service.
Basically all the service does is that it gets data from the database, does some work in memory with it and save data back to the database.
i created a windows form client to consume the service.
Inside the solution of the service, i added a service reference to the service in the project and everything works fine, however when i installed the service and run it, i created a separate client project and referenced the hosted service.
When i call the function that does the work, it doesn't work. (it must update a flag in the database)
Can you please suggest what may be causing this problem, i have not posted any code example because the code is too big, mainly it uses ado.net, Nhibernate ...
If the service is in another project it is likely not running when the second project attempts to access it.
Either setup IIS to expose the service (this is normally how a production environment would be setup) or as a test, use the IIS Light (Cassini) that is provided with Visual Studio to host the service.
Once either of the choices above have been implemented, configure the client to use the service - the URL likely changed.
I found the solution.
The configuration of my WCF has to be placed in the configuration file of the host, which is a windows service in my case.

How to make a C# application act as a service?

I have developed a C# program, although when I try and create a service from it e.g.
sc create "servicetest" binPath=
"C:\Users\Admin\Desktop\test\test.exe" start= auto error= ignore
I get the following message:
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
You need to create it as a service through the Visual Studio interface, which will provide you with the correct classes and methods you need to implement.
You need to base your application on the Windows Service template available in Visual Studio (not available in the Standard Edition.) See here:
How to: Create Windows Services
There is also another way of implementing windows service using TopShelf. You can actually run a console application as windows service using topshelf. Advantage of it is easy to debug. As far As I know when you want to debug windows service, you have start the service in service console. Stop the service if you are compiling and service installed from build output directly. It is extra painful step.
If you are using topshelf, you can start the service like how you start windows forms application to debug. There are other benefits too. Please refer the web site.

Categories

Resources