This commit is contained in:
2023-01-03 16:03:51 +01:00
26 changed files with 391 additions and 138 deletions

View File

@@ -98,6 +98,10 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="MailSender.vb" />
<Compile Include="WCF\Binding.vb" />
<Compile Include="WCF\Channel.vb" />
<Compile Include="WCF\Constants.vb" />
<Compile Include="WCF\ServerAddress.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("Messaging")>
<Assembly: AssemblyCopyright("Copyright © 2022")>
<Assembly: AssemblyTrademark("1.8.0.0")>
<Assembly: AssemblyTrademark("1.9.0.0")>
<Assembly: ComVisible(False)>

31
Messaging/WCF/Binding.vb Normal file
View File

@@ -0,0 +1,31 @@
Imports System.Net
Imports System.ServiceModel
Imports System.Xml
Namespace WCF
Public Class Binding
Public Shared Function GetBinding(Optional AuthenticationMode As TcpClientCredentialType = TcpClientCredentialType.Windows) As NetTcpBinding
Return New NetTcpBinding() With {
.MaxReceivedMessageSize = Constants.ChannelSettings.MAX_RECEIVED_MESSAGE_SIZE,
.MaxBufferSize = Constants.ChannelSettings.MAX_BUFFER_SIZE,
.MaxBufferPoolSize = Constants.ChannelSettings.MAX_BUFFER_POOL_SIZE,
.TransferMode = TransferMode.Streamed,
.Security = New NetTcpSecurity() With {
.Mode = SecurityMode.Transport,
.Transport = New TcpTransportSecurity() With {
.ClientCredentialType = AuthenticationMode
}
},
.ReaderQuotas = New XmlDictionaryReaderQuotas() With {
.MaxArrayLength = Constants.ChannelSettings.MAX_ARRAY_LENGTH,
.MaxStringContentLength = Constants.ChannelSettings.MAX_STRING_CONTENT_LENGTH
}
}
End Function
Public Shared Function GetAddress(pHost As String, pPort As Integer, pName As String) As Uri
Return New Uri($"net.tcp://{pHost}:{pPort}/DigitalData/Services/{pName}")
End Function
End Class
End Namespace

52
Messaging/WCF/Channel.vb Normal file
View File

@@ -0,0 +1,52 @@
Imports System.ServiceModel
Imports System.Xml
Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Logging
Namespace WCF
Public Class Channel(Of TChannel As IClientChannel)
Inherits BaseClass
Private ReadOnly ChannelFactory As ChannelFactory(Of TChannel)
Public Event Reconnect As EventHandler
Public Sub New(pLogConfig As LogConfig, pServerAddress As ServerAddress, Optional pName As String = "Main")
MyBase.New(pLogConfig)
ChannelFactory = GetChannelFactory(pServerAddress, pName)
End Sub
''' <summary>
''' Creates a channel and adds a Faulted-Handler
''' </summary>
''' <returns>A channel object</returns>
Public Function GetChannel() As TChannel
Try
Logger.Debug("Creating channel.")
Dim oChannel = ChannelFactory.CreateChannel()
AddHandler oChannel.Faulted, Sub() RaiseEvent Reconnect(Me, Nothing)
Return oChannel
Catch ex As Exception
Logger.Error(ex)
Throw ex
End Try
End Function
''' <summary>
''' Creates and returns a channel factory with the supplied name and address
''' </summary>
''' <param name="pName">The service name, will be: net.tcp://ip:port/DigitalData/Services/[name]</param>
''' <param name="pAddress">The service address, in the form of ip address and port</param>
''' <returns></returns>
Private Function GetChannelFactory(pAddress As ServerAddress, pName As String) As ChannelFactory(Of TChannel)
Dim oBinding = Binding.GetBinding()
Dim oAddress = New EndpointAddress(Binding.GetAddress(pAddress.Host, pAddress.Port, pName))
Dim oFactory = New ChannelFactory(Of TChannel)(oBinding, oAddress)
Return oFactory
End Function
End Class
End Namespace

View File

@@ -0,0 +1,20 @@
Namespace WCF
Public Class Constants
Public Const DEFAULT_SERVICE_PORT = 9000
''' <summary>
''' Infos about MaxBufferSize and MaxBufferPoolSize
''' https://social.msdn.microsoft.com/Forums/vstudio/en-US/d6e234d3-942f-4e9d-8470-32618d3f3212/maxbufferpoolsize-vs-maxbuffersize?forum=wcf
''' </summary>
Public Class ChannelSettings
Public Const MAX_RECEIVED_MESSAGE_SIZE = 2147483647 ' 1GB
Public Const MAX_BUFFER_SIZE = 104857600 ' 100MB
Public Const MAX_BUFFER_POOL_SIZE = 1048576 ' 1MB
Public Const MAX_CONNECTIONS = 500
Public Const MAX_ARRAY_LENGTH = 2147483647
Public Const MAX_STRING_CONTENT_LENGTH = 2147483647
End Class
End Class
End Namespace

View File

@@ -0,0 +1,7 @@
Namespace WCF
Public Structure ServerAddress
Public Host As String
Public Port As Integer
End Structure
End Namespace