From d850f64f8105c03fcecc25bbc0acc9095f485d15 Mon Sep 17 00:00:00 2001 From: Martin Regen Date: Fri, 15 Sep 2017 09:37:32 +0200 Subject: [PATCH] Support .netstandard2.0 (#237) * add missing ref for build in VSO hosted VS 2017 build * project to just build Dlls * target multiple frameworks * switch to net46/netstandard1.3 * fix projects to allow for netcoreapp 2.0 build * fix networking for .Net Core 2.0: SendAsync and ReceiveAsync now frequently return synchronously even if successful. These cases had not been properly handled yet, previous versions never hit these codepaths. * fix travis build / nugets * change travis build target * fix Kestrel https option for netstandard 2.0 tested with Ua Expert against standard and ref server * Handle special case correctly, when zero bytes are received its ok, or BadTimeout will occur * simplify connect, reduce DiscoverEndpoint calls --- .travis.yml | 19 +++++---- .../SDK/Opc.Ua.Client/Opc.Ua.Client.csproj | 4 +- .../Opc.Ua.Configuration.csproj | 4 +- .../SDK/Opc.Ua.Server/Opc.Ua.Server.csproj | 4 +- .../Samples/Client/Opc.Ua.SampleClient.csproj | 2 +- .../NetCoreConsoleClient.csproj | 3 +- .../Samples/NetCoreConsoleClient/Program.cs | 5 +-- .../NetCoreConsoleServer.csproj | 3 +- .../Opc.Ua.Sample/Opc.Ua.Sample.csproj | 2 +- .../Aggregation/Client/MainForm.Designer.cs | 1 + .../ConsoleAggregationServer.csproj | 3 +- .../ConsoleReferenceServer.csproj | 2 +- .../Reference/Server/Reference Server.csproj | 5 +++ Stack/Opc.Ua.Core/Opc.Ua.Core.csproj | 23 +++++++++-- .../Opc.Ua.Core/Stack/Https/HttpsListener.cs | 33 ++++++++++----- .../Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs | 8 ++-- .../Stack/Tcp/UaSCBinaryChannel.cs | 19 ++++++--- UA Core Library.sln | 40 ++++++++++++++++++ nuget/Opc.Ua.Symbols.nuspec | 41 +++++++++++++++++-- nuget/Opc.Ua.nuspec | 33 +++++++++++++-- 20 files changed, 200 insertions(+), 54 deletions(-) create mode 100644 UA Core Library.sln diff --git a/.travis.yml b/.travis.yml index ce3047d648..4da8ed1f69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,20 +9,21 @@ install: - sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list' - sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 - sudo apt-get update - - sudo apt-get install dotnet-dev-1.0.4 -y + - sudo apt-get install dotnet-dev-2.0.0 -y script: - echo "========== build all .Net Core samples ============" + - dotnet restore "UA Core Library.sln" - dotnet restore "UA-NetStandard.sln" - - dotnet build -c Debug -f netcoreapp1.1 SampleApplications/Samples/NetCoreConsoleClient - - dotnet build -c Debug -f netcoreapp1.1 SampleApplications/Samples/NetCoreConsoleServer - - dotnet build -c Release -f netcoreapp1.1 SampleApplications/Samples/NetCoreConsoleClient - - dotnet build -c Release -f netcoreapp1.1 SampleApplications/Samples/NetCoreConsoleServer + - dotnet build -c Debug SampleApplications/Samples/NetCoreConsoleClient + - dotnet build -c Debug SampleApplications/Samples/NetCoreConsoleServer + - dotnet build -c Release SampleApplications/Samples/NetCoreConsoleClient + - dotnet build -c Release SampleApplications/Samples/NetCoreConsoleServer - dotnet restore "SampleApplications/Workshop/Aggregation/UA Aggregation.sln" - - dotnet build -c Debug -f netcoreapp1.1 SampleApplications/Workshop/Aggregation/ConsoleAggregationServer - - dotnet build -c Release -f netcoreapp1.1 SampleApplications/Workshop/Aggregation/ConsoleAggregationServer + - dotnet build -c Debug SampleApplications/Workshop/Aggregation/ConsoleAggregationServer + - dotnet build -c Release SampleApplications/Workshop/Aggregation/ConsoleAggregationServer - dotnet restore "SampleApplications/Workshop/Reference/UA Reference.sln" - - dotnet build -c Debug -f netcoreapp1.1 SampleApplications/Workshop/Reference/ConsoleReferenceServer - - dotnet build -c Release -f netcoreapp1.1 SampleApplications/Workshop/Reference/ConsoleReferenceServer + - dotnet build -c Debug SampleApplications/Workshop/Reference/ConsoleReferenceServer + - dotnet build -c Release SampleApplications/Workshop/Reference/ConsoleReferenceServer after_script: - echo "========== build done ============" diff --git a/SampleApplications/SDK/Opc.Ua.Client/Opc.Ua.Client.csproj b/SampleApplications/SDK/Opc.Ua.Client/Opc.Ua.Client.csproj index dfc1d0ef81..599cb3157b 100644 --- a/SampleApplications/SDK/Opc.Ua.Client/Opc.Ua.Client.csproj +++ b/SampleApplications/SDK/Opc.Ua.Client/Opc.Ua.Client.csproj @@ -1,7 +1,7 @@  - netstandard1.4 + net46;netstandard1.4;netstandard2.0 Opc.Ua.Client Opc.Ua.Client @@ -10,4 +10,6 @@ + + diff --git a/SampleApplications/SDK/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj b/SampleApplications/SDK/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj index 2705cb480e..51a1473c3d 100644 --- a/SampleApplications/SDK/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj +++ b/SampleApplications/SDK/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj @@ -1,7 +1,7 @@  - netstandard1.4 + net46;netstandard1.4;netstandard2.0 Opc.Ua.Configuration Opc.Ua.Configuration @@ -9,5 +9,7 @@ + + diff --git a/SampleApplications/SDK/Opc.Ua.Server/Opc.Ua.Server.csproj b/SampleApplications/SDK/Opc.Ua.Server/Opc.Ua.Server.csproj index bd5bfe5336..09f5525491 100644 --- a/SampleApplications/SDK/Opc.Ua.Server/Opc.Ua.Server.csproj +++ b/SampleApplications/SDK/Opc.Ua.Server/Opc.Ua.Server.csproj @@ -1,7 +1,7 @@  - netstandard1.4 + net46;netstandard1.4;netstandard2.0 Opc.Ua.Server Opc.Ua.Server @@ -10,4 +10,6 @@ + + diff --git a/SampleApplications/Samples/Client/Opc.Ua.SampleClient.csproj b/SampleApplications/Samples/Client/Opc.Ua.SampleClient.csproj index 2842beae37..2e8c12fa5f 100644 --- a/SampleApplications/Samples/Client/Opc.Ua.SampleClient.csproj +++ b/SampleApplications/Samples/Client/Opc.Ua.SampleClient.csproj @@ -172,7 +172,7 @@ - 5.3.3 + 5.4.0 4.3.0 diff --git a/SampleApplications/Samples/NetCoreConsoleClient/NetCoreConsoleClient.csproj b/SampleApplications/Samples/NetCoreConsoleClient/NetCoreConsoleClient.csproj index 27e1c5dc57..5071ca0b09 100644 --- a/SampleApplications/Samples/NetCoreConsoleClient/NetCoreConsoleClient.csproj +++ b/SampleApplications/Samples/NetCoreConsoleClient/NetCoreConsoleClient.csproj @@ -1,11 +1,10 @@  - netcoreapp1.1 + netcoreapp2.0 NetCoreConsoleClient Exe NetCoreConsoleClient - 1.0.4 diff --git a/SampleApplications/Samples/NetCoreConsoleClient/Program.cs b/SampleApplications/Samples/NetCoreConsoleClient/Program.cs index 33d3ebf7d7..5351244625 100644 --- a/SampleApplications/Samples/NetCoreConsoleClient/Program.cs +++ b/SampleApplications/Samples/NetCoreConsoleClient/Program.cs @@ -137,9 +137,8 @@ namespace NetCoreConsoleClient Console.WriteLine("3 - Create a session with OPC UA server."); var endpointConfiguration = EndpointConfiguration.Create(config); - var endpoint = new ConfiguredEndpoint(selectedEndpoint.Server, endpointConfiguration); - endpoint.Update(selectedEndpoint); - var session = await Session.Create(config, endpoint, true, ".Net Core OPC UA Console Client", 60000, new UserIdentity(new AnonymousIdentityToken()), null); + var endpoint = new ConfiguredEndpoint(null, selectedEndpoint, endpointConfiguration); + var session = await Session.Create(config, endpoint, false, ".Net Core OPC UA Console Client", 60000, new UserIdentity(new AnonymousIdentityToken()), null); Console.WriteLine("4 - Browse the OPC UA server namespace."); ReferenceDescriptionCollection references; diff --git a/SampleApplications/Samples/NetCoreConsoleServer/NetCoreConsoleServer.csproj b/SampleApplications/Samples/NetCoreConsoleServer/NetCoreConsoleServer.csproj index 3f86e4ac42..fedaca0e5a 100644 --- a/SampleApplications/Samples/NetCoreConsoleServer/NetCoreConsoleServer.csproj +++ b/SampleApplications/Samples/NetCoreConsoleServer/NetCoreConsoleServer.csproj @@ -1,11 +1,10 @@  - netcoreapp1.1 + netcoreapp2.0 NetCoreConsoleServer Exe NetCoreConsoleServer - 1.0.4 diff --git a/SampleApplications/Samples/Opc.Ua.Sample/Opc.Ua.Sample.csproj b/SampleApplications/Samples/Opc.Ua.Sample/Opc.Ua.Sample.csproj index f7633ed3a8..1801472e66 100644 --- a/SampleApplications/Samples/Opc.Ua.Sample/Opc.Ua.Sample.csproj +++ b/SampleApplications/Samples/Opc.Ua.Sample/Opc.Ua.Sample.csproj @@ -1,7 +1,7 @@  - netstandard1.4 + net46;netstandard1.4;netstandard2.0 Opc.Ua.Sample Opc.Ua.Sample diff --git a/SampleApplications/Workshop/Aggregation/Client/MainForm.Designer.cs b/SampleApplications/Workshop/Aggregation/Client/MainForm.Designer.cs index ec0f57d9f3..bc11788cfe 100644 --- a/SampleApplications/Workshop/Aggregation/Client/MainForm.Designer.cs +++ b/SampleApplications/Workshop/Aggregation/Client/MainForm.Designer.cs @@ -27,6 +27,7 @@ * http://opcfoundation.org/License/MIT/1.00/ * ======================================================================*/ +using Opc.Ua.Client.Controls; using Opc.Ua.Server.Controls; namespace AggregationClient diff --git a/SampleApplications/Workshop/Aggregation/ConsoleAggregationServer/ConsoleAggregationServer.csproj b/SampleApplications/Workshop/Aggregation/ConsoleAggregationServer/ConsoleAggregationServer.csproj index 5ec5f56dbe..39e1a20e62 100644 --- a/SampleApplications/Workshop/Aggregation/ConsoleAggregationServer/ConsoleAggregationServer.csproj +++ b/SampleApplications/Workshop/Aggregation/ConsoleAggregationServer/ConsoleAggregationServer.csproj @@ -1,11 +1,10 @@  - netcoreapp1.1 + netcoreapp2.0 ConsoleAggregationServer Exe ConsoleAggregationServer - 1.0.4 false false false diff --git a/SampleApplications/Workshop/Reference/ConsoleReferenceServer/ConsoleReferenceServer.csproj b/SampleApplications/Workshop/Reference/ConsoleReferenceServer/ConsoleReferenceServer.csproj index b1b1352f1b..cb9528bea5 100644 --- a/SampleApplications/Workshop/Reference/ConsoleReferenceServer/ConsoleReferenceServer.csproj +++ b/SampleApplications/Workshop/Reference/ConsoleReferenceServer/ConsoleReferenceServer.csproj @@ -1,7 +1,7 @@  - netcoreapp1.1 + netcoreapp2.0 ConsoleReferenceServer Exe ConsoleReferenceServer diff --git a/SampleApplications/Workshop/Reference/Server/Reference Server.csproj b/SampleApplications/Workshop/Reference/Server/Reference Server.csproj index 09422f9e55..c23451f173 100644 --- a/SampleApplications/Workshop/Reference/Server/Reference Server.csproj +++ b/SampleApplications/Workshop/Reference/Server/Reference Server.csproj @@ -151,6 +151,11 @@ Opc.Ua.Server + + + 4.3.0 + + diff --git a/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj b/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj index f52c4947f2..3036d06f6c 100644 --- a/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj +++ b/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj @@ -1,7 +1,7 @@  - netstandard1.4 + net46;netstandard1.4;netstandard2.0 $(DefineConstants);NET_STANDARD Opc.Ua.Core Opc.Ua.Core @@ -12,13 +12,30 @@ - - + + + + + + + + + + + + + + + + + + + diff --git a/Stack/Opc.Ua.Core/Stack/Https/HttpsListener.cs b/Stack/Opc.Ua.Core/Stack/Https/HttpsListener.cs index a9da2c6f9f..d7cf2f2b56 100644 --- a/Stack/Opc.Ua.Core/Stack/Https/HttpsListener.cs +++ b/Stack/Opc.Ua.Core/Stack/Https/HttpsListener.cs @@ -23,18 +23,22 @@ #if !NO_HTTPS -using System; -using System.Net; -using System.IO; -using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.Extensions.Logging; +using System; +using System.IO; +using System.Net; using System.Security.Authentication; -using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; + +#if NETSTANDARD2_0 +using Microsoft.AspNetCore.Server.Kestrel.Core; +#endif + namespace Opc.Ua.Bindings { @@ -175,18 +179,27 @@ namespace Opc.Ua.Bindings { Startup.Listener = this; m_host = new WebHostBuilder(); - +#if NETSTANDARD2_0 + m_host.UseKestrel(options => + { + options.Listen(IPAddress.Loopback, m_uri.Port, listenOptions => + { + listenOptions.NoDelay = true; + listenOptions.UseHttps(m_serverCert); + }); + }); +#else HttpsConnectionFilterOptions httpsOptions = new HttpsConnectionFilterOptions(); httpsOptions.CheckCertificateRevocation = false; httpsOptions.ClientCertificateMode = ClientCertificateMode.NoCertificate; httpsOptions.ServerCertificate = m_serverCert; httpsOptions.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; - m_host.UseKestrel(options => { options.NoDelay = true; options.UseHttps(httpsOptions); }); +#endif m_host.UseContentRoot(Directory.GetCurrentDirectory()); m_host.UseStartup(); m_host.Start(Utils.ReplaceLocalhost(m_uri.ToString())); diff --git a/Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs b/Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs index 613141c47a..de6e31b7da 100644 --- a/Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs +++ b/Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs @@ -667,12 +667,14 @@ namespace Opc.Ua.Bindings if (!socket.ReceiveAsync(args)) { // I/O completed synchronously - if ((args.SocketError != SocketError.Success) || (args.BytesTransferred < (m_bytesToReceive - m_bytesReceived))) + if (args.SocketError != SocketError.Success) { throw ServiceResultException.Create(StatusCodes.BadTcpInternalError, args.SocketError.ToString()); } - - args.Dispose(); + else + { + m_ReadComplete(null, args); + } } } catch (ServiceResultException sre) diff --git a/Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryChannel.cs b/Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryChannel.cs index 8d3f2bb673..4adbc6281e 100644 --- a/Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryChannel.cs +++ b/Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryChannel.cs @@ -405,10 +405,14 @@ namespace Opc.Ua.Bindings if (args.IsSocketError || (args.BytesTransferred < buffer.Count)) { error = ServiceResult.Create(StatusCodes.BadConnectionClosed, args.SocketErrorString); + HandleWriteComplete(null, state, args.BytesTransferred, error); + args.Dispose(); + } + else + { + // success, call Complete + OnWriteComplete(null, args); } - - HandleWriteComplete(null, state, args.BytesTransferred, error); - args.Dispose(); } } catch (Exception ex) @@ -439,10 +443,13 @@ namespace Opc.Ua.Bindings if (args.IsSocketError || (args.BytesTransferred < buffers.TotalSize)) { error = ServiceResult.Create(StatusCodes.BadConnectionClosed, args.SocketErrorString); + HandleWriteComplete(buffers, state, args.BytesTransferred, error); + args.Dispose(); + } + else + { + OnWriteComplete(null, args); } - - HandleWriteComplete(buffers, state, args.BytesTransferred, error); - args.Dispose(); } } catch (Exception ex) diff --git a/UA Core Library.sln b/UA Core Library.sln new file mode 100644 index 0000000000..23c8b3ad1d --- /dev/null +++ b/UA Core Library.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Opc.Ua.Core", "Stack\Opc.Ua.Core\Opc.Ua.Core.csproj", "{84FE2F0A-4192-4D2C-8097-9C396C2375E8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Opc.Ua.Server", "SampleApplications\SDK\Opc.Ua.Server\Opc.Ua.Server.csproj", "{259094EF-B5FC-412D-8187-0ED7FF763D55}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Opc.Ua.Configuration", "SampleApplications\SDK\Opc.Ua.Configuration\Opc.Ua.Configuration.csproj", "{63BEB4B6-E96D-478E-B41D-B42CED6F8E7B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Opc.Ua.Client", "SampleApplications\SDK\Opc.Ua.Client\Opc.Ua.Client.csproj", "{DCA9C101-199F-4519-9F97-4CD22817EBE8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {84FE2F0A-4192-4D2C-8097-9C396C2375E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84FE2F0A-4192-4D2C-8097-9C396C2375E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84FE2F0A-4192-4D2C-8097-9C396C2375E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84FE2F0A-4192-4D2C-8097-9C396C2375E8}.Release|Any CPU.Build.0 = Release|Any CPU + {259094EF-B5FC-412D-8187-0ED7FF763D55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {259094EF-B5FC-412D-8187-0ED7FF763D55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {259094EF-B5FC-412D-8187-0ED7FF763D55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {259094EF-B5FC-412D-8187-0ED7FF763D55}.Release|Any CPU.Build.0 = Release|Any CPU + {63BEB4B6-E96D-478E-B41D-B42CED6F8E7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63BEB4B6-E96D-478E-B41D-B42CED6F8E7B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63BEB4B6-E96D-478E-B41D-B42CED6F8E7B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63BEB4B6-E96D-478E-B41D-B42CED6F8E7B}.Release|Any CPU.Build.0 = Release|Any CPU + {DCA9C101-199F-4519-9F97-4CD22817EBE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DCA9C101-199F-4519-9F97-4CD22817EBE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DCA9C101-199F-4519-9F97-4CD22817EBE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DCA9C101-199F-4519-9F97-4CD22817EBE8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/nuget/Opc.Ua.Symbols.nuspec b/nuget/Opc.Ua.Symbols.nuspec index b40140eb12..fdfbf42523 100644 --- a/nuget/Opc.Ua.Symbols.nuspec +++ b/nuget/Opc.Ua.Symbols.nuspec @@ -12,19 +12,44 @@ http://opcfoundation.github.io/UA-.NETStandardLibrary OPCFoundation OPC-UA netstandard ios linux dotnet net netcore uwp - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -33,5 +58,13 @@ + + + + + + + + diff --git a/nuget/Opc.Ua.nuspec b/nuget/Opc.Ua.nuspec index 27cd1aa5d8..863740c93b 100644 --- a/nuget/Opc.Ua.nuspec +++ b/nuget/Opc.Ua.nuspec @@ -12,22 +12,47 @@ http://opcfoundation.github.io/UA-.NETStandardLibrary OPCFoundation OPC-UA netstandard ios linux dotnet net netcore uwp - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +