简体   繁体   中英

How do I retrieve streaming results using Grpc in .Net Core?

I am building a .NetCore application using gRPC.

I'm having issues constructing code to handle streaming results.

Consider the following protobuf definition:

service SampleService
{
    rpc RegisterClient(G_ClientRequest) returns (stream G_ClientResponse) { }
}

Here is a code snippet to read results from the stream:

public ConnectToClient()
{
    var results = Client.RegisterClient(new G_ClientRequest() 
    { 
        ClientName = "Foo",
        DateTimeStamp = new Google.Protobuf.WellKnownTypes.Timestamp()
    });
    
    var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
    foreach (var result in results.ResponseStream.ReadAllAsync(cancellationToken: cts.Token))
    {

    }   
}

I've been googling around and found something similar to my above code for handling streaming results. However the code does not compile. ReadAllAsync() is not available in the interface definition for IAsyncStreamReader .

Is this functionality not available/supported in .Net Core? I'm using the latest stable version of Grpc (2.38).

If this is not available to me, how do I retrieve results from the ResponseStream in .Net Core?

Thx, JohnB

According to the gRPC docs, interface IAsyncStreamReader does not have a ReadAllAsync() method.

https://grpc.github.io/grpc/csharp/api/Grpc.Core.IAsyncStreamReader-1.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM