This code helps you know how to consume dataservice from silverlight application
public void GetModelsByDataService(string DataServiceURL)
{
try
{
context = new ShapeCollection(new Uri(DataServiceURL));
var models = from m in context.EquipmentModels select m;
DataServiceQuery<EquipmentModel> equipmentmodelQuery = models as DataServiceQuery<EquipmentModel>;
equipmentmodelQuery.BeginExecute(new AsyncCallback(OnGetModelsComplete), equipmentmodelQuery);
}
catch (Exception ex)
{
throw ex;
}
}
void OnGetModelsComplete(IAsyncResult result)
{
DataServiceQuery<EquipmentModel> equipmentmodelQuery =result.AsyncState as DataServiceQuery<EquipmentModel>;
try
{
List<EquipmentModel> lstOfEquipmentModels = equipmentmodelQuery.EndExecute(result).ToList();
var mds = from equipmentAttribute in lstOfEquipmentModels
select equipmentAttribute.Name;
List<string> modelsList = mds.ToList<string>();
modelsList.Sort();
if (GetEquipmentModelsDataServiceCompleted != null)
{
GetEquipmentModelsDataServiceCompleted(modelsList);
}
}
catch (Exception ex)
{
if (GetEquipmentModelsDataServiceCompleted != null)
{
GetEquipmentModelsDataServiceCompleted(null);
}
}
}
No comments:
Post a Comment