Required methods for a VB.NET service? - vb.net

I’m taking over a project in VB.NET. The project is a windows service that is responsible for processing certain information from several databases and creates a text files with information required by the business. I'm having problems when starting the service once compiled. Every time I try to start the service the following error appears.
Error 1053: The service did not respond to the Start or Control
Request in a Timely Fashion.
My impression is that for some reason when I compile the project, the executable that is created does not have the characteristics that distinguish it as a Windows service. When I double click the .exe file no error appears anywhere. But through the Service Manager never works.
I saw in the code base that the Public Sub Main () method is commented. My question is, it is a requirement that in order to compile the project to be recognized as a service a Public Sub Main () method should be defined at least once in the code base?

Related

Workflow WCF Service - Can't call from application - The request object expects an argument that I can't identify

I have created a WCF service using Workflow. It works just fine. I created another Workflow application to consume it. I added the service reference to the application project and rebuilt the project. I added the component from the service to the app, but it's expecting an argument that I never specified.
I've tried rebuilding both the service and the app, generating an entirely new solution and starting from scratch - same problem. I've looked at others' code and they've structured this project the same as mine but this issue does not show up on theirs. Googling this problem seems to bring up not results.
My workflow service is defined as such: https://i.imgur.com/E8mEfs6.png
The parameters of the receive component are: https://i.imgur.com/TaNRw2y.png
But when I add it to my app, the parameters are defined as: https://i.imgur.com/tqgEwNr.png
Which is not what I had defined in my service. I can't even figure out what it wants me to pass in for _GetCityStateFromZip. It says the type is InArgument.
I was expecting it to be expecting the zipcode parameter as I specified in the service. I think I might be adding the service reference incorrectly, but I don't know how. I went to Add Service Reference in Visual Studio, then copy/pasted the path to the .xamlx file of the service on localhost.
Thank you.
I found a solution to this problem here:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/5279fc5f-8a53-43e7-8ef2-3073808dc90f/configuring-workflow-services-how-to-configure-workflow-control-endpoint?forum=wfprerelease
I re-made my service using the steps listed and it works as originally intended.

Windows Service will not start as Local User

EDIT 2: I now believe this is an issue with the machine I'm attempting to run the service on. I tried moving the service to a different machine that is setup similarly and the service was able to start successfully even as a Local User. Now I just need to figure out what's different between the two machines...
I have a Windows Service project (written in VB.net) that is installed and configured with a Startup Type of Automatic and the Log On As set to a Local User account. This service will start when the computer first starts up. However, if I stop the service and try to start it again, I get "Error 1053: The service did not respond to the start or control request in a timely fashion." immediately. However, if I change the Log On As to "Local System account" then the service will start.
Summary:
Service will run as Local User when computer first starts
Service will not run as Local User if started manually
Service will run as Local System when computer first starts
Service will run as Local System if started manually
I have read that Error 1053 is caused by the OnStart method not returning quickly enough. The fact that the service has started previously, and that I get the error message immediately, leads me to believe a timeout is not what's going on. To verify this, I created a completely new Windows Service Project and without changing anything I built and installed it. I get the same behavior.
I am at a loss as to what's happening. As far as I can tell, the Local User has all of the correct privileges to run a service (as is evident by the fact that it will start with those credentials when it the computer is first starting up), and the OnStart method isn't actually timing out (as is evident by the completely blank dumb service exhibiting the same behavior).
Any ideas as to what's preventing the service from starting, or where I can look for better error messages (I have looked in the Application Event Log, but nothing shows up there)?
EDIT:
Here is the code from the dumb service I created (using the EventLogger from here as a module).
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
EventLogger.WriteToEventLog("On Start")
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
EventLogger.WriteToEventLog("On Stop")
End Sub
And the Main method of the same project.
' The main entry point for the process
<MTAThread()> _
<System.Diagnostics.DebuggerNonUserCode()> _
Shared Sub Main()
EventLogger.WriteToEventLog("Starting Main Method")
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service1}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
EventLogger.WriteToEventLog("Leaving Main Method")
End Sub
When I try to run the Service as the Local User, none of the messages show in the Event Log and I get Error 1053. When I run the Service as the Local System, the messages show in the Event Log.
The reason I need to run the actual service as the Local User is so that it can access a network share. I am currently looking into using Windows User Impersonation, but I still think I should be able to start a simple service as a Local User.
Use this resource to create an event logger. Then wrap your code in each sub in a try/catch b/c most likely something is happening in your OnStart sub that is preventing the service from starting. Post some sample code of your onstart, onstop, and/or your service main subs and clarify why you need to use the local user vs the local system.

vb.net console / service app

I'd like to enable my console app. to be installed also as a service using command prompt arguments, handling the following commands
d\:>myapp -console
d\:>myapp -install
d\:>myapp -uninstall
My vb.net service template is as follows,
Public Class MyService
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
End Sub
End Class
How I should proceed to run it as console and/or console.
Thanks in advance,
m0dest0
Ps. using vb.net and Vs 2008
Ps2. The kind of taks to be performed is suitable to be implemented either in console or service. Basically it will monitor files in a specific folder and the process the info.
This is doable, I have a service that does this very thing.
The main business logic should be encapsulated such that it can be run (launched as a thread) from within the Service or from a shared sub Main.
You will need to add a service installer if there is not one already, but the VS template adds that for you so you should be all set.
In your Main, you have to parse the command line (obviously) and execute the appropriate action. I would recommend, for one-stop-shopping, adding a -start and -stop command line option as well to stop and start the service.

Error 404 - file not found on Silverlight RIA service call

I have search everywhere for a solution to my problem, but I am not able to find one. I have built a Silverlight 4 Navigation app, and am using RIA Services to process a custom entity (which is essentially running server-side calls to COM dlls). In my debug environment, everything works fine, but when I try to deploy to IIS7 (on the development machine) as a website, it gives me the following error when calling the Get query on the entity:
Load operation failed for query 'GetNewHWCoil'. The remote server returned an error: NotFound.
at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
Everything I found online says to check the Authentication area on IIS and make sure that it is set only to Anonymous Authentication, which it is. And they also say to enable WCF logging, which when I add the necessary text to the web.config file, I still don't get any logs. They also say to use Fiddler2 to trace the HTTP calls, but I only get a 404 error on there with the textview giving me the standard IIS file not found website. I cannot figure out how to debug this problem.
The Silverlight app needs to make calls to a set of 3rd party COM dlls to calculate the performace of water coils. Since I do not want to have the app run OOB, (this will negate the whole point of it being a web app instead of a WPF app) I have the ASP.net project interacting with the dlls using the custom entities.
The function (or Query as RIA services calls it) GetNewHWCoil is located in the DomainService class and uses this code:
Public Function GetNewHWCoil() as HWCoil 'HWCoil is a custom object
If bRanCalc then 'bRanCalc is a global boolean variable that gets set to true if the calc call on the dlls have been made
Return mHWCoil 'global copy of the calculated coil object
bRanCalc = False
else
Return New HWCoil
end if
End Function
The error runs before any calculation should be called, so it is assumed that it is erroring on the 'Return New HWCoil' part.
Any help on this would be appreciated.
Thanks,
Chris
I found the solution to my problem. I fonud out that I can have VS run the debug from IIS, and when I had it create the virtual directory it told me I needed to install ASP.NET 4 on the server. I thought that by checking the ASP.NET checkbox in the Add Windows Features dialog that I had already done that. But it only installed .NET 2 version. So after looking online for this new problem, I found that I needed to run the command
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i
and everything worked fine after that.
Chris

Unable to debug web service project in Visual Studio 2008

I've been assigned a web app written in VB using VStudio.net 2003. I am trying to configure the source on my localhost (VStudio 2008) so I can explore and learn about the current app (before I begin any real changes) and I cannot get debugging working for the web service project(s).
Symptom 1:
"Unable to automatically step into the server. The remote procedure could not be debugged.
This usually indicates that debugging has not been enabled on the server.
See help for more information".
This happens when I try to F11 (stepInto) the proxy class which invokes my actual web method.
Symptom 2: Pre-setting a breakpoint in my .asmx file code on the statement that will be invoked does not work (i.e. the debugger simply doesn't stop).
Having described the situation, here's how my VStudio Solution is configured:
Service1 - project created from the VB - WEB - ASP.NET Web Service Application template; this Service1 project contains my main .asmx source code I want to debug. Web.config for this project contains compilation defaultLanguage="vb" debug="true"
ProxyService1 - a separate project created from the Windows - [VB]Class Library template; here the form1.vb file was deleted; I visited "Add Service Reference" -> Discover (Services in solution) and then in the "Compatibility" section I click "Add Web Reference". Then choosing the above Service1, I assign it a "web reference name" of WSservice1. This results in a Reference.VB file and when I build the ProxyService1 class a .DLL of the same name in the projects bin\Debug folder; this project has an App.Config file with compilation defaultLanguage="vb" debug="true"
Project1 - the main UI project with the .aspx and .vb files that call the webservice; project1 has a reference to ProxyService1.DLL; Web.config for this project contains compilation defaultLanguage="vb" debug="true". I arrive at a breakpoint in one of the files in this project called message.vb which looks roughly like this:
Public Class Message
Dim wsZipeee As New ProxyService1.WSservice1.myService
Dim dsMessage As DataSet
Public Function GetMessageByType(ByVal iMsgType As Integer) As DataSet
dsMessage = wsZipeee.GetMessageByType(iMsgType)
If I rightmouse/go to definition on the stmt above, here is the code in Reference.vb in my ProxyService1 project:
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ZipeeeWebService/Zipeee/Get Message By Type", RequestElementName:="Get Message By Type", RequestNamespace:="http://tempuri.org/ZipeeeWebService/Zipeee", ResponseElementName:="Get Message By TypeResponse", ResponseNamespace:="http://tempuri.org/ZipeeeWebService/Zipeee", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function GetMessageByType(ByVal iMsgType As Integer) As <System.Xml.Serialization.XmlElementAttribute("Get Message By TypeResult")> System.Data.DataSet
Dim results() As Object = Me.Invoke("GetMessageByType", New Object() {iMsgType})
Return CType(results(0),System.Data.DataSet)
End Function
For completeness, here is the corresponding webmethod in the .asmx file of the Service1 project:
<WebMethod(MessageName:="Get Message By Type")> _
Public Function GetMessageByType(ByVal iMsgType As Integer) As DataSet
con = New SqlConnection(sConnZipeee)
con.Open()
Everyplace in IIS I know to check and within the project properties I have checked for the proper Debug setting to be checked or set on. I've debugged other things that are set up like this but I am truly stuck on what I've missed on this "solution".
For info - if you have got here looking how to debug a .NET4 web service from VS2008/.NET3.5 app, you need to start the service in VS2010, set a break point in the service and then run your app from VS2008 as normal. The break point will be hit.
Without running the service in VS2010, you will get the error described by John above.
When I debug webservices, I usually select the option "Don't open a page. Wait for a request from an external application" in the Web section of my project properties (more info here). I also usually run the project in 2 instances of VS, one for webservice and one for client. I can put break points in the webservice and everything hits and I can see what is happening.
try to attach debugger on running aspnet_wp.exe process
I normally put of the logic to debug in class library that I can start with a console application for debug. This link will be useful too if you must debug as a service.