Running .NET Program As A Service - vb.net

I have a program that is written in VB.NET. It is currently interactive in that the user will click on some buttons on the form and click "GO" and it will do it's stuff.
I would like to set this up via a service on a Windows PC and instead of having user inputs via clicks have all the information in a config file.
It is my understanding that I can set this up as a service with some "parameters" on the call line, etc. and get other information from the config file.
Can someone advise me on how to do this?
Thanks

As far as I'm aware the software must have a ServiceInstaller class to install the service and a Service class that inherits from ServiceBase.
This would enable Windows to install, stop and start the service via the command line and services menu respectively.
Here's a simple example

You will need to make some small changes to convert your program to a Windows Service.
First, you will want to remove the user interface entirely - services shouldn't have a user interface.
You'd then build in the service plumbing required. Visual Studio includes a design experience specifically for creating Windows Services. For details on this, see the Creating a Windows Service Application in the Component Designer.

Related

How do I include a forms application in my service application?

I have an application that is a Windows Service application. It currently reads an XML file for it's configuration and the code works off those settings.
I have created a separate project that is a Windows Forms application (typical windows app). This app is a GUI interface into the configuration settings (changed from XML to database, but that is relatively unimportant).
What I need to do is:
Integrate the 2 projects
Add a system tray icon to pop up the form
I'm unsure exactly how to proceed on this and wanted to get some advice before messing things up.
You can't integrate these two things (entirely). A service is designed to run without a GUI of any kind (there is a work around to allow desktop interaction but this is messy and clunky and will cause you more problems than it solves)
It sounds like you just need to use the code from the service in the forms application. This should be a simple copy and paste operation.
To show an icon in the system tray is pretty easy:
Create a program to run from the system tray
how to put an .net application in system tray when minimized?

VB.Net running as a service

I have built an application that connects to the exchange server and does some scanning tasks on the incoming mail.
Application has a form where i can start and stop scanning,give in an interval, do some other configuration, and a notificationicon in the taskbar to show hide,end and so on..
The problem is that I would like the application to start as a service, because now a user has to log in first on the server before it starts working.
I tried some tools like RunAsService, i had a service, but obviously it didn't run the application.
Of course i understeand now that when the application will run as a service, scanning will be the only thing that will happen, no forms and no notification icons.
However i do not know where to start, should i extract the scanning logic from my configuration as a separate application? What application type should it become then ?
You have two easy options.
First one just create a new Windows Service Project from your New Project button in the Visual Studio, and then just program your app.
Second one, just create a service from the service management window in your computer and add the executable file of your program. It will start running as a service (with visible windows and everything as you coded it).
You should follow this link and schedule your vb.net windows program as windows task
In Your code, at the end ,when everything gets executed you should write Me.Close() to hide your form.

creating web service in VB.NET

I have just little background in web and I need to do this task by myself so I will be most grateful for your help
this is what my boss told me to do (as far as I understand) - I have to write a web service server which gets some parameters, check their validity and then insert/update them in a database. All the parameters are delivered together as a packet written in SOAP - WSDL file. I have to do it using vb.NET in Visual Studio 2010. I read a bit about it and if I understand correctly .NET takes care already of the SOAP an WSDL issue, it is transparent to me, isn't it? or should I install or implement anything concerning that? I saw some examples in the net that all you have to do is to implement web_method in the asmx file, is it so? if yes, which parameters will my method get - the whole bunch of 20 parametres supposed to be in the packet? anything I need to declare or to update in order to connect to the DB? Any help will be appreciated - uf the answer is too long I will be happy just to get a pointer to some relevant material I can read and learn.
Thanks a lot
Try reading this MSDN article: it describes how to write a simple Web service by using Visual Basic .NET
Here are the main steps from the linked MSDN article:
Start Visual Studio .NET or Visual Studio.
Create a new Active Server Pages (ASP) .NET Web service project. Name the Web service MathService and point the location to an
appropriate Web server that is running ASP.NET if necessary.
Change the name of the Solution file to MathService for consistency.
Change the name of the default Web service that is created from Service1.asmx to MathService.asmx.
Click Click here to switch to code view in the designer environment to switch to code view.
Change the name of the class from Public Class Service1 to Public
Class MathService.
Define methods that encapsulate the functionality of your service. Each method that will be exposed from the service must be flagged with
a WebMethod attribute in front of it. Without this attribute, the
method will not be exposed from the service.
Click Build on the Build menu to build the Web service.
Browse to the MathService.asmx Web service page to test the Web service. If you set the local computer to host the page, the URL is
http://localhost/MathService/MathService.asmx.

How can I stop VS2010 from lauching the wcf host when it's not needed?

I imported a vs2008 solution containing a class library with a wcf service defined in it. The solution also contains a console project which holds the hosting app for the service. The console app is set as the startup project. When I hit Debug, the console app tries to open the service host, but vs2010 also launches the generic WcfHost. This causes console app to crash.
How do I stop the WcfHost from launching and competing with the console app that hosts the services too?
or should I stop the console app from hosting?
Not exactly sure about VS2010, but in VS2008, right-click the class library project w/ the WCF service in the Solution Explorer and select Properties. You should see a WCF Options tab. That tab has a checkbox that, to the best of my recollection, is checked by default. I have long since unchecked it, but it controls the startup of the WcfHost. Again, I'm not sure about VS2010, but I would look for a project property setting that controls this.

wcf : Service + Client in same solution, how to debug? I don't want to run 2 versions of VS 2010 at the same time

I have created an application which has a client (WPF) and the Server (WCF), the service is IIS hosted, currently I am having to have 2 versions of vs 2010. One loads the wcf service in IIS and the other in my windows application.
The problem with this is it takes so much resources.
It appears if the wcf service is "NOT" hosted in IIS then I can start two projects at the same time according to this http://msdn.microsoft.com/en-us/library/bb157685.aspx
But what are my other options?
I need to find the best way of being able to compile / run the 2 projects and able STEP INTO each when when in debug, without using too many resources or having more than one vs 2010 open at the same time.
You should be able to debug both from the same instance of Visual Studio if they are in the same solution. When you run your application from Visual Studio, open the Debug menu and choose Attach To Process, you need to attach the debugger to the ASP.NET worker process (aspnet_wp.exe), it should automatically attach to your client.
Open service and client code in VS. Open Debug menu. Attach to process. Hold the Ctrl key and select as many processes as you want to debug using Mouse click.
In your case, you can select the ASP NET worker process depending on the version of IIS and the client process.
The easiest way to debug your WCF service is to:
Right click on project containing svc file.
Select Set as Startup project.
Put a breakpoint on the methods you want to debug.
Breakpoint should be Red.
Make sure your app config file is pointing to the debug WCF service version that's currently running, ex:
http://localhost:12345/MyService.svc
Run your app.
When the app calls that WCF method, it should stop on breakpoint.