Select to view content in your preferred language

Route Task Error using Silverlight 2.0 API

967
5
12-06-2010 12:10 AM
RamiSourani
Emerging Contributor
I am having a routing SolveAsync error "Unable to find attribute Invalid context" using Silverlight 2.0 or 2.1 API.
While the route task is completed successfully through Silverlight 1.2 API using the same code (VS 2010) on the same Network.

Note that I am using the same sample code found in ESRI Resource Centre:
"http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Routing"

Kindly any advice would be appreciated.

FYI:
if (stopsgraphicsLayer.Graphics.Count > 1)
{
   RouteTask routeTask = LayoutRoot.Resources["MyRouteTask"] as RouteTask;
   routeTask.Url = "http://localhost/ArcGIS/rest/services/NetDS/NAServer/Route";
   if (routeTask.IsBusy)
   {
      routeTask.CancelAsync();
      stopsgraphicsLayer.Graphics.RemoveAt(stopsgraphicsLayer.Graphics.Count - 1);
   }
   routeTask.SolveAsync(new RouteParameters() { Stops=stopsgraphicsLayer, UseTimeWindows=false, OutSpatialReference=Map.SpatialReference });
}
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
You are using this same sample but different service?http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Routing

In this sample, the only time an attribute is accessed is after the RouteTask SolveCompleted. Does your service have the same attribute: "Total_Time"?

Or does the error come from RouteTask Failed? (Were error should have been preceded by "Route Error".)

Sometimes, to help identify the problem, running Fiddler with your application helps. Post #14 in this thread http://forums.arcgis.com/threads/14730-Area-And-Perimeter might help you look for information from Fiddler. You can see if these are the expected parameters to your request and also try them out in the web browser directly.
0 Kudos
RamiSourani
Emerging Contributor
Yes different network service published in my server.
The error comes from RouteTask_Failed and the process does not reach RouteTask_SolveCompleted, I just did not copy to the post "Route Error" just the "Unable to find attribute Invalid context".
Thank you
0 Kudos
RamiSourani
Emerging Contributor
Solved by tracking the problem using Fiddler:
the stops where given to the html request as follows:
{"features":[{"attributes":{"NAME":"NoName"},"geometry":{"x":5738096.9537,"y":2909726.3224,"spatialReference":{"wkid":102113}}},{"geometry":{"x":5738296.55435,"y":2911561.78485}}],"doNotLocateOnRestrictedElements":false,"type":"features"}

It seams it was past from the graphics the "{"attributes":{"NAME":"Umm Ghuwailina Health Centre"}", after removing this attribute from the graphic, the process completed successfully:
"features":[{"geometry":{"x":5738096.9537,"y":2909726.3224,"spatialReference":{"wkid":102113}}},{"geometry":{"x":5738296.55435,"y":2911561.78485}}],"doNotLocateOnRestrictedElements":false,"type":"features"}
0 Kudos
DmitryAleshkovsky
Deactivated User
My solution: populate properties of route parameters
               _routeParams.DirectionsLengthUnits = esriUnits.esriMiles;
                _routeParams.ImpedanceAttribute = "Minutes";
                _routeParams.OutputLines = "esriNAOutputLineTrueShape";
                _routeParams.OutSpatialReference = new  ESRI.ArcGIS.Client.Geometry.SpatialReference( 4326);
                _routeParams.UseHierarchy = false; // true by default and i have no Hierarchy in my network. Here was an error
0 Kudos
HoudiniSutherland
Emerging Contributor
Yup, that 'UseHierarchy' parameter being set to true by default really caused hell.
0 Kudos