From a8760944a08519edc0f74a33c396d5a6053de5e9 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 4 Feb 2018 22:23:23 +0100 Subject: Initial version. --- .gitignore | 6 ++++++ HelloApp/HelloApp.fsproj | 13 ++++++++++++ HelloApp/Program.fs | 12 ++++++++++++ HelloApp/README.md | 16 +++++++++++++++ HelloGrpc/HelloGrpc.csproj | 14 +++++++++++++ HelloGrpc/hello.proto | 14 +++++++++++++ HelloLib/HelloLib.fsproj | 19 ++++++++++++++++++ HelloLib/Library.fs | 32 ++++++++++++++++++++++++++++++ HelloNet.sln | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 175 insertions(+) create mode 100644 .gitignore create mode 100644 HelloApp/HelloApp.fsproj create mode 100644 HelloApp/Program.fs create mode 100644 HelloApp/README.md create mode 100644 HelloGrpc/HelloGrpc.csproj create mode 100644 HelloGrpc/hello.proto create mode 100644 HelloLib/HelloLib.fsproj create mode 100644 HelloLib/Library.fs create mode 100644 HelloNet.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab963e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea +obj +bin +*~ +*.userprefs +.DS_Store diff --git a/HelloApp/HelloApp.fsproj b/HelloApp/HelloApp.fsproj new file mode 100644 index 0000000..54be4a7 --- /dev/null +++ b/HelloApp/HelloApp.fsproj @@ -0,0 +1,13 @@ + + + Exe + netcoreapp2.0 + + + + + + + + + \ No newline at end of file diff --git a/HelloApp/Program.fs b/HelloApp/Program.fs new file mode 100644 index 0000000..cbb161d --- /dev/null +++ b/HelloApp/Program.fs @@ -0,0 +1,12 @@ +open HelloLib + +[] +let main argv = + let server = Greeting.Serve () + let client = Greeting.MakeClient () + + client.SayHelloAsync(new HelloNet.Api.HelloRequest(Greetee = "world")).ResponseAsync.Wait() + + server.ShutdownAsync().Wait() + + 0 diff --git a/HelloApp/README.md b/HelloApp/README.md new file mode 100644 index 0000000..0b1f71a --- /dev/null +++ b/HelloApp/README.md @@ -0,0 +1,16 @@ +# About + +This project demonstrates how to build a gRPC service with F# on .NET +Core 2.0. + +# How to Build + +```sh +dotnet build +``` + +# How to Run + +```sh +dotnet HelloApp/bin/Debug/netcoreapp2.0/HelloApp.dll +``` diff --git a/HelloGrpc/HelloGrpc.csproj b/HelloGrpc/HelloGrpc.csproj new file mode 100644 index 0000000..7471977 --- /dev/null +++ b/HelloGrpc/HelloGrpc.csproj @@ -0,0 +1,14 @@ + + + netstandard2.0 + + + + + + + + + 1.9.0 + + diff --git a/HelloGrpc/hello.proto b/HelloGrpc/hello.proto new file mode 100644 index 0000000..8776dd7 --- /dev/null +++ b/HelloGrpc/hello.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package HelloNet.Api; + +service HelloSayer { + rpc SayHello(HelloRequest) returns (HelloResponse) {} +} + +message HelloRequest { + string greetee = 1; +} + +message HelloResponse { +} diff --git a/HelloLib/HelloLib.fsproj b/HelloLib/HelloLib.fsproj new file mode 100644 index 0000000..2ce9913 --- /dev/null +++ b/HelloLib/HelloLib.fsproj @@ -0,0 +1,19 @@ + + + netstandard2.0 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HelloLib/Library.fs b/HelloLib/Library.fs new file mode 100644 index 0000000..10897f3 --- /dev/null +++ b/HelloLib/Library.fs @@ -0,0 +1,32 @@ +namespace HelloLib + +open System.Threading.Tasks +open System +open Hopac +open Google.Protobuf +open Grpc.Core + +module Greeting = + let private Hello name = + printfn "Hello %s from F#!" name + + type private HelloSayerImpl () = + inherit HelloNet.Api.HelloSayer.HelloSayerBase() + + override this.SayHello(request: HelloNet.Api.HelloRequest, context : ServerCallContext) : Task = + Hello request.Greetee + new HelloNet.Api.HelloResponse() |> Hopac.Job.result |> Hopac.queueAsTask + + let Serve () = + let port = 10000 + let server = new Server() + + server.Services.Add(HelloNet.Api.HelloSayer.BindService(new HelloSayerImpl())) + server.Ports.Add(new ServerPort("localhost", port, ServerCredentials.Insecure)) |> ignore + server.Start() + + server + + let MakeClient () = + let channel = new Channel("127.0.0.1:10000", ChannelCredentials.Insecure) + new HelloNet.Api.HelloSayer.HelloSayerClient(channel) diff --git a/HelloNet.sln b/HelloNet.sln new file mode 100644 index 0000000..c220abd --- /dev/null +++ b/HelloNet.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "HelloApp", "HelloApp\HelloApp.fsproj", "{13277315-D58F-44A8-AD99-A6A29538DA6F}" +EndProject +Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "HelloLib", "HelloLib\HelloLib.fsproj", "{D674AD6A-5689-483F-AAC1-6BBF4982643B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloGrpc", "HelloGrpc\HelloGrpc.csproj", "{2283B324-314D-4D97-8076-A368F3BEB1EE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {13277315-D58F-44A8-AD99-A6A29538DA6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13277315-D58F-44A8-AD99-A6A29538DA6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13277315-D58F-44A8-AD99-A6A29538DA6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13277315-D58F-44A8-AD99-A6A29538DA6F}.Release|Any CPU.Build.0 = Release|Any CPU + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Debug|x64.ActiveCfg = Debug|x64 + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Debug|x64.Build.0 = Debug|x64 + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Debug|x86.ActiveCfg = Debug|x86 + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Debug|x86.Build.0 = Debug|x86 + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Release|Any CPU.Build.0 = Release|Any CPU + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Release|x64.ActiveCfg = Release|x64 + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Release|x64.Build.0 = Release|x64 + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Release|x86.ActiveCfg = Release|x86 + {D674AD6A-5689-483F-AAC1-6BBF4982643B}.Release|x86.Build.0 = Release|x86 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Debug|x64.ActiveCfg = Debug|x64 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Debug|x64.Build.0 = Debug|x64 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Debug|x86.ActiveCfg = Debug|x86 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Debug|x86.Build.0 = Debug|x86 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Release|Any CPU.Build.0 = Release|Any CPU + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Release|x64.ActiveCfg = Release|x64 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Release|x64.Build.0 = Release|x64 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Release|x86.ActiveCfg = Release|x86 + {2283B324-314D-4D97-8076-A368F3BEB1EE}.Release|x86.Build.0 = Release|x86 + EndGlobalSection +EndGlobal -- cgit v1.2.3