Пример #1
0
        /// <summary>
        /// Blocking unary call example.  Calls GetFeature and prints the response.
        /// </summary>
        public void GetFeature(int lat, int lon)
        {
            try
            {
                Log("*** GetFeature: lat={0} lon={1}", lat, lon);

                RouteGuide.Point request = new RouteGuide.Point {
                    Latitude = lat, Longitude = lon
                };

                RouteGuide.Feature feature = client.GetFeature(request);
                if (feature.Exists())
                {
                    Log("Found feature called \"{0}\" at {1}, {2}",
                        feature.Name, feature.Location.GetLatitude(), feature.Location.GetLongitude());
                }
                else
                {
                    Log("Found no feature at {0}, {1}",
                        feature.Location.GetLatitude(), feature.Location.GetLongitude());
                }
            }
            catch (RpcException e)
            {
                Log("RPC failed " + e);
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Server-streaming example. Calls listFeatures with a rectangle of interest. Prints each response feature as it arrives.
        /// </summary>
        public async Task ListFeatures(int lowLat, int lowLon, int hiLat, int hiLon)
        {
            try
            {
                Log("*** ListFeatures: lowLat={0} lowLon={1} hiLat={2} hiLon={3}", lowLat, lowLon, hiLat,
                    hiLon);

                RouteGuide.Rectangle request = new RouteGuide.Rectangle
                {
                    Lo = new RouteGuide.Point {
                        Latitude = lowLat, Longitude = lowLon
                    },
                    Hi = new RouteGuide.Point {
                        Latitude = hiLat, Longitude = hiLon
                    }
                };

                using (var call = client.ListFeatures(request))
                {
                    var           responseStream = call.ResponseStream;
                    StringBuilder responseLog    = new StringBuilder("Result: ");

                    while (await responseStream.MoveNext())
                    {
                        RouteGuide.Feature feature = responseStream.Current;
                        responseLog.Append(feature.ToString());
                    }
                    Log(responseLog.ToString());
                }
            }
            catch (RpcException e)
            {
                Log("RPC failed " + e);
                throw;
            }
        }