aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/csharp/Greeter/HelloworldGrpc.cs
blob: 1ca9d2899b37742a46c58a70b233b07cb548acd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: helloworld.proto
#region Designer generated code

using System;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;

namespace helloworld {
  public static class Greeter
  {
    static readonly string __ServiceName = "helloworld.Greeter";

    static readonly Marshaller<global::helloworld.HelloRequest> __Marshaller_HelloRequest = Marshallers.Create((arg) => arg.ToByteArray(), global::helloworld.HelloRequest.ParseFrom);
    static readonly Marshaller<global::helloworld.HelloReply> __Marshaller_HelloReply = Marshallers.Create((arg) => arg.ToByteArray(), global::helloworld.HelloReply.ParseFrom);

    static readonly Method<global::helloworld.HelloRequest, global::helloworld.HelloReply> __Method_SayHello = new Method<global::helloworld.HelloRequest, global::helloworld.HelloReply>(
        MethodType.Unary,
        "SayHello",
        __Marshaller_HelloRequest,
        __Marshaller_HelloReply);

    // client-side stub interface
    public interface IGreeterClient
    {
      global::helloworld.HelloReply SayHello(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken));
      Task<global::helloworld.HelloReply> SayHelloAsync(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken));
    }

    // server-side interface
    public interface IGreeter
    {
      Task<global::helloworld.HelloReply> SayHello(ServerCallContext context, global::helloworld.HelloRequest request);
    }

    // client stub
    public class GreeterClient : AbstractStub<GreeterClient, StubConfiguration>, IGreeterClient
    {
      public GreeterClient(Channel channel) : this(channel, StubConfiguration.Default)
      {
      }
      public GreeterClient(Channel channel, StubConfiguration config) : base(channel, config)
      {
      }
      public global::helloworld.HelloReply SayHello(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken))
      {
        var call = CreateCall(__ServiceName, __Method_SayHello);
        return Calls.BlockingUnaryCall(call, request, token);
      }
      public Task<global::helloworld.HelloReply> SayHelloAsync(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken))
      {
        var call = CreateCall(__ServiceName, __Method_SayHello);
        return Calls.AsyncUnaryCall(call, request, token);
      }
    }

    // creates service definition that can be registered with a server
    public static ServerServiceDefinition BindService(IGreeter serviceImpl)
    {
      return ServerServiceDefinition.CreateBuilder(__ServiceName)
          .AddMethod(__Method_SayHello, serviceImpl.SayHello).Build();
    }

    // creates a new client stub
    public static IGreeterClient NewStub(Channel channel)
    {
      return new GreeterClient(channel);
    }

    // creates a new client stub
    public static IGreeterClient NewStub(Channel channel, StubConfiguration config)
    {
      return new GreeterClient(channel, config);
    }
  }
}
#endregion