diff options
Diffstat (limited to 'src/csharp')
20 files changed, 345 insertions, 229 deletions
diff --git a/src/csharp/Grpc.Auth/GoogleCredential.cs b/src/csharp/Grpc.Auth/GoogleCredential.cs index 36d43d3207..8d5e543a21 100644 --- a/src/csharp/Grpc.Auth/GoogleCredential.cs +++ b/src/csharp/Grpc.Auth/GoogleCredential.cs @@ -37,7 +37,6 @@ using System.IO; using System.Security.Cryptography; using Google.Apis.Auth.OAuth2; -using Mono.Security.Cryptography; using Newtonsoft.Json.Linq; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; @@ -113,8 +112,7 @@ namespace Grpc.Auth { // TODO(jtattermusch): temporary code to create RSACryptoServiceProvider. base64PrivateKey = base64PrivateKey.Replace("-----BEGIN PRIVATE KEY-----", "").Replace("\n", "").Replace("-----END PRIVATE KEY-----", ""); - PKCS8.PrivateKeyInfo PKI = new PKCS8.PrivateKeyInfo(Convert.FromBase64String(base64PrivateKey)); - RsaPrivateCrtKeyParameters key = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(PKI.GetBytes()); + RsaPrivateCrtKeyParameters key = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(base64PrivateKey)); RSAParameters rsaParameters = DotNetUtilities.ToRSAParameters(key); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.ImportParameters(rsaParameters); diff --git a/src/csharp/Grpc.Auth/Grpc.Auth.csproj b/src/csharp/Grpc.Auth/Grpc.Auth.csproj index 1931db5fd8..f7724ea643 100644 --- a/src/csharp/Grpc.Auth/Grpc.Auth.csproj +++ b/src/csharp/Grpc.Auth/Grpc.Auth.csproj @@ -51,9 +51,6 @@ <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop"> <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath> </Reference> - <Reference Include="Mono.Security"> - <HintPath>..\packages\Mono.Security.3.2.3.0\lib\net45\Mono.Security.dll</HintPath> - </Reference> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll</HintPath> diff --git a/src/csharp/Grpc.Auth/packages.config b/src/csharp/Grpc.Auth/packages.config index 0816bdbad1..7d348872ba 100644 --- a/src/csharp/Grpc.Auth/packages.config +++ b/src/csharp/Grpc.Auth/packages.config @@ -7,6 +7,5 @@ <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" /> <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" /> <package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" /> - <package id="Mono.Security" version="3.2.3.0" targetFramework="net45" /> <package id="Newtonsoft.Json" version="6.0.6" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/src/csharp/Grpc.Examples.MathClient/MathClient.cs b/src/csharp/Grpc.Examples.MathClient/MathClient.cs index ca7683d399..85d9cdc7a6 100644 --- a/src/csharp/Grpc.Examples.MathClient/MathClient.cs +++ b/src/csharp/Grpc.Examples.MathClient/MathClient.cs @@ -43,7 +43,7 @@ namespace math using (Channel channel = new Channel("127.0.0.1:23456")) { - MathGrpc.IMathServiceClient stub = new MathGrpc.MathServiceClientStub(channel); + Math.IMathClient stub = new Math.MathClient(channel); MathExamples.DivExample(stub); MathExamples.DivAsyncExample(stub).Wait(); diff --git a/src/csharp/Grpc.Examples.MathServer/MathServer.cs b/src/csharp/Grpc.Examples.MathServer/MathServer.cs index cfde9b42c7..d05e3f2808 100644 --- a/src/csharp/Grpc.Examples.MathServer/MathServer.cs +++ b/src/csharp/Grpc.Examples.MathServer/MathServer.cs @@ -45,7 +45,7 @@ namespace math GrpcEnvironment.Initialize(); Server server = new Server(); - server.AddServiceDefinition(MathGrpc.BindService(new MathServiceImpl())); + server.AddServiceDefinition(Math.BindService(new MathServiceImpl())); int port = server.AddListeningPort(host, 23456); server.Start(); diff --git a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj index f9c1caf700..87ccf07dd8 100644 --- a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj +++ b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj @@ -37,18 +37,6 @@ <Reference Include="Google.ProtocolBuffers"> <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll</HintPath> </Reference> - <Reference Include="System.Reactive.Interfaces"> - <HintPath>..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath> - </Reference> - <Reference Include="System.Reactive.Core"> - <HintPath>..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath> - </Reference> - <Reference Include="System.Reactive.Linq"> - <HintPath>..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll</HintPath> - </Reference> - <Reference Include="System.Reactive.PlatformServices"> - <HintPath>..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll</HintPath> - </Reference> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs" /> @@ -71,4 +59,4 @@ <ItemGroup> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> </ItemGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs index 4ada95edd6..4997d3aa42 100644 --- a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs +++ b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs @@ -33,7 +33,6 @@ using System; using System.Collections.Generic; -using System.Reactive.Linq; using System.Threading; using System.Threading.Tasks; using Grpc.Core; @@ -50,7 +49,7 @@ namespace math.Tests string host = "localhost"; Server server; Channel channel; - MathGrpc.IMathServiceClient client; + Math.IMathClient client; [TestFixtureSetUp] public void Init() @@ -58,7 +57,7 @@ namespace math.Tests GrpcEnvironment.Initialize(); server = new Server(); - server.AddServiceDefinition(MathGrpc.BindService(new MathServiceImpl())); + server.AddServiceDefinition(Math.BindService(new MathServiceImpl())); int port = server.AddListeningPort(host, Server.PickUnusedPort); server.Start(); channel = new Channel(host + ":" + port); @@ -69,7 +68,7 @@ namespace math.Tests { headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef")); }); - client = MathGrpc.NewStub(channel, stubConfig); + client = Math.NewStub(channel, stubConfig); } [TestFixtureTearDown] diff --git a/src/csharp/Grpc.Examples.Tests/packages.config b/src/csharp/Grpc.Examples.Tests/packages.config index 06c5e6a4eb..4d6ec63b3c 100644 --- a/src/csharp/Grpc.Examples.Tests/packages.config +++ b/src/csharp/Grpc.Examples.Tests/packages.config @@ -2,9 +2,4 @@ <packages>
<package id="Google.ProtocolBuffers" version="2.4.1.521" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
- <package id="Rx-Core" version="2.2.5" targetFramework="net45" />
- <package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" />
- <package id="Rx-Linq" version="2.2.5" targetFramework="net45" />
- <package id="Rx-Main" version="2.2.5" targetFramework="net45" />
- <package id="Rx-PlatformServices" version="2.2.5" targetFramework="net45" />
</packages>
\ No newline at end of file diff --git a/src/csharp/Grpc.Examples/Grpc.Examples.csproj b/src/csharp/Grpc.Examples/Grpc.Examples.csproj index 1609c4e3df..2c5019c214 100644 --- a/src/csharp/Grpc.Examples/Grpc.Examples.csproj +++ b/src/csharp/Grpc.Examples/Grpc.Examples.csproj @@ -31,19 +31,7 @@ </PropertyGroup> <ItemGroup> <Reference Include="System" /> - <Reference Include="System.Reactive.Core"> - <HintPath>..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath> - </Reference> - <Reference Include="System.Reactive.Interfaces"> - <HintPath>..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath> - </Reference> <Reference Include="System.Data.Linq" /> - <Reference Include="System.Reactive.Linq"> - <HintPath>..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll</HintPath> - </Reference> - <Reference Include="System.Reactive.PlatformServices"> - <HintPath>..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll</HintPath> - </Reference> <Reference Include="Google.ProtocolBuffers"> <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll</HintPath> </Reference> diff --git a/src/csharp/Grpc.Examples/MathExamples.cs b/src/csharp/Grpc.Examples/MathExamples.cs index dba5a7736c..ab06a44c0d 100644 --- a/src/csharp/Grpc.Examples/MathExamples.cs +++ b/src/csharp/Grpc.Examples/MathExamples.cs @@ -31,7 +31,6 @@ using System; using System.Collections.Generic; -using System.Reactive.Linq; using System.Threading.Tasks; using Grpc.Core.Utils; @@ -39,34 +38,34 @@ namespace math { public static class MathExamples { - public static void DivExample(MathGrpc.IMathServiceClient stub) + public static void DivExample(Math.IMathClient stub) { DivReply result = stub.Div(new DivArgs.Builder { Dividend = 10, Divisor = 3 }.Build()); Console.WriteLine("Div Result: " + result); } - public static async Task DivAsyncExample(MathGrpc.IMathServiceClient stub) + public static async Task DivAsyncExample(Math.IMathClient stub) { Task<DivReply> resultTask = stub.DivAsync(new DivArgs.Builder { Dividend = 4, Divisor = 5 }.Build()); DivReply result = await resultTask; Console.WriteLine("DivAsync Result: " + result); } - public static async Task DivAsyncWithCancellationExample(MathGrpc.IMathServiceClient stub) + public static async Task DivAsyncWithCancellationExample(Math.IMathClient stub) { Task<DivReply> resultTask = stub.DivAsync(new DivArgs.Builder { Dividend = 4, Divisor = 5 }.Build()); DivReply result = await resultTask; Console.WriteLine(result); } - public static async Task FibExample(MathGrpc.IMathServiceClient stub) + public static async Task FibExample(Math.IMathClient stub) { var call = stub.Fib(new FibArgs.Builder { Limit = 5 }.Build()); List<Num> result = await call.ResponseStream.ToList(); Console.WriteLine("Fib Result: " + string.Join("|", result)); } - public static async Task SumExample(MathGrpc.IMathServiceClient stub) + public static async Task SumExample(Math.IMathClient stub) { var numbers = new List<Num> { @@ -80,7 +79,7 @@ namespace math Console.WriteLine("Sum Result: " + await call.Result); } - public static async Task DivManyExample(MathGrpc.IMathServiceClient stub) + public static async Task DivManyExample(Math.IMathClient stub) { var divArgsList = new List<DivArgs> { @@ -93,7 +92,7 @@ namespace math Console.WriteLine("DivMany Result: " + string.Join("|", await call.ResponseStream.ToList())); } - public static async Task DependendRequestsExample(MathGrpc.IMathServiceClient stub) + public static async Task DependendRequestsExample(Math.IMathClient stub) { var numbers = new List<Num> { diff --git a/src/csharp/Grpc.Examples/MathGrpc.cs b/src/csharp/Grpc.Examples/MathGrpc.cs index 03f5c31cb7..2546fd220d 100644 --- a/src/csharp/Grpc.Examples/MathGrpc.cs +++ b/src/csharp/Grpc.Examples/MathGrpc.cs @@ -1,164 +1,122 @@ -#region Copyright notice and license - -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#endregion +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: math.proto +#region Designer generated code using System; -using System.Collections.Generic; -using System.Reactive.Linq; using System.Threading; using System.Threading.Tasks; using Grpc.Core; -namespace math -{ - /// <summary> - /// Math service definitions (this is handwritten version of code that will normally be generated). - /// </summary> - public class MathGrpc +namespace math { + public static class Math + { + static readonly string __ServiceName = "math.Math"; + + static readonly Marshaller<DivArgs> __Marshaller_DivArgs = Marshallers.Create((arg) => arg.ToByteArray(), DivArgs.ParseFrom); + static readonly Marshaller<DivReply> __Marshaller_DivReply = Marshallers.Create((arg) => arg.ToByteArray(), DivReply.ParseFrom); + static readonly Marshaller<FibArgs> __Marshaller_FibArgs = Marshallers.Create((arg) => arg.ToByteArray(), FibArgs.ParseFrom); + static readonly Marshaller<Num> __Marshaller_Num = Marshallers.Create((arg) => arg.ToByteArray(), Num.ParseFrom); + + static readonly Method<DivArgs, DivReply> __Method_Div = new Method<DivArgs, DivReply>( + MethodType.Unary, + "Div", + __Marshaller_DivArgs, + __Marshaller_DivReply); + + static readonly Method<DivArgs, DivReply> __Method_DivMany = new Method<DivArgs, DivReply>( + MethodType.DuplexStreaming, + "DivMany", + __Marshaller_DivArgs, + __Marshaller_DivReply); + + static readonly Method<FibArgs, Num> __Method_Fib = new Method<FibArgs, Num>( + MethodType.ServerStreaming, + "Fib", + __Marshaller_FibArgs, + __Marshaller_Num); + + static readonly Method<Num, Num> __Method_Sum = new Method<Num, Num>( + MethodType.ClientStreaming, + "Sum", + __Marshaller_Num, + __Marshaller_Num); + + // client-side stub interface + public interface IMathClient { - static readonly string ServiceName = "/math.Math"; - - static readonly Marshaller<DivArgs> DivArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivArgs.ParseFrom); - static readonly Marshaller<DivReply> DivReplyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivReply.ParseFrom); - static readonly Marshaller<Num> NumMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Num.ParseFrom); - static readonly Marshaller<FibArgs> FibArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), FibArgs.ParseFrom); - - static readonly Method<DivArgs, DivReply> DivMethod = new Method<DivArgs, DivReply>( - MethodType.Unary, - "Div", - DivArgsMarshaller, - DivReplyMarshaller); - - static readonly Method<FibArgs, Num> FibMethod = new Method<FibArgs, Num>( - MethodType.ServerStreaming, - "Fib", - FibArgsMarshaller, - NumMarshaller); - - static readonly Method<Num, Num> SumMethod = new Method<Num, Num>( - MethodType.ClientStreaming, - "Sum", - NumMarshaller, - NumMarshaller); - - static readonly Method<DivArgs, DivReply> DivManyMethod = new Method<DivArgs, DivReply>( - MethodType.DuplexStreaming, - "DivMany", - DivArgsMarshaller, - DivReplyMarshaller); - - public interface IMathServiceClient - { - DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)); - - Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)); - - AsyncServerStreamingCall<Num> Fib(FibArgs request, CancellationToken token = default(CancellationToken)); - - AsyncClientStreamingCall<Num, Num> Sum(CancellationToken token = default(CancellationToken)); - - AsyncDuplexStreamingCall<DivArgs, DivReply> DivMany(CancellationToken token = default(CancellationToken)); - } - - public class MathServiceClientStub : AbstractStub<MathServiceClientStub, StubConfiguration>, IMathServiceClient - { - public MathServiceClientStub(Channel channel) : this(channel, StubConfiguration.Default) - { - } - - public MathServiceClientStub(Channel channel, StubConfiguration config) : base(channel, config) - { - } - - public DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)) - { - var call = CreateCall(ServiceName, DivMethod); - return Calls.BlockingUnaryCall(call, request, token); - } - - public Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)) - { - var call = CreateCall(ServiceName, DivMethod); - return Calls.AsyncUnaryCall(call, request, token); - } - - public AsyncServerStreamingCall<Num> Fib(FibArgs request, CancellationToken token = default(CancellationToken)) - { - var call = CreateCall(ServiceName, FibMethod); - return Calls.AsyncServerStreamingCall(call, request, token); - } - - public AsyncClientStreamingCall<Num, Num> Sum(CancellationToken token = default(CancellationToken)) - { - var call = CreateCall(ServiceName, SumMethod); - return Calls.AsyncClientStreamingCall(call, token); - } - - public AsyncDuplexStreamingCall<DivArgs, DivReply> DivMany(CancellationToken token = default(CancellationToken)) - { - var call = CreateCall(ServiceName, DivManyMethod); - return Calls.AsyncDuplexStreamingCall(call, token); - } - } - - // server-side interface - public interface IMathService - { - Task<DivReply> Div(ServerCallContext context, DivArgs request); - - Task Fib(ServerCallContext context, FibArgs request, IServerStreamWriter<Num> responseStream); + DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)); + Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)); + AsyncDuplexStreamingCall<DivArgs, DivReply> DivMany(CancellationToken token = default(CancellationToken)); + AsyncServerStreamingCall<Num> Fib(FibArgs request, CancellationToken token = default(CancellationToken)); + AsyncClientStreamingCall<Num, Num> Sum(CancellationToken token = default(CancellationToken)); + } - Task<Num> Sum(ServerCallContext context, IAsyncStreamReader<Num> requestStream); + // server-side interface + public interface IMath + { + Task<DivReply> Div(ServerCallContext context, DivArgs request); + Task DivMany(ServerCallContext context, IAsyncStreamReader<DivArgs> requestStream, IServerStreamWriter<DivReply> responseStream); + Task Fib(ServerCallContext context, FibArgs request, IServerStreamWriter<Num> responseStream); + Task<Num> Sum(ServerCallContext context, IAsyncStreamReader<Num> requestStream); + } - Task DivMany(ServerCallContext context, IAsyncStreamReader<DivArgs> requestStream, IServerStreamWriter<DivReply> responseStream); - } + // client stub + public class MathClient : AbstractStub<MathClient, StubConfiguration>, IMathClient + { + public MathClient(Channel channel) : this(channel, StubConfiguration.Default) + { + } + public MathClient(Channel channel, StubConfiguration config) : base(channel, config) + { + } + public DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_Div); + return Calls.BlockingUnaryCall(call, request, token); + } + public Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_Div); + return Calls.AsyncUnaryCall(call, request, token); + } + public AsyncDuplexStreamingCall<DivArgs, DivReply> DivMany(CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_DivMany); + return Calls.AsyncDuplexStreamingCall(call, token); + } + public AsyncServerStreamingCall<Num> Fib(FibArgs request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_Fib); + return Calls.AsyncServerStreamingCall(call, request, token); + } + public AsyncClientStreamingCall<Num, Num> Sum(CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_Sum); + return Calls.AsyncClientStreamingCall(call, token); + } + } - public static ServerServiceDefinition BindService(IMathService serviceImpl) - { - return ServerServiceDefinition.CreateBuilder(ServiceName) - .AddMethod(DivMethod, serviceImpl.Div) - .AddMethod(FibMethod, serviceImpl.Fib) - .AddMethod(SumMethod, serviceImpl.Sum) - .AddMethod(DivManyMethod, serviceImpl.DivMany).Build(); - } + // creates service definition that can be registered with a server + public static ServerServiceDefinition BindService(IMath serviceImpl) + { + return ServerServiceDefinition.CreateBuilder(__ServiceName) + .AddMethod(__Method_Div, serviceImpl.Div) + .AddMethod(__Method_DivMany, serviceImpl.DivMany) + .AddMethod(__Method_Fib, serviceImpl.Fib) + .AddMethod(__Method_Sum, serviceImpl.Sum).Build(); + } - public static IMathServiceClient NewStub(Channel channel) - { - return new MathServiceClientStub(channel); - } + // creates a new client stub + public static IMathClient NewStub(Channel channel) + { + return new MathClient(channel); + } - public static IMathServiceClient NewStub(Channel channel, StubConfiguration config) - { - return new MathServiceClientStub(channel, config); - } + // creates a new client stub + public static IMathClient NewStub(Channel channel, StubConfiguration config) + { + return new MathClient(channel, config); } + } } +#endregion diff --git a/src/csharp/Grpc.Examples/MathServiceImpl.cs b/src/csharp/Grpc.Examples/MathServiceImpl.cs index 800dee8735..3b33b09bbd 100644 --- a/src/csharp/Grpc.Examples/MathServiceImpl.cs +++ b/src/csharp/Grpc.Examples/MathServiceImpl.cs @@ -33,7 +33,6 @@ using System; using System.Collections.Generic; -using System.Reactive.Linq; using System.Threading; using System.Threading.Tasks; using Grpc.Core; @@ -44,7 +43,7 @@ namespace math /// <summary> /// Implementation of MathService server /// </summary> - public class MathServiceImpl : MathGrpc.IMathService + public class MathServiceImpl : Math.IMath { public Task<DivReply> Div(ServerCallContext context, DivArgs request) { diff --git a/src/csharp/Grpc.Examples/packages.config b/src/csharp/Grpc.Examples/packages.config index a6a949b3b3..51c17bcd5e 100644 --- a/src/csharp/Grpc.Examples/packages.config +++ b/src/csharp/Grpc.Examples/packages.config @@ -1,11 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Google.ProtocolBuffers" version="2.4.1.521" targetFramework="net45" /> - <package id="Ix-Main" version="1.2.3" targetFramework="net45" /> <package id="NUnit" version="2.6.4" targetFramework="net45" /> - <package id="Rx-Core" version="2.2.5" targetFramework="net45" /> - <package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" /> - <package id="Rx-Linq" version="2.2.5" targetFramework="net45" /> - <package id="Rx-Main" version="2.2.5" targetFramework="net45" /> - <package id="Rx-PlatformServices" version="2.2.5" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj index 13bbb5363f..1ca3dd24e1 100644 --- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj +++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj @@ -3,7 +3,7 @@ <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">x86</Platform> - <ProductVersion>10.0.0</ProductVersion> + <ProductVersion>8.0.30703</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{C61154BA-DD4A-4838-8420-0162A28925E0}</ProjectGuid> <OutputType>Library</OutputType> @@ -72,7 +72,6 @@ </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="TestServiceGrpc.cs" /> <Compile Include="Empty.cs" /> <Compile Include="Messages.cs" /> <Compile Include="InteropClientServerTest.cs" /> @@ -80,6 +79,7 @@ <Compile Include="InteropServer.cs" /> <Compile Include="InteropClient.cs" /> <Compile Include="TestCredentials.cs" /> + <Compile Include="TestGrpc.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index a433659a08..02f8a369de 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -132,14 +132,14 @@ namespace Grpc.IntegrationTesting stubConfig = new StubConfiguration(OAuth2InterceptorFactory.Create(credential)); } - TestServiceGrpc.ITestServiceClient client = new TestServiceGrpc.TestServiceClientStub(channel, stubConfig); + TestService.ITestServiceClient client = new TestService.TestServiceClient(channel, stubConfig); RunTestCase(options.testCase, client); } GrpcEnvironment.Shutdown(); } - private void RunTestCase(string testCase, TestServiceGrpc.ITestServiceClient client) + private void RunTestCase(string testCase, TestService.ITestServiceClient client) { switch (testCase) { @@ -181,7 +181,7 @@ namespace Grpc.IntegrationTesting } } - public static void RunEmptyUnary(TestServiceGrpc.ITestServiceClient client) + public static void RunEmptyUnary(TestService.ITestServiceClient client) { Console.WriteLine("running empty_unary"); var response = client.EmptyCall(Empty.DefaultInstance); @@ -189,7 +189,7 @@ namespace Grpc.IntegrationTesting Console.WriteLine("Passed!"); } - public static void RunLargeUnary(TestServiceGrpc.ITestServiceClient client) + public static void RunLargeUnary(TestService.ITestServiceClient client) { Console.WriteLine("running large_unary"); var request = SimpleRequest.CreateBuilder() @@ -205,7 +205,7 @@ namespace Grpc.IntegrationTesting Console.WriteLine("Passed!"); } - public static void RunClientStreaming(TestServiceGrpc.ITestServiceClient client) + public static void RunClientStreaming(TestService.ITestServiceClient client) { Task.Run(async () => { @@ -222,7 +222,7 @@ namespace Grpc.IntegrationTesting }).Wait(); } - public static void RunServerStreaming(TestServiceGrpc.ITestServiceClient client) + public static void RunServerStreaming(TestService.ITestServiceClient client) { Task.Run(async () => { @@ -248,7 +248,7 @@ namespace Grpc.IntegrationTesting }).Wait(); } - public static void RunPingPong(TestServiceGrpc.ITestServiceClient client) + public static void RunPingPong(TestService.ITestServiceClient client) { Task.Run(async () => { @@ -303,7 +303,7 @@ namespace Grpc.IntegrationTesting }).Wait(); } - public static void RunEmptyStream(TestServiceGrpc.ITestServiceClient client) + public static void RunEmptyStream(TestService.ITestServiceClient client) { Task.Run(async () => { @@ -318,7 +318,7 @@ namespace Grpc.IntegrationTesting }).Wait(); } - public static void RunServiceAccountCreds(TestServiceGrpc.ITestServiceClient client) + public static void RunServiceAccountCreds(TestService.ITestServiceClient client) { Console.WriteLine("running service_account_creds"); var request = SimpleRequest.CreateBuilder() @@ -338,7 +338,7 @@ namespace Grpc.IntegrationTesting Console.WriteLine("Passed!"); } - public static void RunComputeEngineCreds(TestServiceGrpc.ITestServiceClient client) + public static void RunComputeEngineCreds(TestService.ITestServiceClient client) { Console.WriteLine("running compute_engine_creds"); var request = SimpleRequest.CreateBuilder() @@ -358,7 +358,7 @@ namespace Grpc.IntegrationTesting Console.WriteLine("Passed!"); } - public static void RunCancelAfterBegin(TestServiceGrpc.ITestServiceClient client) + public static void RunCancelAfterBegin(TestService.ITestServiceClient client) { Task.Run(async () => { @@ -383,7 +383,7 @@ namespace Grpc.IntegrationTesting }).Wait(); } - public static void RunCancelAfterFirstResponse(TestServiceGrpc.ITestServiceClient client) + public static void RunCancelAfterFirstResponse(TestService.ITestServiceClient client) { Task.Run(async () => { @@ -419,7 +419,7 @@ namespace Grpc.IntegrationTesting } // This is not an official interop test, but it's useful. - public static void RunBenchmarkEmptyUnary(TestServiceGrpc.ITestServiceClient client) + public static void RunBenchmarkEmptyUnary(TestService.ITestServiceClient client) { BenchmarkUtil.RunBenchmark(10000, 10000, () => { client.EmptyCall(Empty.DefaultInstance); }); diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs b/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs index 9e49ce0d17..ddbfc61a4e 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs @@ -50,7 +50,7 @@ namespace Grpc.IntegrationTesting string host = "localhost"; Server server; Channel channel; - TestServiceGrpc.ITestServiceClient client; + TestService.ITestServiceClient client; [TestFixtureSetUp] public void Init() @@ -58,7 +58,7 @@ namespace Grpc.IntegrationTesting GrpcEnvironment.Initialize(); server = new Server(); - server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl())); + server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials()); server.Start(); @@ -66,7 +66,7 @@ namespace Grpc.IntegrationTesting .AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build(); channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs); - client = TestServiceGrpc.NewStub(channel); + client = TestService.NewStub(channel); } [TestFixtureTearDown] diff --git a/src/csharp/Grpc.IntegrationTesting/InteropServer.cs b/src/csharp/Grpc.IntegrationTesting/InteropServer.cs index ca54aed041..87c3cbe1d4 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropServer.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropServer.cs @@ -91,7 +91,7 @@ namespace Grpc.IntegrationTesting GrpcEnvironment.Initialize(); var server = new Server(); - server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl())); + server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); string host = "0.0.0.0"; int port = options.port.Value; diff --git a/src/csharp/Grpc.IntegrationTesting/TestGrpc.cs b/src/csharp/Grpc.IntegrationTesting/TestGrpc.cs new file mode 100644 index 0000000000..679aafb57a --- /dev/null +++ b/src/csharp/Grpc.IntegrationTesting/TestGrpc.cs @@ -0,0 +1,159 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: test.proto +#region Designer generated code + +using System; +using System.Threading; +using System.Threading.Tasks; +using Grpc.Core; + +namespace grpc.testing { + public static class TestService + { + static readonly string __ServiceName = "grpc.testing.TestService"; + + static readonly Marshaller<Empty> __Marshaller_Empty = Marshallers.Create((arg) => arg.ToByteArray(), Empty.ParseFrom); + static readonly Marshaller<SimpleRequest> __Marshaller_SimpleRequest = Marshallers.Create((arg) => arg.ToByteArray(), SimpleRequest.ParseFrom); + static readonly Marshaller<SimpleResponse> __Marshaller_SimpleResponse = Marshallers.Create((arg) => arg.ToByteArray(), SimpleResponse.ParseFrom); + static readonly Marshaller<StreamingOutputCallRequest> __Marshaller_StreamingOutputCallRequest = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallRequest.ParseFrom); + static readonly Marshaller<StreamingOutputCallResponse> __Marshaller_StreamingOutputCallResponse = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallResponse.ParseFrom); + static readonly Marshaller<StreamingInputCallRequest> __Marshaller_StreamingInputCallRequest = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallRequest.ParseFrom); + static readonly Marshaller<StreamingInputCallResponse> __Marshaller_StreamingInputCallResponse = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallResponse.ParseFrom); + + static readonly Method<Empty, Empty> __Method_EmptyCall = new Method<Empty, Empty>( + MethodType.Unary, + "EmptyCall", + __Marshaller_Empty, + __Marshaller_Empty); + + static readonly Method<SimpleRequest, SimpleResponse> __Method_UnaryCall = new Method<SimpleRequest, SimpleResponse>( + MethodType.Unary, + "UnaryCall", + __Marshaller_SimpleRequest, + __Marshaller_SimpleResponse); + + static readonly Method<StreamingOutputCallRequest, StreamingOutputCallResponse> __Method_StreamingOutputCall = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>( + MethodType.ServerStreaming, + "StreamingOutputCall", + __Marshaller_StreamingOutputCallRequest, + __Marshaller_StreamingOutputCallResponse); + + static readonly Method<StreamingInputCallRequest, StreamingInputCallResponse> __Method_StreamingInputCall = new Method<StreamingInputCallRequest, StreamingInputCallResponse>( + MethodType.ClientStreaming, + "StreamingInputCall", + __Marshaller_StreamingInputCallRequest, + __Marshaller_StreamingInputCallResponse); + + static readonly Method<StreamingOutputCallRequest, StreamingOutputCallResponse> __Method_FullDuplexCall = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>( + MethodType.DuplexStreaming, + "FullDuplexCall", + __Marshaller_StreamingOutputCallRequest, + __Marshaller_StreamingOutputCallResponse); + + static readonly Method<StreamingOutputCallRequest, StreamingOutputCallResponse> __Method_HalfDuplexCall = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>( + MethodType.DuplexStreaming, + "HalfDuplexCall", + __Marshaller_StreamingOutputCallRequest, + __Marshaller_StreamingOutputCallResponse); + + // client-side stub interface + public interface ITestServiceClient + { + Empty EmptyCall(Empty request, CancellationToken token = default(CancellationToken)); + Task<Empty> EmptyCallAsync(Empty request, CancellationToken token = default(CancellationToken)); + SimpleResponse UnaryCall(SimpleRequest request, CancellationToken token = default(CancellationToken)); + Task<SimpleResponse> UnaryCallAsync(SimpleRequest request, CancellationToken token = default(CancellationToken)); + AsyncServerStreamingCall<StreamingOutputCallResponse> StreamingOutputCall(StreamingOutputCallRequest request, CancellationToken token = default(CancellationToken)); + AsyncClientStreamingCall<StreamingInputCallRequest, StreamingInputCallResponse> StreamingInputCall(CancellationToken token = default(CancellationToken)); + AsyncDuplexStreamingCall<StreamingOutputCallRequest, StreamingOutputCallResponse> FullDuplexCall(CancellationToken token = default(CancellationToken)); + AsyncDuplexStreamingCall<StreamingOutputCallRequest, StreamingOutputCallResponse> HalfDuplexCall(CancellationToken token = default(CancellationToken)); + } + + // server-side interface + public interface ITestService + { + Task<Empty> EmptyCall(ServerCallContext context, Empty request); + Task<SimpleResponse> UnaryCall(ServerCallContext context, SimpleRequest request); + Task StreamingOutputCall(ServerCallContext context, StreamingOutputCallRequest request, IServerStreamWriter<StreamingOutputCallResponse> responseStream); + Task<StreamingInputCallResponse> StreamingInputCall(ServerCallContext context, IAsyncStreamReader<StreamingInputCallRequest> requestStream); + Task FullDuplexCall(ServerCallContext context, IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream); + Task HalfDuplexCall(ServerCallContext context, IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream); + } + + // client stub + public class TestServiceClient : AbstractStub<TestServiceClient, StubConfiguration>, ITestServiceClient + { + public TestServiceClient(Channel channel) : this(channel, StubConfiguration.Default) + { + } + public TestServiceClient(Channel channel, StubConfiguration config) : base(channel, config) + { + } + public Empty EmptyCall(Empty request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_EmptyCall); + return Calls.BlockingUnaryCall(call, request, token); + } + public Task<Empty> EmptyCallAsync(Empty request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_EmptyCall); + return Calls.AsyncUnaryCall(call, request, token); + } + public SimpleResponse UnaryCall(SimpleRequest request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_UnaryCall); + return Calls.BlockingUnaryCall(call, request, token); + } + public Task<SimpleResponse> UnaryCallAsync(SimpleRequest request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_UnaryCall); + return Calls.AsyncUnaryCall(call, request, token); + } + public AsyncServerStreamingCall<StreamingOutputCallResponse> StreamingOutputCall(StreamingOutputCallRequest request, CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_StreamingOutputCall); + return Calls.AsyncServerStreamingCall(call, request, token); + } + public AsyncClientStreamingCall<StreamingInputCallRequest, StreamingInputCallResponse> StreamingInputCall(CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_StreamingInputCall); + return Calls.AsyncClientStreamingCall(call, token); + } + public AsyncDuplexStreamingCall<StreamingOutputCallRequest, StreamingOutputCallResponse> FullDuplexCall(CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_FullDuplexCall); + return Calls.AsyncDuplexStreamingCall(call, token); + } + public AsyncDuplexStreamingCall<StreamingOutputCallRequest, StreamingOutputCallResponse> HalfDuplexCall(CancellationToken token = default(CancellationToken)) + { + var call = CreateCall(__ServiceName, __Method_HalfDuplexCall); + return Calls.AsyncDuplexStreamingCall(call, token); + } + } + + // creates service definition that can be registered with a server + public static ServerServiceDefinition BindService(ITestService serviceImpl) + { + return ServerServiceDefinition.CreateBuilder(__ServiceName) + .AddMethod(__Method_EmptyCall, serviceImpl.EmptyCall) + .AddMethod(__Method_UnaryCall, serviceImpl.UnaryCall) + .AddMethod(__Method_StreamingOutputCall, serviceImpl.StreamingOutputCall) + .AddMethod(__Method_StreamingInputCall, serviceImpl.StreamingInputCall) + .AddMethod(__Method_FullDuplexCall, serviceImpl.FullDuplexCall) + .AddMethod(__Method_HalfDuplexCall, serviceImpl.HalfDuplexCall).Build(); + } + + // creates a new client stub + public static ITestServiceClient NewStub(Channel channel) + { + return new TestServiceClient(channel); + } + + // creates a new client stub + public static ITestServiceClient NewStub(Channel channel, StubConfiguration config) + { + return new TestServiceClient(channel, config); + } + } +} +#endregion diff --git a/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs b/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs index 40f32b5a88..d6ba61ef82 100644 --- a/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs +++ b/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs @@ -44,7 +44,7 @@ namespace grpc.testing /// <summary> /// Implementation of TestService server /// </summary> - public class TestServiceImpl : TestServiceGrpc.ITestService + public class TestServiceImpl : TestService.ITestService { public Task<Empty> EmptyCall(ServerCallContext context, Empty request) { diff --git a/src/csharp/generate_proto_csharp.sh b/src/csharp/generate_proto_csharp.sh new file mode 100755 index 0000000000..f980787bb7 --- /dev/null +++ b/src/csharp/generate_proto_csharp.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Regenerates gRPC service stubs from proto files. +set +e +cd $(dirname $0) + +PLUGIN=protoc-gen-grpc=../../bins/opt/grpc_csharp_plugin +EXAMPLES_DIR=Grpc.Examples +INTEROP_DIR=Grpc.IntegrationTesting + +protoc --plugin=$PLUGIN --grpc_out=$EXAMPLES_DIR \ + -I $EXAMPLES_DIR/proto $EXAMPLES_DIR/proto/math.proto + +protoc --plugin=$PLUGIN --grpc_out=$INTEROP_DIR \ + -I $INTEROP_DIR/proto $INTEROP_DIR/proto/test.proto |