GetResponse() breaks

Hello,

I’m not sure if this is related to ServiceStack or .NET core or .NET 4.6.

Server: .NET Core 2.0, Kestrel (no IIS), ServiceStack.Core 1.0.44
Client: .NET 4.6.1, ServiceStack 4.5.14

If debug mode is enabled on server and request object sent from JsonServiceClient is large (List of 1000 items) then error message is not properly deserialized from responseStatus and everytime is “The request was aborted: The connection was closed unexpectedly.”

Problem is in StackTrace size - when debug mode is false (and StackTrace is not sent) then everything is OK.
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at ServiceStack.Net40PclExport.GetResponse(WebRequest webRequest)
at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request)
at ServiceStack.ServiceClientBase.Post[TResponse](IReturn`1 requestDto)

Please provide a stand alone example we can run to repro the issue. I will add .NET’s HttpWebRequest is a completely different implementation in .NET Core where it’s retrofitted on top of HttpClient, so can you let me know if you still have the issue when using JsonHttpClient.

I have created example app:

The Exception is raised within .NET’s HttpWebRequest when calling GetResponse() on a large response, looking to see if there’s any configuration we can enable to increase any limits.

In the meantime it works as expected when switching to use JsonHttpClient:

var client = new JsonHttpClient("http://localhost:5000");

This appears to be a bug in .NET’s HttpWebRequest (originating back to 2005) where the only config I’ve found that prevents aborting the connection is to change the protocol version back to HTTP 1.0, which you can do in a global Request Filter for all requests with:

JsonServiceClient.GlobalRequestFilter = req => req.ProtocolVersion = HttpVersion.Version10;

Or on a per request basis:

client.RequestFilter = req => req.ProtocolVersion = HttpVersion.Version10;

I don’t want to change the default config to revert back to using HTTP 1.0, but this appears the best solution to prevent this issue when using .NET’s HttpWebRequest.

OK, thanks.
It is not big problem when I know what is wrong. I just turn off debug to check my exceptions or maybe I will switch to JsonHttpClient.
Problem was when I thought that my code is causing this.

Since JsonHttpClient does not have action OnAuthenticationRequired is there recommended way to reauthenticate client on session expire or server reset?
I am using custom CredentialsAuthProvider and storing my sessions in memory for now.

I have tried to override Send method and on HttpError 400 reauthenticate user and send request again, but not sure which one needs to be overridden to have all situations covered (sync, async, POCO dtos, streams…)?

JsonHttpClient supports retrieving new JWT Tokens with the RefreshToken but there isn’t an equivalent to OnAuthenticationRequired.