ServiceStack BaseUrl configuration

Is it possible to configure the ServiceStack reference using a appsettings file?

I am working with a couple of different webservices that I maintain myself and I want to be able to switch between local running instances and deployed instances using my solution build configurations. I use my appsettings for a couple of different settings but I did not manage to find out how I can configure my ServiceStack reference using a configuration or settings file.

Is there a way to generate the C# dto’s using the https://marketplace.visualstudio.com/items?itemName=Mythz.ServiceStackVS extension? Or is there another way to achieve the same result?

Thanks in advance!

I don’t know exactly what you’re asking, but the Typed DTOs themselves are generated from the remote ServiceStack instance not a client generation tool. So it’s only using the configuration of the remote instance which needs to be available when generating the ServiceStack Reference DTOs.

If the server APIs are deployed on multiple instances, the same DTOs / code can be reused by simply changing the baseUrl for which server the client should send the client requests should be sent to:

var baseUrl = ...;
var client = new JsonServiceClient(baseUrl);

If you instead want the same app to call multiple different ServiceStack APIs you can specify which file name the dtos should be generated in, e.g:

x csharp https://app1.example.org app1
x csharp https://app2.example.org app2
x csharp https://app3.example.org app3

This will generate each DTOs in different files, e.g. app1.dtos.cs all of which can be updated with a single command using the x dotnet tool:

x csharp

Alternatively you can update the DTOs from a specific app by specifying its filename, e.g:

x csharp app1.dtos.cs

Each generated DTOs can be further individually customized with the DTO Customization Options, e.g. if you want them to generated under a specific C# namespace you can use:

GlobalNamespace: App1

Which will be used after updating the ServiceStack reference.

The only other customization is available by applying them on the server, see the C# Server Configuration docs for an example.

Thank you for the quick reply!

I think I can make it work with the x tool. Using a local configuration I will update the dto’s using a local running instance of the service. This way I can test multiple versions of my dto’s just by changing the configuration.

Is it possible to do some of the configuration while using the x tool?
For example: can I use the tool like

x csharp https://app1.example.org app1 --globalnamespace=“MyGlobalNamespace”

There’s not an explicit command, but after changing the GlobalNamespace Header options after download it for the first time, running the update command will send any custom options:

$ x csharp

But you can achieve the desired behavior by downloading the custom URL directly with x get, e.g:

$ x get https://app1.example.org/types/csharp?GlobalNamespace=MyGlobal -out app1.dtos.cs