Как отправить несколько путевых точек в виртуальный веб-сервис маршрутизации по земле - PullRequest
2 голосов
/ 05 июня 2009

Я пытаюсь использовать виртуальный веб-сервис:

http://staging.dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc?wsdl

чтобы вернуть общее расстояние, пройденное транспортным средством, остановившимся в нескольких точках.

Мой код отлично работает для поездок с 4 путевыми точками, но, кроме этого, я получаю следующую ошибку:

Максимальная квота размера сообщения для входящих сообщений (65536) было превышены. Чтобы увеличить квоту, используйте свойство MaxReceivedMessageSize на соответствующий обязательный элемент.

приблизительный код: (консольное приложение C #)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Text;
using System.Configuration;
using System.Threading;
using System.Text.RegularExpressions;
using altRouteFinder.VEStagingToken;
using altRouteFinder.VERoutingService;

namespace altRouteFinder
{
 class Program
{
    static void Main(string[] args)
    {
        waypointString = "53.450356,-2.873335;53.399184,-2.980577;53.440535,-2.864101;53.449368,-2.885361;53.454417,-2.930646;53.450356,-2.873335";

        string[] points = waypointString.Split(';');
        Waypoint[] waypoints = new Waypoint[points.Length];
        double dayDistance = 0;
        int pointIndex = -1;
        foreach (string point in points)
        {
            pointIndex++;
            waypoints[pointIndex] = new Waypoint();
            string[] digits = point.Split(',');
            waypoints[pointIndex].Location = new VERoutingService.Location();
            waypoints[pointIndex].Location.Latitude = double.Parse(digits[0].Trim());
            waypoints[pointIndex].Location.Longitude = double.Parse(digits[1].Trim());

            if (pointIndex == 0)
                waypoints[pointIndex].Description = "Start";
            else if (pointIndex == points.Length)
                waypoints[pointIndex].Description = "End";
            else
                waypoints[pointIndex].Description = string.Format("Stop #{0}", pointIndex);
        }

        routeRequest.Waypoints = waypoints;

        RouteOptions myRouteOptions = new RouteOptions();
        //Set travel mode - Driving or Walking 
        myRouteOptions.Mode = TravelMode.Driving;
        //Set the optimization type - MinimizeDistance or MinimizeTime 
        myRouteOptions.Optimization = RouteOptimization.MinimizeTime;
        //Set the use of traffic conditions - TrafficBasedRouteAndTime, TrafficBasedTime, or None 
        myRouteOptions.TrafficUsage = TrafficUsage.TrafficBasedTime;
        //Pass the Route Options to the Route Object 
        routeRequest.Options = myRouteOptions; 

        // Make the calculate route request
        RouteServiceClient routeService = new RouteServiceClient();

        RouteResponse routeResponse = routeService.CalculateRoute(routeRequest);

        // Iterate through each itinerary item to get the route directions
        StringBuilder directions = new StringBuilder("");

        if (routeResponse.Result.Legs.Length > 0)
        {
            int instructionCount = 0;
            int legCount = 0;

            foreach (RouteLeg leg in routeResponse.Result.Legs)
            {
                legCount++;
                directions.Append(string.Format("Leg #{0}\n", legCount));

                foreach (ItineraryItem item in leg.Itinerary)
                {
                    instructionCount++;
                    directions.Append(string.Format("{0}. {1} {2}\n",
                        instructionCount, item.Summary.Distance, item.Text));
                    dayDistance += item.Summary.Distance;
                }
            }
            //Remove all Bing Maps tags around keywords.  
            //If you wanted to format the results, you could use the tags
            Regex regex = new Regex("<[/a-zA-Z:]*>",
              RegexOptions.IgnoreCase | RegexOptions.Multiline);
            results = regex.Replace(directions.ToString(), string.Empty);
        }
        else
            results = "No Route found";

        Console.WriteLine(results);
        Console.WriteLine(dayDistance);
    }

}

}

Я не знаю, где установить MaxReceivedMessageSize, плюс я читал, что он работает только в Vista?!

Помогите кому-нибудь?

Ответы [ 2 ]

1 голос
/ 08 июня 2009

Я нашел решение здесь: текст ссылки

Значение maxReceivedMessgeSize находится в файле .config приложения, т. Е. Web.config или app.config и т. Д.

0 голосов
/ 09 июля 2013

Вы делаете это в app.config в WPF и web.config в asp

Хитрость в том, что maxBufferSize также должно быть равно maxReceivedMessageSize

Максимальное значение для RouteService составляет 9000000 . Я проверил это и смог получить список направлений по всему миру.

<binding name="BasicHttpBinding_IRouteService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
...