Skip to content

Instantly share code, notes, and snippets.

@steff-mueller
Created July 25, 2012 18:54
Show Gist options
  • Save steff-mueller/3177873 to your computer and use it in GitHub Desktop.
Save steff-mueller/3177873 to your computer and use it in GitHub Desktop.
ServiceStack v4.00

Multiple reqeust DTOs per service

Default routes are normal REST routes now.

Default routes have changed to:

/[json/xml/jsv/csv/form]/[requestreply/oneway]/[operation name]

Async

The REST routes (AsyncRestHandler) and the SOAP handler (AsyncSoapHandler) are using IHttpAsyncHandler to process requests.

Created AsyncServiceBase and AsyncRestServiceBase to support async/await.

The refactored ServiceController now contains two new methods:

  • ExecuteAsync()
  • ExecuteOneWay()

The mechanism to find the REST route for a specific request was extracted out in a separate class from ServiceController: https://github.com/ServiceStack/ServiceStack/blob/async/src/ServiceStack/ServiceHost/RestController.cs.

SOAP support on HttpListener

Response binders

Sync response binders:

this.ResponseBinders[typeof(ResponseBinderResponse)] = (service, request, response) => ...

Async response binders (only available from IServiceController):

IServiceController controller = new ServiceController();
controller.AsyncResponseBinders.Add((service, request, response, callback) =>
{
    //return IServiceResult and execute callback
    //...
});

Task plugin

The Task plugin is using an async response binder to handle Task<> return types.

See the implementation of Convert() to see the custom processing for Task<> (https://github.com/ServiceStack/ServiceStack/blob/async/src/ServiceStack.Plugins.Tasks/TaskSupport.cs).

[Route] attribute

ServiceStack v4.00 supports the [Route("/path")] attribute (https://github.com/ServiceStack/ServiceStack/blob/async/src/ServiceStack.Interfaces/ServiceHost/RouteAttribute.cs). [RestService] is still supported, but was marked as deprecated.

For a route (REST path) allowed Content-Types can be set (https://github.com/ServiceStack/ServiceStack/blob/async/src/ServiceStack.Interfaces/ServiceHost/RouteAttribute.cs#L182). If the Content-Type of the request is not valid according to AllowedContentTypes, ServiceStack will try to deserialize the request with the first allowed Content-Type provided.

The default routes use this functionality to limit their Content-Type, e. g. https://github.com/ServiceStack/ServiceStack/blob/async/src/ServiceStack/ServiceHost/RestController.cs#L36. Look at DefaultRouteTests to see the exact behavior of the default routes.

The attribute also exposes a PreferredContentType property. not implemented yet

One-way services (IOneWayService)

One-way routes can be declared by doing [Route("/path", IsOneWay = true)]. For a one-way route, void ExecuteOneWay(T request) of IOneWayService (https://github.com/ServiceStack/ServiceStack/blob/async/src/ServiceStack.Interfaces/ServiceHost/IOneWayService.cs) is called.

Other

Removed formats from the EndpointAttributes enum. The user can already inspect the Content-Type of the request from IHttpRequest, so there's no need for this extra abstraction.

Additionally EndpointAttributes.LocalSubnet does not exist anymore since the overhead to check if the request is from the local subnet is too big. ServiceStack now uses IHttpRequest.IsLocal to determine if the request is from localhost or external (if a user wants to know if the request is from the local subnet, they should handle this information themselves).

Endpoint restrictions

Removed ServiceAttribute and the corresponding tests - this functionality is replaced with a filter attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment