1

我有一个 Windows 服务,它使用 WCF 在 4 个端口上公开相同的接口。地址是:

net.tcp://localhost:1200/IContract
net.tcp://localhost:1201/IContract
net.tcp://localhost:1202/IContract
net.tcp://localhost:1203/IContract

这项服务已经投入生产了很长时间,有时它会中断,我什至无法远程登录有问题的端口。我通常必须重置服务。

我真的不明白为同一个合同有很多端口,但这个解决方案可能掩盖了最初的问题。

无论如何,是什么导致服务主机在服务器端崩溃?客户端是否会使服务主机崩溃,或者它可能与某种拒绝服务有关?

PS:这个问题偶尔会发生,我无法在开发中重现。在生产中使用跟踪也不实际。

谢谢

4

2 回答 2

2

您可以向华生医生寻求帮助。您可以为您的应用程序配置WEH(前提是您可以签署您的代码)。或者,您可以使用bugcollect.comexceptioneer.comerrortc.com等工具收集崩溃信息。

但最终,您不能只是简单地问“任意进程如何崩溃”。方法实在是太多了。您最多可以得到一个通用的答案(“它崩溃了,因为它取消了对受保护地址的引用”)。

于 2010-07-12T17:15:11.813 回答
1

服务主机可能会失败。你是否解决这个问题并不重要,他们只是在下一次以不同的方式失败。

我通过创建自己的包含日志记录和自动重启功能的 ServiceHost 子类型来解决这个问题。

Public Class RestartableServiceHost
    Inherits ServiceHost

    Private m_Log As FileLogger
    Private ReadOnly m_FaultResponse As ServiceHostFaultResponse
    Private ReadOnly m_Name As String

    Public Sub New(ByVal serviceType As Type, ByVal faultResponse As ServiceHostFaultResponse, ByVal log As FileLogger)
        MyBase.New(serviceType)
        If serviceType Is Nothing Then Throw New ArgumentNullException("serviceType", "serviceType is nothing.")
        If log Is Nothing Then Throw New ArgumentNullException("log", "log is nothing.")


        m_Log = log
        m_FaultResponse = faultResponse
        m_Name = serviceType.Name & " service host"
    End Sub

    Public Sub New(ByVal singletonInstance As Object, ByVal faultResponse As ServiceHostFaultResponse, ByVal log As FileLogger)
        MyBase.New(singletonInstance)

        If singletonInstance Is Nothing Then Throw New ArgumentNullException("singletonInstance", "singletonInstance is nothing.")
        If log Is Nothing Then Throw New ArgumentNullException("log", "log is nothing.")

        m_Log = log
        m_FaultResponse = faultResponse
        m_Name = singletonInstance.GetType.Name & " service host"
    End Sub

    Private Sub AamServiceHost_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Closed
        m_Log.Write(m_Name & " has closed")
    End Sub

    Private Sub AamServiceHost_Closing(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Closing
        m_Log.Write(m_Name & " is closing")
    End Sub

    Private Sub AamServiceHost_Faulted(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Faulted
        m_Log.Write(m_Name & " has faulted.")

        Select Case m_FaultResponse
            Case ServiceHostFaultResponse.None
                'NOP
            Case ServiceHostFaultResponse.AbortReopenThrow
                Try
                    Abort()
                Catch ex As Exception
                    m_Log.Write("Unable to abort SecurityMasterChangeListener Service Host", ex, Severity.Warning)
                End Try
                Threading.Thread.Sleep(TimeSpan.FromSeconds(30))
                Try
                    Open()
                Catch ex As Exception
                    m_Log.Write("Unable to reopen SecurityMasterChangeListener Service Host.", ex, Severity.ErrorServiceFailed)
                    Throw
                End Try
        End Select

    End Sub

    Private Sub AamServiceHost_Opened(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Opened
        m_Log.Write(m_Name & " has opened")
    End Sub

    Private Sub AamServiceHost_Opening(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Opening
        m_Log.Write(m_Name & " is opening")
    End Sub

    Private Sub AamServiceHost_UnknownMessageReceived(ByVal sender As Object, ByVal e As UnknownMessageReceivedEventArgs) Handles Me.UnknownMessageReceived
        m_Log.Write("SecurityMasterChangeListener Service Host has received an unknown message. The message will be ignored.", Severity.ErrorTaskFailed)
    End Sub

End Class
于 2010-07-12T18:22:22.733 回答