Gateway.Send, CompressResponse & ContentType Header

I am using CompressResponse on a service that is called by browser client as well as another internal service. The other internal service has headers to spit out an excel file [AddHeader(ContentType = “application/”)]

I am getting a 405 Not Supported Error code when calling the [Compress]'ed service through the gateway.

Removing [Compress] allows it to work. I assume instantiating the service and calling Any(requestDTO) would work as well but neither of those seem optimal?

Any hints?

I’ve stopped the [Compress] from being applied to internal Service Gateway requests in this commit.

This change is available from the latest v5.4.1 that’s now available on MyGet.

Awesome - thank you very much.

I think I’ve got everything at myget 5.4.1 in the solution, but am still getting the error.

2019-03-22 21:21:49.104 []:ERROR:Service Ex System.AggregateException: One or more errors occurred. (ContentType not supported ‘application/’) —> System.NotSupportedException: ContentType not supported ‘application/’
at ServiceStack.Host.ContentTypes.SerializeUnknownContentType(IRequest req, Object response, Stream stream)
— End of inner exception stack trace —
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at ServiceStack.Host.ContentTypes.SerializeToString(IRequest req, Object response)
at ServiceStack.CompressResponseAttribute.ExecuteAsync(IRequest req, IResponse res, Object response)
at ServiceStack.Host.ServiceRunner`1.ExecuteAsync(IRequest req, Object instance, TRequest requestDto)
—> (Inner Exception #0) System.NotSupportedException: ContentType not supported ‘application/’
at ServiceStack.Host.ContentTypes.SerializeUnknownContentType(IRequest req, Object response, Stream stream)<—

ServiceStack doesn’t know how to serialize an unknown/unregistered Content-Type, how are you returning the contents?

If you returned it as a raw string or a byte[] it would get written to the response as-is:

Otherwise ServiceStack has no way to know how to serialize it.

Here’s a peak at the request object of outer service before calling gateway:

AbsoluteUri: “https://localhost:8443/app-product/download/40988/test11//all"
Accept: "
AcceptTypes: {string[1]}
Authorization: “Bearer …”
BufferedStream: (null)
ContentLength: 0
ContentType: (null)
Cookies: Count = 3
Dto: {ServiceModel.Download}
Files: {ServiceStack.Web.IHttpFile[0]}
FormData: {System.Collections.Specialized.NameValueCollection}
HasExplicitResponseContentType: true
Headers: {ServiceStack.NetCore.NetCoreHeadersCollection}
HttpContext: {Microsoft.AspNetCore.Http.DefaultHttpContext}
HttpMethod: “GET”
HttpRequest: {Microsoft.AspNetCore.Http.Internal.DefaultHttpRequest}
HttpResponse: (null)
InputStream: {Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream}
IsDirectory: false
IsFile: false
IsLocal: true
IsSecureConnection: true
Items: Count = 1
OperationName: “Download”
OriginalPathInfo: "/app-product/download/40988/test11/
OriginalRequest: {Microsoft.AspNetCore.Http.Internal.DefaultHttpRequest}
PathInfo: “/app-product/download/40988/test11//all"
QueryString: {}
RawUrl: "/app-product/download/40988/test11/
RemoteIp: “”
RequestAttributes: Localhost | Secure | HttpGet | Reply | FormatOther | Http
RequestPreferences: {ServiceStack.Host.RequestPreferences}
Resolver: {PublicAPI.AppHost}
Response: {ServiceStack.Host.NetCore.NetCoreResponse}
ResponseContentType: “application/”
UrlReferrer: (null)
UseBufferedStream: false
UserAgent: “PostmanRuntime/7.6.0”
UserHostAddress: “”
Verb: “GET”
XForwardedFor: (null)
XForwardedPort: (null)
XForwardedProtocol: (null)
XRealIp: (null)
Static members:
Non-Public members:

This looks like the contents of IRequest? What’s the response you’re returning?

The response of the inner service is a DTO.

 var rv = new getProductRequestResponse();

return rv;

The response of the outer service is a memory stream from a NOPI document - but we aren’t getting that far. It feels like the inner service is assuming we’re on HTTP and picking up the headers applied to the outer service’s method. It’s failing on the gateway.send(reqdto)

Service1 has content type header and returns a memory stream.
Service2 returns poco dto but has the compress attribute
Service1 Calls Service2 and fails with 405 if the compress attribute is on service2… ok if not.

It shouldn’t be as it’s no longer being run for in-process requests, did you clear your NuGet packages cache? e.g:

$ nuget locals all -clear

Ok yep. Cached packages. All Set, thanks!

1 Like