复制粘贴代码出错:找不到类型或命名空间

时间:2012-04-16 21:27:49

标签: c#

当尝试在两点之间实现查找路径时,我使用this article,但它产生错误:

  

找不到类型或命名空间名称'findroute'(您是否缺少using指令或程序集引用?)

using findroute.geocodeservice;
  private void Geocode(string strAddress, int waypointIndex)
    {
        // Here we create the service variable and set the callback method using the GeocodeCompleted property.
        findroute.geocodeservice.GeocodeServiceClient geocodeService = new findroute.geocodeservice.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        geocodeService.GeocodeCompleted += new EventHandler<findroute.geocodeservice.GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
        // Here we Set the credentials and the geocode query,which could be an address or location.
        findroute.geocodeservice.GeocodeRequest geocodeRequest = new findroute.geocodeservice.GeocodeRequest();
        geocodeRequest.Credentials = new Credentials();
        geocodeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)map1.CredentialsProvider).ApplicationId;
        geocodeRequest.Query = strAddress;
        // Now Making the asynchronous Geocode request, using the 'waypoint index' as
        //   the user state to track this request and allow it to be identified when the response is returned.
        geocodeService.GeocodeAsync(geocodeRequest, waypointIndex);
    }

如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

您是否遵循了这一点说明?

  
      
  • 转到解决方案资源管理器
  •   
  • 还添加服务参考 - &gt;右键单击参考

  •   
  • 添加服务参考

  •   
  • 在地址栏中输入http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/mex。这是在应用程序中使用Route相关的类。将此服务引用命名为routeservice

  •   
  • 添加其他服务参考http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc/mex。这是在应用程序中使用Geocode相关类。将此服务引用命名为geocodeservice

  •   

给出的实际名称可能是findroute.routeservice而不仅仅是routeservice,但这基本上就是它正在寻找的东西 - 相应地使用您的名字调整代码使用