I have developed an application that calls Web APIs on a remote listener service to perform various back end functions (mainly database queries and updates). For debugging purposes, I originally wrote the listener side as a self host console application running on my local machine. I have everything working so the next step was to convert the console application to a windows service and install it on my main server. I converted the console application to a service, installed it on my server and started it up. I also configured the firewall on the server to accept incoming connections on the port that I am using. The service appears to be running as expected. The service is configured to run under the administrator account.
When I run the application, it breaks when I call GetResponseStream. Here is the error that I get:
No connection could be made because the target machine actively refused it
The URL that I am calling looks fine. It is the same one that I am calling against my console application (which works).
When I check the service after receiving this error, it has stopped. When I check the application log, I see that there is a "System.NullReferenceException" error. I have code all over the place to record when the application has received commands. None of this is being executed which makes me think that the error is happening in the parser.
Here is my startup code:
Protected Overrides Sub OnStart(ByVal args() As String)
Dim config As New HttpSelfHostConfiguration("http://localhost:21212")
config.Routes.MapHttpRoute( _
name:="DefaultApi", _
routeTemplate:="api/{controller}/{id}", _
defaults:=New With {.id = RouteParameter.Optional} _
)
Using server As New HttpSelfHostServer(config)
Try
server.OpenAsync()
Catch aggEx As Exception
ProcessError("Error opening server.", "OnStart")
End Try
End Using
End Sub
I am calling the Web API using http://192.168.0.2:21212/api/employees/12.
Here is my EmployeesController code:
Imports System.Web.Http
Imports System.Net
Imports System.Net.Http
Namespace Controllers
Public Class EmployeesController
Inherits ApiController
Public Function GetGetEmployeeInfoUsingID(id As Integer) As Employee
ProcessDebug("GetEmployeeInfoUsingID called: " + CStr(id)) ' this is where I write to a file to indicate that this function has been called
Return GetEmployeeInfoUsingID(id)
End Function
End Class
End Namespace
I am not doing anything differently than the console application so I can't figure out why the service would fail.
Any ideas?
John