本文整理汇总了C#中Grpc.Core.Server.AddServiceDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# Server.AddServiceDefinition方法的具体用法?C# Server.AddServiceDefinition怎么用?C# Server.AddServiceDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grpc.Core.Server
的用法示例。
在下文中一共展示了Server.AddServiceDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init()
{
server = new Server();
server.AddServiceDefinition(ServiceDefinition);
int port = server.AddListeningPort(Host, Server.PickUnusedPort);
server.Start();
channel = new Channel(Host, port);
}
示例2: Init
public void Init()
{
server = new Server();
server.AddServiceDefinition(ServiceDefinition);
int port = server.AddPort(Host, Server.PickUnusedPort, ServerCredentials.Insecure);
server.Start();
channel = new Channel(Host, port, Credentials.Insecure);
}
示例3: Init
public void Init()
{
server = new Server();
server.AddServiceDefinition(ServiceDefinition);
int port = server.AddPort(Host, Server.PickUnusedPort, ServerCredentials.Insecure);
server.Start();
channel = new Channel(Host, port, Credentials.Insecure);
stringFromServerHandlerTcs = new TaskCompletionSource<string>();
}
示例4: Init
public void Init()
{
serviceImpl = new HealthServiceImpl();
server = new Server();
server.AddServiceDefinition(Grpc.Health.V1Alpha.Health.BindService(serviceImpl));
int port = server.AddListeningPort(Host, Server.PickUnusedPort);
server.Start();
channel = new Channel(Host, port);
client = Grpc.Health.V1Alpha.Health.NewClient(channel);
}
示例5: Init
public void Init()
{
server = new Server();
server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
int port = server.AddPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials());
server.Start();
var options = new List<ChannelOption>
{
new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
};
channel = new Channel(host, port, TestCredentials.CreateTestClientCredentials(true), options);
client = TestService.NewClient(channel);
}
示例6: Main
public static void Main(string[] args)
{
GrpcEnvironment.Initialize();
Server server = new Server();
server.AddServiceDefinition(Greeter.BindService(new GreeterImpl()));
int port = server.AddListeningPort("localhost", 50051);
server.Start();
Console.WriteLine("Greeter server listening on port " + port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例7: Init
public void Init()
{
server = new Server();
server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
int port = server.AddPort(host, Server.PickUnusedPort, ServerCredentials.Insecure);
server.Start();
channel = new Channel(host, port, Credentials.Insecure);
client = Math.NewClient(channel);
// TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
// for header support.
client.HeaderInterceptor = (metadata) =>
{
metadata.Add(new Metadata.Entry("customHeader", "abcdef"));
};
}
示例8: Main
public static void Main(string[] args)
{
string host = "0.0.0.0";
Server server = new Server();
server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
int port = server.AddPort(host, 23456, ServerCredentials.Insecure);
server.Start();
Console.WriteLine("MathServer listening on port " + port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例9: Main
static void Main(string[] args)
{
var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);
GrpcEnvironment.Initialize();
Server server = new Server();
server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features)));
int port = server.AddListeningPort("localhost", 50052);
server.Start();
Console.WriteLine("RouteGuide server listening on port " + port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例10: UnaryCall
public void UnaryCall()
{
Server server = new Server();
server.AddServiceDefinition(
ServerServiceDefinition.CreateBuilder("someService")
.AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build());
int port = server.AddPort(host + ":0");
server.Start();
using (Channel channel = new Channel(host + ":" + port))
{
var call = new Call<string, string>(unaryEchoStringMethod, channel);
Assert.AreEqual("ABC", Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)));
Assert.AreEqual("abcdef", Calls.BlockingUnaryCall(call, "abcdef", default(CancellationToken)));
}
server.ShutdownAsync().Wait();
}
示例11: Init
public void Init()
{
GrpcEnvironment.Initialize();
server = new Server();
server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
int port = server.AddListeningPort(host, Server.PickUnusedPort);
server.Start();
channel = new Channel(host + ":" + port);
// TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
// for header support.
var stubConfig = new StubConfiguration((headerBuilder) =>
{
headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef"));
});
client = Math.NewStub(channel, stubConfig);
}
示例12: Init
public void Init()
{
var rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityPath);
var keyCertPair = new KeyCertificatePair(
File.ReadAllText(TestCredentials.ServerCertChainPath),
File.ReadAllText(TestCredentials.ServerPrivateKeyPath));
var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert);
var clientCredentials = new SslCredentials(rootCert, keyCertPair);
server = new Server();
server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
int port = server.AddPort(host, Server.PickUnusedPort, serverCredentials);
server.Start();
var options = new List<ChannelOption>
{
new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
};
channel = new Channel(host, port, clientCredentials, options);
client = TestService.NewClient(channel);
}
示例13: Init
public void Init()
{
GrpcEnvironment.Initialize();
server = new Server();
server.AddServiceDefinition(MathGrpc.BindService(new MathServiceImpl()));
int port = server.AddPort(host + ":0");
server.Start();
channel = new Channel(host + ":" + port);
client = MathGrpc.NewStub(channel);
}
示例14: Run
private void Run()
{
GrpcEnvironment.Initialize();
var server = new Server();
server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl()));
string addr = "0.0.0.0:" + options.port;
if (options.useTls)
{
server.AddPort(addr, TestCredentials.CreateTestServerCredentials());
}
else
{
server.AddPort(addr);
}
Console.WriteLine("Running server on " + addr);
server.Start();
server.ShutdownTask.Wait();
GrpcEnvironment.Shutdown();
}
示例15: Init
public void Init()
{
GrpcEnvironment.Initialize();
server = new Server();
server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials());
server.Start();
var channelArgs = ChannelArgs.CreateBuilder()
.AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build();
channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs);
client = TestService.NewStub(channel);
}