From 92d93c3521aa3dd6af2c4b0e95f117fc4f5b160a Mon Sep 17 00:00:00 2001 From: Jan Scheperski Date: Fri, 24 Feb 2023 00:36:37 +0100 Subject: [PATCH 1/2] updated projects to .NET7.0 --- MtApi5/MtApi5.csproj | 2 +- MtApiServiceNetCore/MtApiServiceNetCore.csproj | 2 +- MtApiServiceTest/MtApiServiceTest.csproj | 2 +- TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj | 2 +- TestClients/MtApi5TestClient/MtApi5TestClient.csproj | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj index bbccef4d..37c38f59 100644 --- a/MtApi5/MtApi5.csproj +++ b/MtApi5/MtApi5.csproj @@ -1,6 +1,6 @@  - net5.0 + net7.0 Library false false diff --git a/MtApiServiceNetCore/MtApiServiceNetCore.csproj b/MtApiServiceNetCore/MtApiServiceNetCore.csproj index 6412f143..aa7c1438 100644 --- a/MtApiServiceNetCore/MtApiServiceNetCore.csproj +++ b/MtApiServiceNetCore/MtApiServiceNetCore.csproj @@ -1,6 +1,6 @@  - net5.0 + net7.0 Library false false diff --git a/MtApiServiceTest/MtApiServiceTest.csproj b/MtApiServiceTest/MtApiServiceTest.csproj index 7d4750cc..fccd6592 100644 --- a/MtApiServiceTest/MtApiServiceTest.csproj +++ b/MtApiServiceTest/MtApiServiceTest.csproj @@ -1,7 +1,7 @@ - net5.0 + net7.0 false diff --git a/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj b/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj index cca38828..8cf427ab 100644 --- a/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj +++ b/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 enable enable diff --git a/TestClients/MtApi5TestClient/MtApi5TestClient.csproj b/TestClients/MtApi5TestClient/MtApi5TestClient.csproj index 05a14f75..885b69be 100644 --- a/TestClients/MtApi5TestClient/MtApi5TestClient.csproj +++ b/TestClients/MtApi5TestClient/MtApi5TestClient.csproj @@ -1,6 +1,6 @@  - net5.0-windows + net7.0-windows x86 WinExe false From cd8af98e3116508c5eaca50354b02ee7bb1e81b1 Mon Sep 17 00:00:00 2001 From: Jan Scheperski Date: Sun, 26 Feb 2023 20:34:24 +0100 Subject: [PATCH 2/2] enable support for net named pipe --- MTApiService/MtServer.cs | 52 +++++++++---------- MtApi5/MtApi5.csproj | 2 +- .../MtApiServiceNetCore.csproj | 7 +-- MtApiServiceNetCore/MtClient.cs | 47 ++++++++++++++--- MtApiServiceTest/MtApiServiceTest.csproj | 2 +- .../MTApiClientStandalone.csproj | 2 +- 6 files changed, 71 insertions(+), 41 deletions(-) diff --git a/MTApiService/MtServer.cs b/MTApiService/MtServer.cs index c796be77..f05fc1c2 100755 --- a/MTApiService/MtServer.cs +++ b/MTApiService/MtServer.cs @@ -61,14 +61,13 @@ private bool InitHosts(int port) return false; } - // currently not supported with CoreWCF - ////init local pipe host - //var localPipeUrl = CreateConnectionAddress(null, port, true); - //var localPipeServiceHost = CreateServiceHost(localPipeUrl, true); - //if (localPipeServiceHost != null) - //{ - // _hosts.Add(localPipeServiceHost); - //} + //init local pipe host + var localPipeUrl = CreateConnectionAddress(null, port, true); + var localPipeServiceHost = CreateServiceHost(localPipeUrl, true); + if (localPipeServiceHost != null) + { + _hosts.Add(localPipeServiceHost); + } //init localhost var localUrl = CreateConnectionAddress("localhost", port, false); @@ -78,24 +77,23 @@ private bool InitHosts(int port) _hosts.Add(localServiceHost); } - // currently not required for CoreWCF - ////init network hosts - //var dnsHostName = Dns.GetHostName(); - //var ips = Dns.GetHostEntry(dnsHostName); - - //foreach (var ipAddress in ips.AddressList) - //{ - // if (ipAddress?.AddressFamily == AddressFamily.InterNetwork) - // { - // var ip = ipAddress.ToString(); - // var networkUrl = CreateConnectionAddress(ip, port, false); - // var serviceHost = CreateServiceHost(networkUrl, false); - // if (serviceHost != null) - // { - // _hosts.Add(serviceHost); - // } - // } - //} + //init network hosts + var dnsHostName = Dns.GetHostName(); + var ips = Dns.GetHostEntry(dnsHostName); + + foreach (var ipAddress in ips.AddressList) + { + if (ipAddress?.AddressFamily == AddressFamily.InterNetwork) + { + var ip = ipAddress.ToString(); + var networkUrl = CreateConnectionAddress(ip, port, false); + var serviceHost = CreateServiceHost(networkUrl, false); + if (serviceHost != null) + { + _hosts.Add(serviceHost); + } + } + } count = _hosts.Count; } @@ -124,7 +122,7 @@ private ServiceHost CreateServiceHost(string serverUrlAdress, bool local) serviceHost.AddServiceEndpoint(typeof(IMtApi), binding, serverUrlAdress); serviceHost.Open(); } - catch(Exception e) + catch (Exception e) { Log.ErrorFormat("CreateServiceHost: Error! {0}", e.Message); serviceHost = null; diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj index 37c38f59..86f6bac1 100644 --- a/MtApi5/MtApi5.csproj +++ b/MtApi5/MtApi5.csproj @@ -1,6 +1,6 @@  - net7.0 + net7.0-windows Library false false diff --git a/MtApiServiceNetCore/MtApiServiceNetCore.csproj b/MtApiServiceNetCore/MtApiServiceNetCore.csproj index aa7c1438..f7b7b123 100644 --- a/MtApiServiceNetCore/MtApiServiceNetCore.csproj +++ b/MtApiServiceNetCore/MtApiServiceNetCore.csproj @@ -1,6 +1,6 @@  - net7.0 + net7.0-windows Library false false @@ -35,8 +35,9 @@ - - + + + \ No newline at end of file diff --git a/MtApiServiceNetCore/MtClient.cs b/MtApiServiceNetCore/MtClient.cs index 3bbeeab6..a1e6d710 100644 --- a/MtApiServiceNetCore/MtClient.cs +++ b/MtApiServiceNetCore/MtClient.cs @@ -24,7 +24,16 @@ public sealed class MtClient : IMtApiCallback, IDisposable #endregion #region ctor - public MtClient(string host, int port) + + private MtClient() + { + var quoteScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent); + var eventScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent); + lastQuoteTask = quoteScheduler.StartNew(() => { }); + lastEventTask = eventScheduler.StartNew(() => { }); + } + + public MtClient(string host, int port): this() { if (string.IsNullOrEmpty(host)) throw new ArgumentNullException(nameof(host), "host is null or empty"); @@ -54,17 +63,39 @@ public MtClient(string host, int port) } }; - var quoteScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent); - var eventScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent); - lastQuoteTask = quoteScheduler.StartNew(() => { }); - lastEventTask = eventScheduler.StartNew(() => { }); - _proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService)); _proxy.Faulted += ProxyFaulted; } - public MtClient(int port) : this("localhost", port) - { } + public MtClient(int port): this() + { + if (port < 0 || port > 65536) + throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid"); + + Port = port; + + var urlService = $"net.pipe://localhost/{ServiceName}_{port}"; + + var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) + { + MaxReceivedMessageSize = 2147483647, + MaxBufferSize = 2147483647, + MaxBufferPoolSize = 2147483647, + SendTimeout = new TimeSpan(12, 0, 0), + ReceiveTimeout = new TimeSpan(12, 0, 0), + ReaderQuotas = + { + MaxArrayLength = 2147483647, + MaxBytesPerRead = 2147483647, + MaxDepth = 2147483647, + MaxStringContentLength = 2147483647, + MaxNameTableCharCount = 2147483647 + } + }; + + _proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService)); + _proxy.Faulted += ProxyFaulted; + } #endregion diff --git a/MtApiServiceTest/MtApiServiceTest.csproj b/MtApiServiceTest/MtApiServiceTest.csproj index fccd6592..b413e598 100644 --- a/MtApiServiceTest/MtApiServiceTest.csproj +++ b/MtApiServiceTest/MtApiServiceTest.csproj @@ -1,7 +1,7 @@ - net7.0 + net7.0-windows false diff --git a/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj b/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj index 8cf427ab..9363006d 100644 --- a/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj +++ b/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net7.0-windows enable enable