Bing地图凭证不存在?

时间:2012-07-19 20:45:59

标签: c# wpf soap bing-maps

我正在搞乱Bing Maps WPF控件和SOAP服务,试图反转地理编码点。我尝试从this project实现一些代码,特别是这段代码:

private string ReverseGeocodePoint(string locationString)
          {
              string results = "";
              ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

              // Set the credentials using a valid Bing Maps key
              reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
              reverseGeocodeRequest.Credentials.ApplicationId = key;

              // Set the point to use to find a matching address
              GeocodeService.Location point = new GeocodeService.Location();
              string[] digits = locationString.Split(';');

              point.Latitude = double.Parse(digits[0].Trim());
              point.Longitude = double.Parse(digits[1].Trim());

              reverseGeocodeRequest.Location = point;

              // Make the reverse geocode request
              GeocodeServiceClient geocodeService = new GeocodeServiceClient();
              GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

              if (geocodeResponse.Results.Length > 0)
                  results = geocodeResponse.Results[0].DisplayName;
              else
                  results = "No Results found";

              return results;
          }

然而,当我尝试实现它时,我被告知:Error: The type or namespace name 'Credentials' does not exist in the namespace 'GeocodeTest.GeocodeService' (are you missing an assembly reference?)此错误发生在该行:

reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();

好奇,我决定通过对象浏览器查看服务引用。显然,我的GeocodeService甚至没有Credentials成员。所以现在的问题是:

  • 我应该自己添加会员吗?如果是这样,我该怎么做?
  • 如果没有,在提供凭据方面有哪些替代方法?

1 个答案:

答案 0 :(得分:2)

服务引用Credentials不存在GeocodeText.GeocodeService命名空间/类型。相反,您必须使用Bing Maps WPF Control中的Credentials。声明如下:

reverseGeocodeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials();