GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Cancellable Requests Cancellable Requests
Demis Bellot edited this page
This page has moved to docs.servicestack.netThe Cancellable Requests Feature makes it easy to design long-running Services that are cancellable with an external Web Service Request. To enable this feature, register the Plugins.Add(new CancellableRequestsFeature()); Then in your Service you can wrap your implementation within a disposable public object Any(TestCancelRequest req) { using (var cancellableRequest = base.Request.CreateCancellableRequest()) { //Simulate long-running request while (true) { cancellableRequest.Token.ThrowIfCancellationRequested(); Thread.Sleep(100); } } } To be able to cancel a Server request on the client, the client must first Tag the request which it does by assigning the var tag = Guid.NewGuid().ToString(); var client = new JsonServiceClient(baseUri) { RequestFilter = req => req.Headers[HttpHeaders.XTag] = tag }; var responseTask = client.PostAsync(new TestCancelRequest()); Then at anytime whilst the Service is still executing the remote request can be cancelled by calling the var cancelResponse = client.Post(new CancelRequest { Tag = tag }); If it was successfully cancelled it will return a
Clone this wiki locally |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |