public async Task <HttpResponseMessage> GetTotalBallots() { string activityId = Guid.NewGuid().ToString(); ServiceEventSource.Current.ServiceRequestStart("VotesController.GetTotalBallots", activityId); Interlocked.Increment(ref _requestCount); try { IVotingDataService client = GetRemotingClient(); var totalBallots = await client.GetTotalBallotsCast(); var response = Request.CreateResponse(HttpStatusCode.OK, totalBallots); response.Headers.CacheControl = new CacheControlHeaderValue() { NoCache = true, MustRevalidate = true }; ServiceEventSource.Current.ServiceRequestStop("VotesController.GetTotalBallots", activityId); return(response); } catch (Exception ex) { ServiceEventSource.Current.Message("Error in VotesController.GetTotalBallots method: {0}", ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "An error occurred: " + ex.Message)); } }
private static IVotingDataService GetRemotingClient() { if (client == null) { var resolver = ServicePartitionResolver.GetDefault(); var partKey = new ServicePartitionKey(1); var partition = resolver.ResolveAsync(new Uri(REMOTING_URI), partKey, new CancellationToken()); client = ServiceProxy.Create <IVotingDataService>(new Uri(REMOTING_URI), partKey); } return(client); }
public async Task <HttpResponseMessage> Delete(string key) { string activityId = Guid.NewGuid().ToString(); ServiceEventSource.Current.ServiceRequestStart("VotesController.Delete", activityId); Interlocked.Increment(ref _requestCount); IVotingDataService client = GetRemotingClient(); await client.DeleteVoteItem(key); ServiceEventSource.Current.ServiceRequestStop("VotesController.Delete", activityId); return(Request.CreateResponse(HttpStatusCode.OK)); }