Auto-Generating Client Code - OpenRasta, Nancy and ServiceStack

619 views Asked by At

I have looked through the documentation for the above Frameworks to see if they provide a facility to auto-generate client code, i.e. classes for models. Does anyone know whether they can, or do you have to try and do this using svcutil? If so, does anyone have any experience of this?

1

There are 1 answers

0
mythz On

ServiceStack has a number of different options for enabling a strong typed API for consuming ServiceStack Services on the client:

1) Share Server DTO's on Client

ServiceStack encourages logically separating your Services so that your Services Request and Response DTO's (i.e. Message Contracts) are defined in a dependency and impl-free project, typically named {ProjectName}.ServiceModel. This recommended project structure is contained within each of ServiceStackVS VS.NET Project Templates.

The benefits of this approach is that you're clients are able to re-use the Server DTO dll (used to define the Web Services Contract with) in combination with any of the .NET Service Clients to enable an end-to-end typed API without any code-gen.

This approach also lets you define your Message-based DTO's (i.e. Services Contracts) code-first, i.e. free of any implementation concerns letting you focus on the domain value of what Services should accept and return. Once DTO's are defined, the Client and Server teams can implement them in parallel and independently of each other as clients can bind to Service responses before they've even been implemented.

All ServiceStack's ServiceClients implements clean interfaces (e.g. IServiceClient) which allow clients to be easily mocked to to return to stub results until the Server is implemented.

2) Add ServiceStack Reference

Add ServiceStack Reference provides an alternative for sharing DTO dlls, which can enable a better dev workflow for external clients who can instead generate (and update) Typed APIs for remote ServiceStack Services from their BaseUrl - reducing the burden and effort required to consume ServiceStack Services whilst benefiting from clients native language strong-typing feedback.

Add ServiceStack Reference also includes integration with most leading IDE's where clients can easily add a reference to a remote ServiceStack instance and update DTO's directly from within VS.NET, Xamarin Studio, XCode and Android Studio for these supported languages:

Supported Languages

3) SOAP and WSDL Generated Proxies

Sharing DTO's or using Add ServiceStack Reference is the recommended approach as it holds a number of benefits over using SOAP, WSDL's and generated proxies for enabling a typed Client API which encourages a complex and fragile combination of technologies used in web service implementations today.

But when they're needed, ServiceStack also enables SOAP endpoints for your Services that follow the SOAP limitations, providing the WSDL and XSD's necessary for external clients to generate a WSDL-generated proxy.