THRIFT-3933 Microsoft .Net Core library port and generator for this library
Client: .NET Core
Patch: Volodymyr Gotra <vgotra@gmail.com> PR #1088, with significant improvements by Jens Geyer <jensg@apache.org> PR #1149
This closes #1088
This closes #1149
diff --git a/tutorial/Makefile.am b/tutorial/Makefile.am
index 5865c54..efa314a 100755
--- a/tutorial/Makefile.am
+++ b/tutorial/Makefile.am
@@ -58,6 +58,10 @@
SUBDIRS += haxe
endif
+if WITH_DOTNETCORE
+SUBDIRS += netcore
+endif
+
if WITH_GO
SUBDIRS += go
endif
diff --git a/tutorial/netcore/.gitignore b/tutorial/netcore/.gitignore
new file mode 100644
index 0000000..9938bb2
--- /dev/null
+++ b/tutorial/netcore/.gitignore
@@ -0,0 +1 @@
+!**/*.pfx
\ No newline at end of file
diff --git a/tutorial/netcore/Client/Client.xproj b/tutorial/netcore/Client/Client.xproj
new file mode 100644
index 0000000..8726182
--- /dev/null
+++ b/tutorial/netcore/Client/Client.xproj
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>de78a01b-f7c6-49d1-97da-669d2ed37641</ProjectGuid>
+ <RootNamespace>Client</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
diff --git a/tutorial/netcore/Client/Program.cs b/tutorial/netcore/Client/Program.cs
new file mode 100644
index 0000000..5485e95
--- /dev/null
+++ b/tutorial/netcore/Client/Program.cs
@@ -0,0 +1,277 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
+using Thrift;
+using Thrift.Protocols;
+using Thrift.Transports;
+using Thrift.Transports.Client;
+using tutorial;
+using shared;
+
+namespace Client
+{
+ public class Program
+ {
+ private static readonly ILogger Logger = new LoggerFactory().CreateLogger(nameof(Client));
+
+ private static void DisplayHelp()
+ {
+ Console.WriteLine(@"
+Usage:
+ Client.exe -h
+ will diplay help information
+
+ Client.exe -t:<transport> -p:<protocol>
+ will run client with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+ -t (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - buffered transport over tcp will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (address - ""http://localhost:9090"")
+ tcptls - tcp tls transport will be used (host - ""localhost"", port - 9090)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+ Client.exe -t:tcp -p:binary
+");
+ }
+
+ public static void Main(string[] args)
+ {
+ args = args ?? new string[0];
+
+ if (args.Any(x => x.StartsWith("-h", StringComparison.OrdinalIgnoreCase)))
+ {
+ DisplayHelp();
+ return;
+ }
+
+
+ using (var source = new CancellationTokenSource())
+ {
+ RunAsync(args, source.Token).GetAwaiter().GetResult();
+ }
+ }
+
+ private static async Task RunAsync(string[] args, CancellationToken cancellationToken)
+ {
+ var clientTransport = GetTransport(args);
+
+ Logger.LogInformation($"Selected client transport: {clientTransport}");
+
+ var clientProtocol = GetProtocol(args, clientTransport);
+
+ Logger.LogInformation($"Selected client protocol: {clientProtocol}");
+
+ await RunClientAsync(clientProtocol, cancellationToken);
+ }
+
+ private static TClientTransport GetTransport(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-t"))?.Split(':')?[1];
+
+ Transport selectedTransport;
+ if (Enum.TryParse(transport, true, out selectedTransport))
+ {
+ switch (selectedTransport)
+ {
+ case Transport.Tcp:
+ return new TSocketClientTransport(IPAddress.Loopback, 9090);
+ case Transport.NamedPipe:
+ return new TNamedPipeClientTransport(".test");
+ case Transport.Http:
+ return new THttpClientTransport(new Uri("http://localhost:9090"), null);
+ case Transport.TcpBuffered:
+ return
+ new TBufferedClientTransport(
+ new TSocketClientTransport(IPAddress.Loopback, 9090));
+ case Transport.TcpTls:
+ return new TTlsSocketClientTransport(IPAddress.Loopback, 9090,
+ GetCertificate(), CertValidator, LocalCertificateSelectionCallback);
+ case Transport.Framed:
+ throw new NotSupportedException("Framed is not ready for samples");
+ }
+ }
+
+ return new TSocketClientTransport(IPAddress.Loopback, 9090);
+ }
+
+ private static X509Certificate2 GetCertificate()
+ {
+ // due to files location in net core better to take certs from top folder
+ var certFile = GetCertPath(Directory.GetParent(Directory.GetCurrentDirectory()));
+ return new X509Certificate2(certFile, "ThriftTest");
+ }
+
+ private static string GetCertPath(DirectoryInfo di, int maxCount = 6)
+ {
+ var topDir = di;
+ var certFile =
+ topDir.EnumerateFiles("ThriftTest.pfx", SearchOption.AllDirectories)
+ .FirstOrDefault();
+ if (certFile == null)
+ {
+ if (maxCount == 0)
+ throw new FileNotFoundException("Cannot find file in directories");
+ return GetCertPath(di.Parent, maxCount - 1);
+ }
+
+ return certFile.FullName;
+ }
+
+ private static X509Certificate LocalCertificateSelectionCallback(object sender,
+ string targetHost, X509CertificateCollection localCertificates,
+ X509Certificate remoteCertificate, string[] acceptableIssuers)
+ {
+ return GetCertificate();
+ }
+
+ private static bool CertValidator(object sender, X509Certificate certificate,
+ X509Chain chain, SslPolicyErrors sslPolicyErrors)
+ {
+ return true;
+ }
+
+ private static TProtocol GetProtocol(string[] args, TClientTransport transport)
+ {
+ var protocol = args.FirstOrDefault(x => x.StartsWith("-p"))?.Split(':')?[1];
+
+ Protocol selectedProtocol;
+ if (Enum.TryParse(protocol, true, out selectedProtocol))
+ {
+ switch (selectedProtocol)
+ {
+ case Protocol.Binary:
+ return new TBinaryProtocol(transport);
+ case Protocol.Compact:
+ return new TCompactProtocol(transport);
+ case Protocol.Json:
+ return new TJsonProtocol(transport);
+ }
+ }
+
+ return new TBinaryProtocol(transport);
+ }
+
+ private static async Task RunClientAsync(TProtocol protocol,
+ CancellationToken cancellationToken)
+ {
+ try
+ {
+ var client = new Calculator.Client(protocol);
+ await client.OpenTransportAsync(cancellationToken);
+
+ try
+ {
+ // Async version
+
+ Logger.LogInformation("PingAsync()");
+ await client.pingAsync(cancellationToken);
+
+ Logger.LogInformation("AddAsync(1,1)");
+ var sum = await client.addAsync(1, 1, cancellationToken);
+ Logger.LogInformation($"AddAsync(1,1)={sum}");
+
+ var work = new Work
+ {
+ Op = Operation.DIVIDE,
+ Num1 = 1,
+ Num2 = 0
+ };
+
+ try
+ {
+ Logger.LogInformation("CalculateAsync(1)");
+ await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation("Whoa we can divide by 0");
+ }
+ catch (InvalidOperation io)
+ {
+ Logger.LogInformation("Invalid operation: " + io);
+ }
+
+ work.Op = Operation.SUBTRACT;
+ work.Num1 = 15;
+ work.Num2 = 10;
+
+ try
+ {
+ Logger.LogInformation("CalculateAsync(1)");
+ var diff = await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation($"15-10={diff}");
+ }
+ catch (InvalidOperation io)
+ {
+ Logger.LogInformation("Invalid operation: " + io);
+ }
+
+ Logger.LogInformation("GetStructAsync(1)");
+ var log = await client.getStructAsync(1, cancellationToken);
+ Logger.LogInformation($"Check log: {log.Value}");
+
+ Logger.LogInformation("ZipAsync() with delay 100mc on server side");
+ await client.zipAsync(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex.ToString());
+ }
+ finally
+ {
+ protocol.Transport.Close();
+ }
+ }
+ catch (TApplicationException x)
+ {
+ Logger.LogError(x.ToString());
+ }
+ }
+
+ private enum Transport
+ {
+ Tcp,
+ NamedPipe,
+ Http,
+ TcpBuffered,
+ Framed,
+ TcpTls
+ }
+
+ private enum Protocol
+ {
+ Binary,
+ Compact,
+ Json,
+ }
+ }
+}
\ No newline at end of file
diff --git a/tutorial/netcore/Client/Properties/AssemblyInfo.cs b/tutorial/netcore/Client/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..568382e
--- /dev/null
+++ b/tutorial/netcore/Client/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Thrift")]
+[assembly: AssemblyCopyright("The Apache Software Foundation")]
+[assembly: AssemblyTrademark("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+
+[assembly: Guid("de78a01b-f7c6-49d1-97da-669d2ed37641")]
\ No newline at end of file
diff --git a/tutorial/netcore/Client/Properties/launchSettings.json b/tutorial/netcore/Client/Properties/launchSettings.json
new file mode 100644
index 0000000..f351eeb
--- /dev/null
+++ b/tutorial/netcore/Client/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "Client": {
+ "commandName": "Project",
+ "commandLineArgs": "-t:tcptls"
+ }
+ }
+}
\ No newline at end of file
diff --git a/tutorial/netcore/Client/ThriftTest.pfx b/tutorial/netcore/Client/ThriftTest.pfx
new file mode 100644
index 0000000..f0ded28
--- /dev/null
+++ b/tutorial/netcore/Client/ThriftTest.pfx
Binary files differ
diff --git a/tutorial/netcore/Client/project.json b/tutorial/netcore/Client/project.json
new file mode 100644
index 0000000..c850e5d
--- /dev/null
+++ b/tutorial/netcore/Client/project.json
@@ -0,0 +1,28 @@
+{
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true
+ },
+
+ "dependencies": {
+ "Interfaces": "1.0.0-*",
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0"
+ },
+ "Thrift": "1.0.0-*",
+ //"Thrift": "1.0.0-*"
+ },
+
+ "runtimes": {
+ "win10-x64": {},
+ "osx.10.11-x64": {},
+ "ubuntu.16.04-x64": {}
+ },
+
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports": "dnxcore50"
+ }
+ }
+}
diff --git a/tutorial/netcore/Interfaces/Interfaces.xproj b/tutorial/netcore/Interfaces/Interfaces.xproj
new file mode 100644
index 0000000..d472ce6
--- /dev/null
+++ b/tutorial/netcore/Interfaces/Interfaces.xproj
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>4d13163d-9067-4c9c-8af0-64e08451397d</ProjectGuid>
+ <RootNamespace>Interfaces</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
diff --git a/tutorial/netcore/Interfaces/Properties/AssemblyInfo.cs b/tutorial/netcore/Interfaces/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..9126b17
--- /dev/null
+++ b/tutorial/netcore/Interfaces/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Thrift")]
+[assembly: AssemblyCopyright("The Apache Software Foundation")]
+[assembly: AssemblyTrademark("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+
+[assembly: Guid("4d13163d-9067-4c9c-8af0-64e08451397d")]
\ No newline at end of file
diff --git a/tutorial/netcore/Interfaces/project.json b/tutorial/netcore/Interfaces/project.json
new file mode 100644
index 0000000..b5f7c98
--- /dev/null
+++ b/tutorial/netcore/Interfaces/project.json
@@ -0,0 +1,22 @@
+{
+ "version": "1.0.0-*",
+
+ "dependencies": {
+ "NETStandard.Library": "1.6.0",
+ "System.ServiceModel.Primitives": "4.0.0",
+ "Thrift": "1.0.0-*",
+ //"Thrift": "1.0.0-*"
+ },
+
+ "frameworks": {
+ "netstandard1.6": {
+ "imports": "dnxcore50"
+ }
+ },
+
+ "scripts": {
+ "precompile": [
+ //"%project:Directory%/../../thrift.exe -r -out %project:Directory% --gen netcore:wcf %project:Directory%/tutorial.thrift"
+ ]
+ }
+}
diff --git a/tutorial/netcore/Makefile.am b/tutorial/netcore/Makefile.am
new file mode 100644
index 0000000..a3abaee
--- /dev/null
+++ b/tutorial/netcore/Makefile.am
@@ -0,0 +1,82 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+SUBDIRS = .
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+GENDIR = Interfaces/gen-netcore
+
+# Due to a known issue with "dotnet restore" the Thrift.dll dependency cannot be resolved from cmdline.
+# The problem does NOT affect Visual Studio builds, only cmdline.
+# - For details see https://github.com/dotnet/cli/issues/3199 and related tickets.
+# - Workaround is to temporarily copy the Thrift project into the solution
+COPYCMD = cp -u -p -r
+
+
+THRIFTCODE = \
+ Interfaces/Properties/AssemblyInfo.cs \
+ Client/Properties/AssemblyInfo.cs \
+ Client/Program.cs \
+ Server/Properties/AssemblyInfo.cs \
+ Server/Program.cs
+
+all-local: \
+ Client.exe
+
+Client.exe: $(THRIFTCODE)
+ $(MKDIR_P) $(GENDIR)
+ $(THRIFT) -gen netcore:wcf -r -out $(GENDIR) $(top_srcdir)/tutorial/tutorial.thrift
+ $(MKDIR_P) ./Thrift
+ $(COPYCMD) $(top_srcdir)/lib/netcore/Thrift/* ./Thrift
+ $(DOTNETCORE) --info
+ $(DOTNETCORE) restore
+ $(DOTNETCORE) build **/*/project.json -r win10-x64
+ $(DOTNETCORE) build **/*/project.json -r osx.10.11-x64
+ $(DOTNETCORE) build **/*/project.json -r ubuntu.16.04-x64
+
+clean-local:
+ $(RM) Client.exe
+ $(RM) Server.exe
+ $(RM) Interfaces.dll
+ $(RM) -r $(GENDIR)
+ $(RM) -r Client/bin
+ $(RM) -r Client/obj
+ $(RM) -r Server/bin
+ $(RM) -r Server/obj
+ $(RM) -r Interfaces/bin
+ $(RM) -r Interfaces/obj
+ $(RM) -r Thrift
+
+EXTRA_DIST = \
+ $(THRIFTCODE) \
+ global.json \
+ Tutorial.sln \
+ Interfaces/project.json \
+ Interfaces/Interfaces.xproj \
+ Server/project.json \
+ Server/Server.xproj \
+ Server/ThriftTest.pfx \
+ Client/project.json \
+ Client/Client.xproj \
+ Client/ThriftTest.pfx \
+ build.cmd \
+ build.sh \
+ README.md
+
diff --git a/tutorial/netcore/README.md b/tutorial/netcore/README.md
new file mode 100644
index 0000000..18aac02
--- /dev/null
+++ b/tutorial/netcore/README.md
@@ -0,0 +1,253 @@
+# Building of samples for different platforms
+
+Details:
+
+- [https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index ](https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index "https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index ")
+- [https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog](https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog "https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog")
+
+# Running of samples
+
+Please install Thrift C# .NET Core library or copy sources and build them to correcly build and run samples
+
+# NetCore Server
+
+Usage:
+
+ Server.exe -h
+ will diplay help information
+
+ Server.exe -t:<transport> -p:<protocol>
+ will run server with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+
+ -t (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - tcp buffered transport will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (http address - ""localhost:9090"")
+ tcptls - tcp transport with tls will be used (host - ""localhost"", port - 9090)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+
+ Server.exe -t:tcp
+
+**Remarks**:
+
+ For TcpTls mode certificate's file ThriftTest.pfx should be in directory with binaries in case of command line usage (or at project level in case of debugging from IDE).
+ Password for certificate - "ThriftTest".
+
+
+
+# NetCore Client
+
+Usage:
+
+ Client.exe -h
+ will diplay help information
+
+ Client.exe -t:<transport> -p:<protocol>
+ will run client with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+
+ -t (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - buffered transport over tcp will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (address - ""http://localhost:9090"")
+ tcptls - tcp tls transport will be used (host - ""localhost"", port - 9090)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+
+ Client.exe -t:tcp -p:binary
+
+Remarks:
+
+ For TcpTls mode certificate's file ThriftTest.pfx should be in directory
+ with binaries in case of command line usage (or at project level in case of debugging from IDE).
+ Password for certificate - "ThriftTest".
+
+# How to test communication between NetCore and Python
+
+* Generate code with the latest **thrift.exe** util
+* Ensure that **thrift.exe** util generated folder **gen-py** with generated code for Python
+* Create **client.py** and **server.py** from the code examples below and save them to the folder with previosly generated folder **gen-py**
+* Run netcore samples (client and server) and python samples (client and server)
+
+Remarks:
+
+Samples of client and server code below use correct methods (operations)
+and fields (properties) according to generated contracts from *.thrift files
+
+At Windows 10 add record **127.0.0.1 testserver** to **C:\Windows\System32\drivers\etc\hosts** file
+for correct work of python server
+
+
+**Python Client:**
+
+```python
+import sys
+import glob
+sys.path.append('gen-py')
+
+from tutorial import Calculator
+from tutorial.ttypes import InvalidOperation, Operation, Work
+
+from thrift import Thrift
+from thrift.transport import TSocket
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol
+
+
+def main():
+ # Make socket
+ transport = TSocket.TSocket('127.0.0.1', 9090)
+
+ # Buffering is critical. Raw sockets are very slow
+ transport = TTransport.TBufferedTransport(transport)
+
+ # Wrap in a protocol
+ protocol = TBinaryProtocol.TBinaryProtocol(transport)
+
+ # Create a client to use the protocol encoder
+ client = Calculator.Client(protocol)
+
+ # Connect!
+ transport.open()
+
+ client.Ping()
+ print('ping()')
+
+ sum = client.Add(1, 1)
+ print(('1+1=%d' % (sum)))
+
+ work = Work()
+
+ work.Op = Operation.Divide
+ work.Num1 = 1
+ work.Num2 = 0
+
+ try:
+ quotient = client.Calculate(1, work)
+ print('Whoa? You know how to divide by zero?')
+ print('FYI the answer is %d' % quotient)
+ except InvalidOperation as e:
+ print(('InvalidOperation: %r' % e))
+
+ work.Op = Operation.Substract
+ work.Num1 = 15
+ work.Num2 = 10
+
+ diff = client.Calculate(1, work)
+ print(('15-10=%d' % (diff)))
+
+ log = client.GetStruct(1)
+ print(('Check log: %s' % (log.Value)))
+
+ client.Zip()
+ print('zip()')
+
+ # Close!
+ transport.close()
+
+if __name__ == '__main__':
+ try:
+ main()
+ except Thrift.TException as tx:
+ print('%s' % tx.message)
+```
+
+
+**Python Server:**
+
+
+```python
+import glob
+import sys
+sys.path.append('gen-py')
+
+from tutorial import Calculator
+from tutorial.ttypes import InvalidOperation, Operation
+
+from shared.ttypes import SharedStruct
+
+from thrift.transport import TSocket
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol
+from thrift.server import TServer
+
+
+class CalculatorHandler:
+ def __init__(self):
+ self.log = {}
+
+ def Ping(self):
+ print('ping()')
+
+ def Add(self, n1, n2):
+ print('add(%d,%d)' % (n1, n2))
+ return n1 + n2
+
+ def Calculate(self, logid, work):
+ print('calculate(%d, %r)' % (logid, work))
+
+ if work.Op == Operation.Add:
+ val = work.Num1 + work.Num2
+ elif work.Op == Operation.Substract:
+ val = work.Num1 - work.Num2
+ elif work.Op == Operation.Multiply:
+ val = work.Num1 * work.Num2
+ elif work.Op == Operation.Divide:
+ if work.Num2 == 0:
+ x = InvalidOperation()
+ x.WhatOp = work.Op
+ x.Why = 'Cannot divide by 0'
+ raise x
+ val = work.Num1 / work.Num2
+ else:
+ x = InvalidOperation()
+ x.WhatOp = work.Op
+ x.Why = 'Invalid operation'
+ raise x
+
+ log = SharedStruct()
+ log.Key = logid
+ log.Value = '%d' % (val)
+ self.log[logid] = log
+
+ return val
+
+ def GetStruct(self, key):
+ print('getStruct(%d)' % (key))
+ return self.log[key]
+
+ def Zip(self):
+ print('zip()')
+
+if __name__ == '__main__':
+ handler = CalculatorHandler()
+ processor = Calculator.Processor(handler)
+ transport = TSocket.TServerSocket(host="testserver", port=9090)
+ tfactory = TTransport.TBufferedTransportFactory()
+ pfactory = TBinaryProtocol.TBinaryProtocolFactory()
+
+ server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
+ print('Starting the server...')
+ server.serve()
+ print('done.')
+
+ # You could do one of these for a multithreaded server
+ # server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
+ # server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
+```
\ No newline at end of file
diff --git a/tutorial/netcore/Server/Program.cs b/tutorial/netcore/Server/Program.cs
new file mode 100644
index 0000000..6041924
--- /dev/null
+++ b/tutorial/netcore/Server/Program.cs
@@ -0,0 +1,397 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Thrift;
+using Thrift.Protocols;
+using Thrift.Server;
+using Thrift.Transports;
+using Thrift.Transports.Server;
+using tutorial;
+using shared;
+
+namespace Server
+{
+ public class Program
+ {
+ private static readonly ILogger Logger = new LoggerFactory().CreateLogger(nameof(Server));
+
+ public static void Main(string[] args)
+ {
+ args = args ?? new string[0];
+
+ if (args.Any(x => x.StartsWith("-h", StringComparison.OrdinalIgnoreCase)))
+ {
+ DisplayHelp();
+ return;
+ }
+
+ using (var source = new CancellationTokenSource())
+ {
+ RunAsync(args, source.Token).GetAwaiter().GetResult();
+
+ Logger.LogInformation("Press any key to stop...");
+
+ Console.ReadLine();
+ source.Cancel();
+ }
+ }
+
+ private static void DisplayHelp()
+ {
+ Console.WriteLine(@"
+Usage:
+ Server.exe -h
+ will diplay help information
+
+ Server.exe -t:<transport> -p:<protocol>
+ will run server with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+ -t (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - tcp buffered transport will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (http address - ""localhost:9090"")
+ tcptls - tcp transport with tls will be used (host - ""localhost"", port - 9090)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+ Server.exe -t:tcp
+");
+ }
+
+ private static async Task RunAsync(string[] args, CancellationToken cancellationToken)
+ {
+ var selectedTransport = GetTransport(args);
+ var selectedProtocol = GetProtocol(args);
+
+ if (selectedTransport == Transport.Http)
+ {
+ new HttpServerSample().Run(cancellationToken);
+ }
+ else
+ {
+ await
+ RunSelectedConfigurationAsync(selectedTransport, selectedProtocol,
+ cancellationToken);
+ }
+ }
+
+ private static Protocol GetProtocol(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-p"))?.Split(':')?[1];
+ Protocol selectedProtocol;
+
+ Enum.TryParse(transport, true, out selectedProtocol);
+
+ return selectedProtocol;
+ }
+
+ private static Transport GetTransport(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-t"))?.Split(':')?[1];
+ Transport selectedTransport;
+
+ Enum.TryParse(transport, true, out selectedTransport);
+
+ return selectedTransport;
+ }
+
+ private static async Task RunSelectedConfigurationAsync(Transport transport,
+ Protocol protocol, CancellationToken cancellationToken)
+ {
+ var fabric = new LoggerFactory();
+ var handler = new CalculatorAsyncHandler();
+ var processor = new Calculator.AsyncProcessor(handler);
+
+ TServerTransport serverTransport = null;
+
+ switch (transport)
+ {
+ case Transport.Tcp:
+ serverTransport = new TServerSocketTransport(9090);
+ break;
+ case Transport.TcpBuffered:
+ serverTransport = new TServerSocketTransport(port: 9090, clientTimeout: 10000,
+ useBufferedSockets: true);
+ break;
+ case Transport.NamedPipe:
+ serverTransport = new TNamedPipeServerTransport(".test");
+ break;
+ case Transport.TcpTls:
+ serverTransport = new TTlsServerSocketTransport(9090, false, GetCertificate(),
+ ClientCertValidator, LocalCertificateSelectionCallback);
+ break;
+ }
+
+ ITProtocolFactory inputProtocolFactory;
+ ITProtocolFactory outputProtocolFactory;
+
+ switch (protocol)
+ {
+ case Protocol.Binary:
+ {
+ inputProtocolFactory = new TBinaryProtocol.Factory();
+ outputProtocolFactory = new TBinaryProtocol.Factory();
+ }
+ break;
+ case Protocol.Compact:
+ {
+ inputProtocolFactory = new TCompactProtocol.Factory();
+ outputProtocolFactory = new TCompactProtocol.Factory();
+ }
+ break;
+ case Protocol.Json:
+ {
+ inputProtocolFactory = new TJsonProtocol.Factory();
+ outputProtocolFactory = new TJsonProtocol.Factory();
+ }
+ break;
+ default:
+ throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null);
+ }
+
+ try
+ {
+ Logger.LogInformation(
+ $"Selected TAsyncServer with {serverTransport} transport and {inputProtocolFactory} protocol factories");
+
+ var server = new AsyncBaseServer(processor, serverTransport, inputProtocolFactory,
+ outputProtocolFactory, fabric);
+
+ Logger.LogInformation("Starting the server...");
+ await server.ServeAsync(cancellationToken);
+ }
+ catch (Exception x)
+ {
+ Logger.LogInformation(x.ToString());
+ }
+
+ Logger.LogInformation("Server stopped.");
+ }
+
+ private static X509Certificate2 GetCertificate()
+ {
+ // due to files location in net core better to take certs from top folder
+ var certFile = GetCertPath(Directory.GetParent(Directory.GetCurrentDirectory()));
+ return new X509Certificate2(certFile, "ThriftTest");
+ }
+
+ private static string GetCertPath(DirectoryInfo di, int maxCount = 6)
+ {
+ var topDir = di;
+ var certFile =
+ topDir.EnumerateFiles("ThriftTest.pfx", SearchOption.AllDirectories)
+ .FirstOrDefault();
+ if (certFile == null)
+ {
+ if (maxCount == 0)
+ throw new FileNotFoundException("Cannot find file in directories");
+ return GetCertPath(di.Parent, maxCount - 1);
+ }
+
+ return certFile.FullName;
+ }
+
+ private static X509Certificate LocalCertificateSelectionCallback(object sender,
+ string targetHost, X509CertificateCollection localCertificates,
+ X509Certificate remoteCertificate, string[] acceptableIssuers)
+ {
+ return GetCertificate();
+ }
+
+ private static bool ClientCertValidator(object sender, X509Certificate certificate,
+ X509Chain chain, SslPolicyErrors sslPolicyErrors)
+ {
+ return true;
+ }
+
+ private enum Transport
+ {
+ Tcp,
+ TcpBuffered,
+ NamedPipe,
+ Http,
+ TcpTls
+ }
+
+ private enum Protocol
+ {
+ Binary,
+ Compact,
+ Json,
+ }
+
+ public class HttpServerSample
+ {
+ public void Run(CancellationToken cancellationToken)
+ {
+ var config = new ConfigurationBuilder()
+ .AddEnvironmentVariables(prefix: "ASPNETCORE_")
+ .Build();
+
+ var host = new WebHostBuilder()
+ .UseConfiguration(config)
+ .UseKestrel()
+ .UseUrls("http://localhost:9090")
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .UseIISIntegration()
+ .UseStartup<Startup>()
+ .Build();
+
+ host.Run(cancellationToken);
+ }
+
+ public class Startup
+ {
+ public Startup(IHostingEnvironment env)
+ {
+ var builder = new ConfigurationBuilder()
+ .SetBasePath(env.ContentRootPath)
+ .AddEnvironmentVariables();
+
+ Configuration = builder.Build();
+ }
+
+ public IConfigurationRoot Configuration { get; }
+
+ // This method gets called by the runtime. Use this method to add services to the container.
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddTransient<Calculator.IAsync, CalculatorAsyncHandler>();
+ services.AddTransient<ITAsyncProcessor, Calculator.AsyncProcessor>();
+ services.AddTransient<THttpServerTransport, THttpServerTransport>();
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env,
+ ILoggerFactory loggerFactory)
+ {
+ app.UseMiddleware<THttpServerTransport>();
+ }
+ }
+ }
+
+ public class CalculatorAsyncHandler : Calculator.IAsync
+ {
+ Dictionary<int, SharedStruct> _log;
+
+ public CalculatorAsyncHandler()
+ {
+ _log = new Dictionary<int, SharedStruct>();
+ }
+
+ public async Task<SharedStruct> getStructAsync(int key,
+ CancellationToken cancellationToken)
+ {
+ Logger.LogInformation("GetStructAsync({0})", key);
+ return await Task.FromResult(_log[key]);
+ }
+
+ public async Task pingAsync(CancellationToken cancellationToken)
+ {
+ Logger.LogInformation("PingAsync()");
+ await Task.CompletedTask;
+ }
+
+ public async Task<int> addAsync(int num1, int num2, CancellationToken cancellationToken)
+ {
+ Logger.LogInformation($"AddAsync({num1},{num2})");
+ return await Task.FromResult(num1 + num2);
+ }
+
+ public async Task<int> calculateAsync(int logid, Work w, CancellationToken cancellationToken)
+ {
+ Logger.LogInformation($"CalculateAsync({logid}, [{w.Op},{w.Num1},{w.Num2}])");
+
+ var val = 0;
+ switch (w.Op)
+ {
+ case Operation.ADD:
+ val = w.Num1 + w.Num2;
+ break;
+
+ case Operation.SUBTRACT:
+ val = w.Num1 - w.Num2;
+ break;
+
+ case Operation.MULTIPLY:
+ val = w.Num1*w.Num2;
+ break;
+
+ case Operation.DIVIDE:
+ if (w.Num2 == 0)
+ {
+ var io = new InvalidOperation
+ {
+ WhatOp = (int) w.Op,
+ Why = "Cannot divide by 0"
+ };
+
+ throw io;
+ }
+ val = w.Num1/w.Num2;
+ break;
+
+ default:
+ {
+ var io = new InvalidOperation
+ {
+ WhatOp = (int) w.Op,
+ Why = "Unknown operation"
+ };
+
+ throw io;
+ }
+ }
+
+ var entry = new SharedStruct
+ {
+ Key = logid,
+ Value = val.ToString()
+ };
+
+ _log[logid] = entry;
+
+ return await Task.FromResult(val);
+ }
+
+ public async Task zipAsync(CancellationToken cancellationToken)
+ {
+ Logger.LogInformation("ZipAsync() with delay 100mc");
+ await Task.Delay(100, CancellationToken.None);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tutorial/netcore/Server/Properties/AssemblyInfo.cs b/tutorial/netcore/Server/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..a044235
--- /dev/null
+++ b/tutorial/netcore/Server/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Thrift")]
+[assembly: AssemblyCopyright("The Apache Software Foundation")]
+[assembly: AssemblyTrademark("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+
+[assembly: Guid("e210fc10-5aff-4b04-ac21-58afc7b74b0c")]
\ No newline at end of file
diff --git a/tutorial/netcore/Server/Properties/launchSettings.json b/tutorial/netcore/Server/Properties/launchSettings.json
new file mode 100644
index 0000000..e23253d
--- /dev/null
+++ b/tutorial/netcore/Server/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "Server": {
+ "commandName": "Project",
+ "commandLineArgs": "-t:tcptls"
+ }
+ }
+}
\ No newline at end of file
diff --git a/tutorial/netcore/Server/Server.xproj b/tutorial/netcore/Server/Server.xproj
new file mode 100644
index 0000000..5cebad1
--- /dev/null
+++ b/tutorial/netcore/Server/Server.xproj
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>e210fc10-5aff-4b04-ac21-58afc7b74b0c</ProjectGuid>
+ <RootNamespace>Server</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
diff --git a/tutorial/netcore/Server/ThriftTest.pfx b/tutorial/netcore/Server/ThriftTest.pfx
new file mode 100644
index 0000000..f0ded28
--- /dev/null
+++ b/tutorial/netcore/Server/ThriftTest.pfx
Binary files differ
diff --git a/tutorial/netcore/Server/project.json b/tutorial/netcore/Server/project.json
new file mode 100644
index 0000000..7948c27
--- /dev/null
+++ b/tutorial/netcore/Server/project.json
@@ -0,0 +1,29 @@
+{
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true
+ },
+
+ "dependencies": {
+ "Interfaces": "1.0.0-*",
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0"
+ },
+ "Microsoft.AspNetCore.Http": "1.0.0",
+ "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
+ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
+ "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
+ "Thrift": "1.0.0-*" },
+ "runtimes": {
+ "win10-x64": {},
+ "osx.10.11-x64": {},
+ "ubuntu.16.04-x64": {}
+ },
+
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports": "dnxcore50"
+ }
+ }
+}
diff --git a/tutorial/netcore/Tutorial.sln b/tutorial/netcore/Tutorial.sln
new file mode 100644
index 0000000..0368f21
--- /dev/null
+++ b/tutorial/netcore/Tutorial.sln
@@ -0,0 +1,45 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Server", "Server\Server.xproj", "{E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Interfaces", "Interfaces\Interfaces.xproj", "{4D13163D-9067-4C9C-8AF0-64E08451397D}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Client", "Client\Client.xproj", "{DE78A01B-F7C6-49D1-97DA-669D2ED37641}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Thrift", "..\..\lib\netcore\Thrift\Thrift.xproj", "{6850CF46-5467-4C65-BD78-871581C539FC}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49B45AE5-C6CB-4E11-AA74-6A5472FFAF8F}"
+ ProjectSection(SolutionItems) = preProject
+ global.json = global.json
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/tutorial/netcore/build.cmd b/tutorial/netcore/build.cmd
new file mode 100644
index 0000000..2d20cbe
--- /dev/null
+++ b/tutorial/netcore/build.cmd
@@ -0,0 +1,45 @@
+@echo off
+rem /*
+rem * Licensed to the Apache Software Foundation (ASF) under one
+rem * or more contributor license agreements. See the NOTICE file
+rem * distributed with this work for additional information
+rem * regarding copyright ownership. The ASF licenses this file
+rem * to you under the Apache License, Version 2.0 (the
+rem * "License"); you may not use this file except in compliance
+rem * with the License. You may obtain a copy of the License at
+rem *
+rem * http://www.apache.org/licenses/LICENSE-2.0
+rem *
+rem * Unless required by applicable law or agreed to in writing,
+rem * software distributed under the License is distributed on an
+rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+rem * KIND, either express or implied. See the License for the
+rem * specific language governing permissions and limitations
+rem * under the License.
+rem */
+setlocal
+
+cd Interfaces
+thrift -gen netcore:wcf -r ..\..\tutorial.thrift
+cd ..
+
+rem * Due to a known issue with "dotnet restore" the Thrift.dll dependency cannot be resolved from cmdline
+rem * For details see https://github.com/dotnet/cli/issues/3199 and related tickets
+rem * The problem does NOT affect Visual Studio builds.
+
+rem * workaround for "dotnet restore" issue
+xcopy ..\..\lib\netcore\Thrift .\Thrift /YSEI >NUL
+
+dotnet --info
+dotnet restore
+
+dotnet build **/*/project.json -r win10-x64
+dotnet build **/*/project.json -r osx.10.11-x64
+dotnet build **/*/project.json -r ubuntu.16.04-x64
+
+rem * workaround for "dotnet restore" issue
+del .\Thrift\* /Q /S >NUL
+rd .\Thrift /Q /S >NUL
+
+
+:eof
diff --git a/tutorial/netcore/build.sh b/tutorial/netcore/build.sh
new file mode 100644
index 0000000..3879455
--- /dev/null
+++ b/tutorial/netcore/build.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+#exit if any command fails
+#set -e
+
+cd Interfaces
+../../../compiler/cpp/thrift -gen netcore:wcf -r ../../tutorial.thrift
+cd ..
+
+
+# Due to a known issue with "dotnet restore" the Thrift.dll dependency cannot be resolved from cmdline
+# For details see https://github.com/dotnet/cli/issues/3199 and related tickets
+# The problem does NOT affect Visual Studio builds.
+
+# workaround for "dotnet restore" issue
+cp -u -p -r ..\..\lib\netcore\Thrift .\Thrift
+
+dotnet --info
+dotnet restore
+
+dotnet build **/*/project.json -r win10-x64
+dotnet build **/*/project.json -r osx.10.11-x64
+dotnet build **/*/project.json -r ubuntu.16.04-x64
+# workaround for "dotnet restore" issue
+rm -r .\Thrift
diff --git a/tutorial/netcore/global.json b/tutorial/netcore/global.json
new file mode 100644
index 0000000..53f1811
--- /dev/null
+++ b/tutorial/netcore/global.json
@@ -0,0 +1,3 @@
+{
+ "projects": [ "../../lib/netcore" ]
+}
\ No newline at end of file
diff --git a/tutorial/shared.thrift b/tutorial/shared.thrift
index 386000b..3cc1bb3 100644
--- a/tutorial/shared.thrift
+++ b/tutorial/shared.thrift
@@ -29,6 +29,7 @@
namespace perl shared
namespace php shared
namespace haxe shared
+namespace netcore shared
struct SharedStruct {
1: i32 key
diff --git a/tutorial/tutorial.thrift b/tutorial/tutorial.thrift
index c4a96f0..f8c5320 100644
--- a/tutorial/tutorial.thrift
+++ b/tutorial/tutorial.thrift
@@ -69,6 +69,7 @@
namespace php tutorial
namespace perl tutorial
namespace haxe tutorial
+namespace netcore tutorial
/**
* Thrift lets you do typedefs to get pretty names for your types. Standard