Skip to content

Commit

Permalink
Support .netstandard2.0 (#237)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mregen authored and barnstee committed Sep 15, 2017
1 parent 2178fcd commit d850f64
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 52 deletions.
19 changes: 10 additions & 9 deletions .travis.yml
Expand Up @@ -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 ============"
Expand Down
4 changes: 3 additions & 1 deletion SampleApplications/SDK/Opc.Ua.Client/Opc.Ua.Client.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<TargetFrameworks>net46;netstandard1.4;netstandard2.0</TargetFrameworks>
<AssemblyName>Opc.Ua.Client</AssemblyName>
<PackageId>Opc.Ua.Client</PackageId>
</PropertyGroup>
Expand All @@ -10,4 +10,6 @@
<ProjectReference Include="..\..\..\Stack\Opc.Ua.Core\Opc.Ua.Core.csproj" />
</ItemGroup>

<Target Name="GetPackagingOutputs" />

</Project>
@@ -1,13 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<TargetFrameworks>net46;netstandard1.4;netstandard2.0</TargetFrameworks>
<AssemblyName>Opc.Ua.Configuration</AssemblyName>
<PackageId>Opc.Ua.Configuration</PackageId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Stack\Opc.Ua.Core\Opc.Ua.Core.csproj" />
</ItemGroup>

<Target Name="GetPackagingOutputs" />

</Project>
4 changes: 3 additions & 1 deletion SampleApplications/SDK/Opc.Ua.Server/Opc.Ua.Server.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<TargetFrameworks>net46;netstandard1.4;netstandard2.0</TargetFrameworks>
<AssemblyName>Opc.Ua.Server</AssemblyName>
<PackageId>Opc.Ua.Server</PackageId>
</PropertyGroup>
Expand All @@ -10,4 +10,6 @@
<ProjectReference Include="..\..\..\Stack\Opc.Ua.Core\Opc.Ua.Core.csproj" />
</ItemGroup>

<Target Name="GetPackagingOutputs" />

</Project>
Expand Up @@ -172,7 +172,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>5.3.3</Version>
<Version>5.4.0</Version>
</PackageReference>
<PackageReference Include="System.Xml.XmlDocument">
<Version>4.3.0</Version>
Expand Down
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>NetCoreConsoleClient</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>NetCoreConsoleClient</PackageId>
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions SampleApplications/Samples/NetCoreConsoleClient/Program.cs
Expand Up @@ -137,9 +137,8 @@ public static async Task ConsoleSampleClient(string endpointURL)

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;
Expand Down
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>NetCoreConsoleServer</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>NetCoreConsoleServer</PackageId>
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<TargetFrameworks>net46;netstandard1.4;netstandard2.0</TargetFrameworks>
<AssemblyName>Opc.Ua.Sample</AssemblyName>
<PackageId>Opc.Ua.Sample</PackageId>
</PropertyGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>ConsoleAggregationServer</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>ConsoleAggregationServer</PackageId>
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>ConsoleReferenceServer</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>ConsoleReferenceServer</PackageId>
Expand Down
Expand Up @@ -151,6 +151,11 @@
<Name>Opc.Ua.Server</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Security.Cryptography.X509Certificates">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
23 changes: 20 additions & 3 deletions Stack/Opc.Ua.Core/Opc.Ua.Core.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<TargetFrameworks>net46;netstandard1.4;netstandard2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);NET_STANDARD</DefineConstants>
<AssemblyName>Opc.Ua.Core</AssemblyName>
<PackageId>Opc.Ua.Core</PackageId>
Expand All @@ -12,13 +12,30 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<PackageReference Include="System.Private.ServiceModel" Version="4.3.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="1.1.2" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Private.ServiceModel" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.IdentityModel" />
<Reference Include="System.IdentityModel.Selectors" />
</ItemGroup>

<Target Name="GetPackagingOutputs" />

</Project>
33 changes: 23 additions & 10 deletions Stack/Opc.Ua.Core/Stack/Https/HttpsListener.cs
Expand Up @@ -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
{
Expand Down Expand Up @@ -175,18 +179,27 @@ public void Start()
{
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<Startup>();
m_host.Start(Utils.ReplaceLocalhost(m_uri.ToString()));
Expand Down
8 changes: 5 additions & 3 deletions Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs
Expand Up @@ -667,12 +667,14 @@ private void ReadNextBlock()
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)
Expand Down
19 changes: 13 additions & 6 deletions Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryChannel.cs
Expand Up @@ -405,10 +405,14 @@ protected void BeginWriteMessage(ArraySegment<byte> buffer, object state)
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)
Expand Down Expand Up @@ -439,10 +443,13 @@ protected void BeginWriteMessage(BufferCollection buffers, object state)
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)
Expand Down
40 changes: 40 additions & 0 deletions 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

0 comments on commit d850f64

Please sign in to comment.