Polishing C# routeguide

pull/3109/head
Jan Tattermusch 10 years ago
parent db7f5226d5
commit 46b90ad82e
  1. 15
      csharp/route_guide/README.md

@ -130,6 +130,8 @@ As you can see, our server has a `RouteGuideImpl` class that implements the gene
public class RouteGuideImpl : RouteGuide.IRouteGuide
```
#### Simple RPC
`RouteGuideImpl` implements all our service methods. Let's look at the simplest type first, `GetFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`.
```csharp
@ -143,6 +145,8 @@ The method is passed a context for the RPC (which is empty in the alpha release)
implementation, the method returns `Task<Feature>` rather than just `Feature`. You are free to perform your computations synchronously and return
the result once you've finished, just as we do in the example.
#### Server-side streaming RPC
Now let's look at something a bit more complicated - a streaming RPC. `ListFeatures` is a server-side streaming RPC, so we need to send back multiple `Feature` protocol buffers to our client.
```csharp
@ -174,7 +178,9 @@ Now let's look at something a bit more complicated - a streaming RPC. `ListFeatu
As you can see, here the request object is a `Rectangle` in which our client wants to find `Feature`s, but instead of returning a simple response we need to write responses to an asynchronous stream `IServerStreamWriter` using async method `WriteAsync`.
Similarly, the client-side streaming method `RecordRoute` uses an [IAsyncEnumerator](https://github.com/Reactive-Extensions/Rx.NET/blob/master/Ix.NET/Source/System.Interactive.Async/IAsyncEnumerator.cs), to read the stream of requests using async method `MoveNext` and property `Current`.
#### Client-side streaming RPC
Similarly, the client-side streaming method `RecordRoute` uses an [IAsyncEnumerator](https://github.com/Reactive-Extensions/Rx.NET/blob/master/Ix.NET/Source/System.Interactive.Async/IAsyncEnumerator.cs), to read the stream of requests using the async method `MoveNext` and the `Current` property.
```csharp
public async Task<RouteSummary> RecordRoute(Grpc.Core.ServerCallContext context,
@ -208,6 +214,9 @@ Similarly, the client-side streaming method `RecordRoute` uses an [IAsyncEnumera
.SetElapsedTime((int) (stopwatch.ElapsedMilliseconds / 1000)).Build();
}
```
#### Bidirectional streaming RPC
Finally, let's look at our bidirectional streaming RPC `RouteChat`.
```csharp
@ -238,7 +247,7 @@ Finally, let's look at our bidirectional streaming RPC `RouteChat`.
}
```
Here the method receives both `requestStream` and `responseStream` as an argument. Reading the requests is done in a same way as in the `RecordRoute` example. Writing the responses is done the same way as in the `ListFeatures` example.
Here the method receives both `requestStream` and `responseStream` arguments. Reading the requests is done the same way as in the client-side streaming method `RecordRoute`. Writing the responses is done the same way as in the server-side streaming method `ListFeatures`.
### Starting the server
@ -264,7 +273,7 @@ As you can see, we build and start our server using `Grpc.Core.Server` class. To
1. Create an instance of `Grpc.Core.Server`.
1. Create an instance of our service implementation class `RouteGuideImpl`.
3. Register our service implementation with the server using method `AddServiceDefinition` and the generated method `RouteGuide.BindService`.
3. Register our service implementation with the server using the `AddServiceDefinition` method and the generated method `RouteGuide.BindService`.
2. Specify the address and port we want to use to listen for client requests using the `AddListeningPort` method.
4. Call `Start` on the server instance to start an RPC server for our service.

Loading…
Cancel
Save