Imports System.ServiceModel Imports System.ServiceModel.Channels Imports DigitalData.Modules.Logging Imports DigitalData.Modules.EDMIFileOps.EDMIServiceReference Public Class ClassService Private ReadOnly _LogConfig As LogConfig Private ReadOnly _Logger As Logger Public Enum ConnectionTestResult Successful NotFound Unknown End Enum Public Sub New(LogConfig As LogConfig) _LogConfig = LogConfig _Logger = _LogConfig.GetLogger() End Sub 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, ClassConstants.SERVICE_OPEN_TIMEOUT) 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.Config.ServiceConnection) End Function Public Function GetChannelFactory(EndpointURL As String) As ChannelFactory(Of IEDMServiceChannel) Dim oBinding = GetBinding() Dim oEndpoint = New EndpointAddress(EndpointURL) Dim oFactory As New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpoint) Return oFactory 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, ClassConstants.SERVICE_OPEN_TIMEOUT) Return oBinding End Function End Class