69 lines
2.3 KiB
VB.net
69 lines
2.3 KiB
VB.net
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Logging.LogConfig
|
|
Imports System.ServiceModel
|
|
Imports EDMI_ClientSuite.NetworkService_DDEDM
|
|
Imports System.IO
|
|
|
|
|
|
Public Class ClassInit
|
|
Private _ChannelFactory As ChannelFactory(Of IEDMServiceChannel)
|
|
Private _Channel As IEDMServiceChannel
|
|
Private _Logger As Logger
|
|
Private _LogConfig As LogConfig
|
|
|
|
Private CurrentRetry As Integer = 0
|
|
|
|
Private Const MAX_RETRIES = 10
|
|
Private Const OPEN_TIMEOUT = 10
|
|
|
|
Public Sub New()
|
|
_LogConfig = New LogConfig(PathType.AppData)
|
|
_Logger = _LogConfig.GetLogger()
|
|
MyLogger = _Logger
|
|
MyLogConfig = _LogConfig
|
|
|
|
|
|
_ChannelFactory = ConfigureChannelFactory()
|
|
_Logger.Debug("Service channelfactory created")
|
|
|
|
Connect()
|
|
End Sub
|
|
|
|
Public Function ConfigureChannelFactory()
|
|
Dim oBinding As New NetTcpBinding()
|
|
oBinding.Security.Mode = SecurityMode.Transport
|
|
oBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows
|
|
oBinding.MaxReceivedMessageSize = 2147483647
|
|
oBinding.MaxBufferSize = 2147483647
|
|
oBinding.MaxBufferPoolSize = 2147483647
|
|
oBinding.MaxConnections = 10000
|
|
oBinding.ReaderQuotas.MaxArrayLength = 2147483647
|
|
oBinding.ReaderQuotas.MaxStringContentLength = 2147483647
|
|
'oBinding.OpenTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT)
|
|
Dim oEndpointAddress = New EndpointAddress(My.Settings.EDM_NetworkService_Adress)
|
|
|
|
Return New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpointAddress)
|
|
End Function
|
|
|
|
Private Sub Connect()
|
|
Try
|
|
_Channel = _ChannelFactory.CreateChannel()
|
|
_Logger.Debug("Service channel created")
|
|
_Logger.Debug("Opening service channel")
|
|
AddHandler _Channel.Faulted, AddressOf Reconnect
|
|
_Channel.Open()
|
|
_Logger.Debug("Service channel opened")
|
|
_Logger.Info("Connection to service established!")
|
|
Catch ex As Exception
|
|
_Logger.Error(ex)
|
|
Throw ex
|
|
End Try
|
|
End Sub
|
|
Private Sub Reconnect(sender As Object, e As EventArgs)
|
|
_Logger.Warn("Could not connect to service. Retrying.")
|
|
_Channel.Abort()
|
|
|
|
Connect()
|
|
End Sub
|
|
End Class
|