我在我的WPF应用程序中使用Bing Map API将地址列表固定到我的WPF UI,但有时在使用此代码块时我没有得到任何结果,有时它会返回正确数量的记录。
如何解决此问题?为什么有时bing-map响应异常?
using Microsoft.Maps.MapControl.WPF;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using Ravager.BingMapsService;
using Ravager.Shell.UI;
namespace Ravager.MappingPlugins.MapViewModel
{
public class GeoCodeResultByAddress
{
public async static Task<List<GeocodeResult>> GeocodeAddress(List<string> addres)//async Task<>
{
List<GeocodeResult> GeocodeResult = new List<GeocodeResult>();
foreach (var address in addres)
{
try
{
GeocodeResult res = null;
if (!(string.IsNullOrEmpty(address) && string.IsNullOrWhiteSpace(address)))
{
int Counts = 0;
again: using (GeocodeServiceClient client = new GeocodeServiceClient("CustomBinding_IGeocodeService"))
{
GeocodeRequest request = new GeocodeRequest();
request.Credentials = new Credentials() { ApplicationId = (App.Current.Resources["MyCredentials"] as ApplicationIdCredentialsProvider).ApplicationId };
request.Query = address;
GeocodeResponse respons = await Task.Run(() => client.Geocode(request));
res = respons.Results.Count > 0 ? respons.Results[0] : null;
if (res != null)
{
GeocodeResult.Add(res);
}
else
{
if (Counts < 3)
{
Counts++;
goto again;
}
MessageBox.Show("Unable to Generate GeocodeAddress for " + address);
}
}
}
else
{
MessageBox.Show("Unable to Generate GeocodeAddress");
}
}
catch (Exception ex)
{
}
}
return GeocodeResult;
}
}
}
答案 0 :(得分:0)
之前已经多次回答过这个问题。你很可能受到限制。当您的帐户以超过免费使用条款的费率消费交易时,或者当服务受到使用Bing地图的其他人的大量负载时,会发生试用版和基本Bing地图密钥。使用。限制速率限制可能性的唯一方法是升级到Enterprise密钥。
当请求发生速率限制时,会在响应的标头中添加一个标志,以指示已发生这种情况。这在此处记录:https://msdn.microsoft.com/en-us/library/ff701703.aspx