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 796edf4a..0827161f 100644 --- a/MtApi5/MtApi5.csproj +++ b/MtApi5/MtApi5.csproj @@ -1,6 +1,6 @@  - net5.0 + net7.0-windows Library false false diff --git a/MtApiServiceNetCore/MtApiServiceNetCore.csproj b/MtApiServiceNetCore/MtApiServiceNetCore.csproj index d6d1827f..331319ea 100644 --- a/MtApiServiceNetCore/MtApiServiceNetCore.csproj +++ b/MtApiServiceNetCore/MtApiServiceNetCore.csproj @@ -1,6 +1,6 @@  - net5.0 + net7.0-windows Library false false @@ -44,8 +44,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 da1bf1f4..721331ef 100644 --- a/MtApiServiceTest/MtApiServiceTest.csproj +++ b/MtApiServiceTest/MtApiServiceTest.csproj @@ -1,7 +1,7 @@ - net5.0 + net7.0-windows false diff --git a/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj b/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj index f93ce0f4..6cc2a93d 100644 --- a/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj +++ b/TestClients/MTApiClientStandalone/MTApiClientStandalone.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0-windows enable enable AnyCPU;x64 diff --git a/TestClients/MtApi5TestClient/MtApi5TestClient.csproj b/TestClients/MtApi5TestClient/MtApi5TestClient.csproj index b9cb1542..bb72aa7a 100644 --- a/TestClients/MtApi5TestClient/MtApi5TestClient.csproj +++ b/TestClients/MtApi5TestClient/MtApi5TestClient.csproj @@ -1,6 +1,6 @@  - net5.0-windows + net7.0-windows x86 WinExe false