diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | HelloApp/HelloApp.fsproj | 13 | ||||
-rw-r--r-- | HelloApp/Program.fs | 12 | ||||
-rw-r--r-- | HelloApp/README.md | 16 | ||||
-rw-r--r-- | HelloGrpc/HelloGrpc.csproj | 14 | ||||
-rw-r--r-- | HelloGrpc/hello.proto | 14 | ||||
-rw-r--r-- | HelloLib/HelloLib.fsproj | 19 | ||||
-rw-r--r-- | HelloLib/Library.fs | 32 | ||||
-rw-r--r-- | HelloNet.sln | 49 |
9 files changed, 175 insertions, 0 deletions
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 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp2.0</TargetFramework> + </PropertyGroup> + <ItemGroup> + <Compile Include="Program.fs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\HelloLib\HelloLib.fsproj" /> + <ProjectReference Include="..\HelloGrpc\HelloGrpc.csproj" /> + </ItemGroup> +</Project>
\ 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
+
+[<EntryPoint>]
+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 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>netstandard2.0</TargetFramework> + </PropertyGroup> + <ItemGroup> + <PackageReference Include="Google.Protobuf" Version="3.5.1" /> + <PackageReference Include="Grpc" Version="1.9.0" /> + <PackageReference Include="Grpc.Tools" Version="1.9.0" /> + <PackageReference Include="Grpc.Tools.MsBuild.Unofficial" Version="1.0.44" /> + </ItemGroup> + <PropertyGroup> + <GrpcToolsVersion>1.9.0</GrpcToolsVersion> + </PropertyGroup> +</Project> 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 @@ +<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="Library.fs" />
+ </ItemGroup>
+ <ItemGroup>
+ <PackageReference Include="Expecto" Version="5.1.2" />
+ <PackageReference Include="Grpc" Version="1.9.0" />
+ <PackageReference Include="Grpc.Core" Version="1.9.0" />
+ <PackageReference Include="Google.Protobuf" Version="3.5.1" />
+ <PackageReference Include="Hopac" Version="0.3.23" />
+ <PackageReference Include="Hopac.IO" Version="1.3.0" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\HelloGrpc\HelloGrpc.csproj" />
+ </ItemGroup>
+</Project>
\ 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<HelloNet.Api.HelloResponse> =
+ 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 |