Messaging: Add general WCF code
This commit is contained in:
parent
078282c579
commit
3883c0dad7
@ -96,6 +96,9 @@
|
|||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="MailSender.vb" />
|
<Compile Include="MailSender.vb" />
|
||||||
|
<Compile Include="WCF\Channel.vb" />
|
||||||
|
<Compile Include="WCF\Constants.vb" />
|
||||||
|
<Compile Include="WCF\ServerAddress.vb" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="My Project\Resources.resx">
|
<EmbeddedResource Include="My Project\Resources.resx">
|
||||||
|
|||||||
@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
|
|||||||
<Assembly: AssemblyCompany("")>
|
<Assembly: AssemblyCompany("")>
|
||||||
<Assembly: AssemblyProduct("Messaging")>
|
<Assembly: AssemblyProduct("Messaging")>
|
||||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||||
<Assembly: AssemblyTrademark("1.8.0.0")>
|
<Assembly: AssemblyTrademark("1.9.0.0")>
|
||||||
|
|
||||||
<Assembly: ComVisible(False)>
|
<Assembly: ComVisible(False)>
|
||||||
|
|
||||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
|||||||
' übernehmen, indem Sie "*" eingeben:
|
' übernehmen, indem Sie "*" eingeben:
|
||||||
' <Assembly: AssemblyVersion("1.0.*")>
|
' <Assembly: AssemblyVersion("1.0.*")>
|
||||||
|
|
||||||
<Assembly: AssemblyVersion("1.8.0.0")>
|
<Assembly: AssemblyVersion("1.9.0.0")>
|
||||||
<Assembly: AssemblyFileVersion("1.8.0.0")>
|
<Assembly: AssemblyFileVersion("1.9.0.0")>
|
||||||
|
|||||||
69
Messaging/WCF/Channel.vb
Normal file
69
Messaging/WCF/Channel.vb
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
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)
|
||||||
|
MyBase.New(pLogConfig)
|
||||||
|
ChannelFactory = GetChannelFactory(pServerAddress)
|
||||||
|
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, Optional pName As String = "Main") As ChannelFactory(Of TChannel)
|
||||||
|
Dim oBinding = GetBinding()
|
||||||
|
Dim oAddress = New EndpointAddress($"net.tcp://{pAddress.Host}:{pAddress.Port}/DigitalData/Services/{pName}")
|
||||||
|
Dim oFactory = New ChannelFactory(Of TChannel)(oBinding, oAddress)
|
||||||
|
Return oFactory
|
||||||
|
End Function
|
||||||
|
|
||||||
|
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
|
||||||
|
End Class
|
||||||
|
End Namespace
|
||||||
20
Messaging/WCF/Constants.vb
Normal file
20
Messaging/WCF/Constants.vb
Normal 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
|
||||||
7
Messaging/WCF/ServerAddress.vb
Normal file
7
Messaging/WCF/ServerAddress.vb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Namespace WCF
|
||||||
|
Public Structure ServerAddress
|
||||||
|
Public Host As String
|
||||||
|
Public Port As Integer
|
||||||
|
End Structure
|
||||||
|
|
||||||
|
End Namespace
|
||||||
Loading…
x
Reference in New Issue
Block a user