I would like to call internal or external services (through Consul) from a service method with the Gateway.Send but I get InvalidCastException if I use the ToOptimizedResultUsingCache.
I read this post InvalidCastException, getting back ServiceStack.CompressedResult instead of data but I don’t know how to use it with external services.
You can’t call a Service Gateway using ToOptimizedResultUsingCache since it returns the compressed byte[] on cached requests whereas the Service Gateway needs access to the unserialized Response DTO. If you use the newer [CacheResponse] Attribute it wont return compressed byte[] responses for Service Gateway requests.
It applies to all ToOptimizedResult APIs for reasons above.
Don’t use the [CacheResponse] attribute with ToOptimizedResult, just use one or the other and if you want to be able to call it via the Gateway you cant use the ToOptimizedResult APIs.