如何将多个航点发送到虚拟地球路由Web服务

时间:2009-06-05 16:59:25

标签: c# web-services bing-maps bing virtual-earth

我正在尝试使用虚拟地球网络服务:

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

返回已停在多个点的车辆的总行程距离。

我的代码适用于有4个航点的旅程,但除此之外我还会收到以下错误:

  

最大邮件大小配额   传入消息(65536)已经存在   超标。要增加配额,请使用   MaxReceivedMessageSize属性   适当的绑定元素。

粗略的代码是:(C#console app)

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 个答案:

答案 0 :(得分:1)

我在这里找到了解决方案: link text

maxReceivedMessgeSize位于应用的.config文件中,即web.config或app.config等。

答案 1 :(得分:0)

您可以在WPF中的app.config和asp

中的web.config中执行此操作

诀窍是,maxBufferSize也必须等于maxReceivedMessageSize

The max for RouteService is 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">