Modules/EDMI_ClientSuite/ClassInit.vb
2019-02-13 16:23:02 +01:00

82 lines
3.5 KiB
VB.net

Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Config
Imports System.ServiceModel
Imports EDMI_ClientSuite.NetworkService_DDEDM
Imports System.ServiceModel.Channels
Public Class ClassInit
Private Const OPEN_TIMEOUT_SECONDS = 3
Public Enum ConnectionTestResult
Successful
NotFound
Unknown
End Enum
Private ReadOnly _Logger As Logger
Public Sub New()
_Logger = My.LogConfig.GetLogger()
End Sub
Public Function TestConnectionURLExists() As Boolean
Return My.ConfigManager.Config.ServiceConnection <> String.Empty
'Return My.Settings.ICMServiceAddress <> String.Empty
End Function
Public Async Function TestConnectionAsync(EndpointURL As String) As Task(Of ConnectionTestResult)
Return Await Task.Factory.StartNew(Function()
Try
Dim oChannelFactory = GetChannelFactory(EndpointURL)
Dim oChannel = oChannelFactory.CreateChannel()
oChannel.OperationTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT_SECONDS)
oChannel.Open()
oChannel.Close()
Return ConnectionTestResult.Successful
Catch ex As EndpointNotFoundException
_Logger.Error(ex)
Return ConnectionTestResult.NotFound
Catch ex As Exception
_Logger.Error(ex)
Return ConnectionTestResult.Unknown
End Try
End Function)
End Function
Public Function GetChannelFactory() As IChannelFactory(Of IEDMServiceChannel)
'Return GetChannelFactory(My.Settings.ICMServiceAddress)
Return GetChannelFactory(My.ConfigManager.Config.ServiceConnection)
End Function
Public Function GetChannelFactory(EndpointURL As String) As ChannelFactory(Of IEDMServiceChannel)
Dim oBinding = GetBinding()
Dim oEndpoint = GetEndpoint(EndpointURL)
Dim oFactory As New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpoint)
Return oFactory
End Function
Private Function GetEndpoint(EndpointURL As String) As EndpointAddress
Dim oEndpoint = New EndpointAddress(EndpointURL)
Return oEndpoint
End Function
Private Function GetBinding() As NetTcpBinding
Dim oBinding As New NetTcpBinding()
oBinding.Security.Mode = SecurityMode.Transport
oBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows
oBinding.MaxReceivedMessageSize = ClassConstants.SERVICE_MAX_MESSAGE_SIZE
oBinding.MaxBufferSize = ClassConstants.SERVICE_MAX_BUFFER_SIZE
oBinding.MaxBufferPoolSize = ClassConstants.SERVICE_MAX_BUFFER_SIZE
oBinding.MaxConnections = ClassConstants.SERVICE_MAX_CONNECTIONS
oBinding.ReaderQuotas.MaxArrayLength = ClassConstants.SERVICE_MAX_ARRAY_LENGTH
oBinding.ReaderQuotas.MaxStringContentLength = ClassConstants.SERVICE_MAX_STRING_LENGTH
oBinding.OpenTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT_SECONDS)
Return oBinding
End Function
End Class