-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Cancellable Requests
This page has moved to docs.servicestack.net
The 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 CancellableRequestsFeature
plugin:
Plugins.Add(new CancellableRequestsFeature());
Then in your Service you can wrap your implementation within a disposable ICancellableRequest
block which encapsulates a Cancellation Token that you can watch to determine if the Request has been cancelled, e.g:
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 X-Tag
HTTP Header with a user-defined string in a Request Filter before calling a cancellable Service, e.g:
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 CancelRequest
Service with the specified Tag, e.g:
var cancelResponse = client.Post(new CancelRequest { Tag = tag });
If it was successfully cancelled it will return a CancelRequestResponse
DTO with the elapsed time of how long the Service ran for. Otherwise if the remote Service had completed or never existed it will throw 404 Not Found in a WebServiceException
.
- Why ServiceStack?
- Important role of DTOs
- What is a message based web service?
- Advantages of message based web services
- Why remote services should use separate DTOs
-
Getting Started
-
Designing APIs
-
Reference
-
Clients
-
Formats
-
View Engines 4. Razor & Markdown Razor
-
Hosts
-
Security
-
Advanced
- Configuration options
- Access HTTP specific features in services
- Logging
- Serialization/deserialization
- Request/response filters
- Filter attributes
- Concurrency Model
- Built-in profiling
- Form Hijacking Prevention
- Auto-Mapping
- HTTP Utils
- Dump Utils
- Virtual File System
- Config API
- Physical Project Structure
- Modularizing Services
- MVC Integration
- ServiceStack Integration
- Embedded Native Desktop Apps
- Auto Batched Requests
- Versioning
- Multitenancy
-
Caching
-
HTTP Caching 1. CacheResponse Attribute 2. Cache Aware Clients
-
Auto Query
-
AutoQuery Data 1. AutoQuery Memory 2. AutoQuery Service 3. AutoQuery DynamoDB
-
Server Events
-
Service Gateway
-
Encrypted Messaging
-
Plugins
-
Tests
-
ServiceStackVS
-
Other Languages
-
Amazon Web Services
-
Deployment
-
Install 3rd Party Products
-
Use Cases
-
Performance
-
Other Products
-
Future