This project is read-only.

Self Hosting from a DLL?

Topics: Web Api
Nov 8, 2011 at 7:41 PM
Edited Nov 8, 2011 at 8:01 PM

I created a dll that i'm planning to use to self host my service from.  Here is the code:

Imports Microsoft.ApplicationServer.Http
Imports StructureMap

Public Class IssueTrackerHost
    Implements IDisposable

    Private _host As HttpServiceHost

    Public Sub New()

                                     x.For(Of IIssueTrackerRepository)().Use(Of IssueTrackerRepository)()
                                 End Sub
        _host = New HttpServiceHost(ObjectFactory.GetInstance(Of IssueTrackerResource), "http://localhost:8000")
    End Sub

#Region "IDisposable Support"
    Private disposedValue As Boolean ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: dispose managed state (managed objects).
                DirectCast(_host, IDisposable).Dispose()
            End If

            ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
            ' TODO: set large fields to null.
        End If
        Me.disposedValue = True
    End Sub

    ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
    'Protected Overrides Sub Finalize()
    '    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
    '    Dispose(False)
    '    MyBase.Finalize()
    'End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
    End Sub
#End Region

End Class

Something isn't working quite right. I know from my experimentation that you must run visual studio as administrator or you 
will get a security exception when you call "_host.Open()".

I don't get any error when i call open even when i don't run in administrative mode. Also its not opening correctly because i 
can not hit the service. 

We are planning to host our services locally on the user machine (architectural decision) so in the future we have the flexibility
to be able to redirect the client to hit a remote machine instead of the local machine.

Does anyone know whats going on? 
Nov 9, 2011 at 2:13 PM

Please disregard this question. I figured it out. It does actually work. It was something stupid i did in the client that i didn't notice before :)