本文整理汇总了C#中Grpc.Core.Channel类的典型用法代码示例。如果您正苦于以下问题:C# Channel类的具体用法?C# Channel怎么用?C# Channel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Channel类属于Grpc.Core命名空间,在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Target
public void Target()
{
using (var channel = new Channel("127.0.0.1", Credentials.Insecure))
{
Assert.IsTrue(channel.Target.Contains("127.0.0.1"));
}
}
示例2: Init
public void Init()
{
var marshaller = new Marshaller<string>(
(str) =>
{
if (str == "UNSERIALIZABLE_VALUE")
{
// Google.Protobuf throws exception inherited from IOException
throw new IOException("Error serializing the message.");
}
return System.Text.Encoding.UTF8.GetBytes(str);
},
(payload) =>
{
var s = System.Text.Encoding.UTF8.GetString(payload);
if (s == "UNPARSEABLE_VALUE")
{
// Google.Protobuf throws exception inherited from IOException
throw new IOException("Error parsing the message.");
}
return s;
});
helper = new MockServiceHelper(Host, marshaller);
server = helper.GetServer();
server.Start();
channel = helper.GetChannel();
}
示例3: ConnectAsync
public static async Task<WalletClient> ConnectAsync(string networkAddress, string rootCertificate)
{
if (networkAddress == null)
throw new ArgumentNullException(nameof(networkAddress));
if (rootCertificate == null)
throw new ArgumentNullException(nameof(rootCertificate));
var channel = new Channel(networkAddress, new SslCredentials(rootCertificate));
var deadline = DateTime.UtcNow.AddSeconds(3);
try
{
await channel.ConnectAsync(deadline);
}
catch (TaskCanceledException)
{
await channel.ShutdownAsync();
throw new ConnectTimeoutException();
}
// Ensure the server is running a compatible version.
var versionClient = new VersionService.VersionServiceClient(channel);
var response = await versionClient.VersionAsync(new VersionRequest(), deadline: deadline);
var serverVersion = new SemanticVersion(response.Major, response.Minor, response.Patch);
SemanticVersion.AssertCompatible(RequiredRpcServerVersion, serverVersion);
return new WalletClient(channel);
}
示例4: 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, true);
var clientCredentials = new SslCredentials(rootCert, keyCertPair);
server = new Server
{
Services = { TestService.BindService(new TestServiceImpl()) },
Ports = { { Host, ServerPort.PickUnused, serverCredentials } }
};
server.Start();
var options = new List<ChannelOption>
{
new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
};
channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options);
client = TestService.NewClient(channel);
}
示例5: Main
static void Main(string[] args)
{
var rpcChannel = new Channel("localhost:1337", ChannelCredentials.Insecure);
var rpcClient = new BenchmarkServiceClient(BenchmarkService.NewClient(rpcChannel));
rpcChannel.ConnectAsync().Wait();
_timer.Elapsed += (s, e) =>
{
var lastMinuteCallCount = Interlocked.Exchange(ref _lastMinuteCallCount, 0);
Console.WriteLine($"{DateTime.Now} -- {lastMinuteCallCount} ops/sec");
};
_timer.Start();
for (int i = 0; i < CALL_COUNT; i++)
{
rpcClient.Operation(new ServiceRequest { Id = 10 });
Interlocked.Increment(ref _lastMinuteCallCount);
}
//for (int i = 0; i < CALL_COUNT; i++)
//{
// rpcClient.OperationAsync(new ServiceRequest { Id = 10 }).ContinueWith(t => Interlocked.Increment(ref _lastMinuteCallCount));
//}
//rpcClient.OperationStreamAsync(() => Interlocked.Increment(ref _lastMinuteCallCount)).Wait();
}
示例6: Init
public void Init()
{
var serverCredentials = new SslServerCredentials(new[] { new KeyCertificatePair(File.ReadAllText(TestCredentials.ServerCertChainPath), File.ReadAllText(TestCredentials.ServerPrivateKeyPath)) });
server = new Server
{
Services = { TestService.BindService(new TestServiceImpl()) },
Ports = { { Host, ServerPort.PickUnused, serverCredentials } }
};
server.Start();
var options = new List<ChannelOption>
{
new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
};
var asyncAuthInterceptor = new AsyncAuthInterceptor(async (authUri, metadata) =>
{
await Task.Delay(100); // make sure the operation is asynchronous.
metadata.Add("authorization", "SECRET_TOKEN");
});
var clientCredentials = ChannelCredentials.Create(
new SslCredentials(File.ReadAllText(TestCredentials.ClientCertAuthorityPath)),
new MetadataCredentials(asyncAuthInterceptor));
channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options);
client = TestService.NewClient(channel);
}
示例7: Init
public void Init()
{
helper = new MockServiceHelper(Host);
server = helper.GetServer();
server.Start();
channel = helper.GetChannel();
}
示例8: WaitForStateChangedAsync_InvalidArgument
public void WaitForStateChangedAsync_InvalidArgument()
{
using (var channel = new Channel("localhost", Credentials.Insecure))
{
Assert.Throws(typeof(ArgumentException), () => channel.WaitForStateChangedAsync(ChannelState.FatalFailure));
}
}
示例9: State_IdleAfterCreation
public void State_IdleAfterCreation()
{
using (var channel = new Channel("localhost", Credentials.Insecure))
{
Assert.AreEqual(ChannelState.Idle, channel.State);
}
}
示例10: Main
private const string ProjectName = "apiarydotnetclienttesting"; // this is actually gRPC, but I had that project handy
#endregion Fields
#region Methods
static void Main(string[] args)
{
// Prerequisites
// 1. create a new cloud project with your google account
// 2. enable cloud datastore API on that project
// 3. 'gcloud auth login' to store your google credential in a well known location (from where GoogleCredential.GetApplicationDefaultAsync() can pick it up).
var credentials = Task.Run(() => GoogleCredential.GetApplicationDefaultAsync()).Result;
Channel channel = new Channel("datastore.googleapis.com", credentials.ToChannelCredentials());
var datastoreClient = new Google.Datastore.V1Beta3.Datastore.DatastoreClient(channel);
var result = datastoreClient.RunQuery(new RunQueryRequest
{
ProjectId = ProjectName,
GqlQuery = new GqlQuery {
QueryString = "SELECT * FROM Foo"
}
});
Console.WriteLine(result);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
channel.ShutdownAsync();
}
示例11: 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);
}
示例12: Init
public void Init()
{
server = new Server();
server.AddServiceDefinition(ServiceDefinition);
int port = server.AddListeningPort(Host, Server.PickUnusedPort);
server.Start();
channel = new Channel(Host, port);
}
示例13: Main
public static void Main(string[] args)
{
// This code doesn't do much but makes sure the native extension is loaded
// which is what we are testing here.
Channel c = new Channel("127.0.0.1:1000", ChannelCredentials.Insecure);
c.ShutdownAsync().Wait();
Console.WriteLine("Success!");
}
示例14: Main
static void Main(string[] args)
{
var channel = new Channel("127.0.0.1:9007", ChannelCredentials.Insecure);
var client = new gRPC.gRPCClient(channel);
var replay = client.SayHello(new HelloRequest { Name = "shoy" });
Console.WriteLine(replay.Message);
channel.ShutdownAsync().Wait();
Console.ReadKey();
}
示例15: 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>();
}