locked
Can't Connect to Service RRS feed

  • Question

  • User-419934277 posted

    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

     

    Tuesday, June 2, 2015 5:46 PM

All replies

  • User197322208 posted

    Log the exception too and let us see

    Tuesday, June 2, 2015 5:53 PM
  • User-419934277 posted

    How would I do that?

    I have a Try block but it isn't catching the exception.  I am seeing a .NET Runtime error in the event log.

    Log Name:      Application

    Source:        .NET Runtime

    Date:          6/2/2015 2:33:37 PM

    Event ID:      1026 Task

    Category: None

    Level:         Error

    Keywords:      Classic

    User:          N/A

    Computer:      YS.XXXX.local

    Description: Application: YS Web API.exe

    Framework Version: v4.0.30319

    Description: The process was terminated due to an unhandled exception.

    Exception Info: System.NullReferenceException Stack:    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__5(System.Object)    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()    at System.Threading.ThreadPoolWorkQueue.Dispatch()

    Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">   <System>     <Provider Name=".NET Runtime" />     <EventID Qualifiers="0">1026</EventID>     <Level>2</Level>     <Task>0</Task>     <Keywords>0x80000000000000</Keywords>     <TimeCreated SystemTime="2015-06-02T21:33:37.000000000Z" />     <EventRecordID>2182240</EventRecordID>     <Channel>Application</Channel>     <Computer>YS.YakimaSteel.local</Computer>     <Security />   </System>   <EventData>     <Data>Application: Yakima Steel Web API.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.NullReferenceException Stack:    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.&lt;ThrowAsync&gt;b__5(System.Object)    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()    at System.Threading.ThreadPoolWorkQueue.Dispatch() </Data>   </EventData> </Event>

    Tuesday, June 2, 2015 6:42 PM
  • User1644755831 posted

    Hello jgehlsen,

    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).

    1. Create a test method in your web api with httpget verb and just return a test string. Compile the web api and debug it now call that method directly from web browser if its returns the result that means your web api launches correctly and the problem lies with your calling from console app.

    2. See this article about how to log unhandled exceptions in Web API.

    http://www.asp.net/web-api/overview/error-handling/web-api-global-error-handling

    Hope this helps.

    With Regards,

    Krunal Parekh

     

    Thursday, June 4, 2015 12:06 AM
  • User1869050296 posted

    set your proxy to the correct one or bypass the proxy as long as you can connect to the server.

    Thursday, September 17, 2015 2:38 AM