Ios async rest call never returns after upgrade to 4.0.0
I love Refit and have been using it for my X.F. project. Recently I moved from PCL to .net standard for my shared code. I use Refit in combination with ModernHttpClient and up to version 3.1.0 all works fine. After upgrade to 4.0.0 or higher on Ios only my async rest calls seems to be awaiting for ever. I have added a working basic example project to demonstrate the issue, the rest call never returns. If you downgrade refit to 3.1.0 it will work. On android it is not a problem
My Interface:
[Get("/posts/{postId}")]
Task<PostModel> GetPostAsync(int postId);
My Code:
var testApi = RestService.For<ITestApi>(new HttpClient(new NativeMessageHandler()) {
BaseAddress = new Uri("https://jsonplaceholder.typicode.com") });
var post1 = await testApi.GetPostAsync(1);
// With Refit 3.1.0 above line works fine
// With Refit 4.0.0 and higher above line seems to await for ever
Deleted my previous comment as my libraries have indeed been updated to 4.0.1. I'm seeing the same issue and as above only on iOS, Android works fine.
If you look with Fiddler, what do you see? Is the request actually being fired?
Also, I wonder if this is related to another issue: https://github.com/paulcbetts/refit/issues/347
Issue #347 is IOS only but that is the only resemblance.
- In my case version 2.4.1 has no problem while the other do.
- Also in the other issue an exception is thrown while in my case it does not.
So my feeling is that it is unrelated.
If you look with Fiddler, what do you see? Is the request actually being fired?
I used nettop to monitor the network traffic that the ios simulator is generating and yes the request is being fired. With refit 3.x i see a connection with the backend "https://jsonplaceholder.typicode.com" = 104.31.86.157:443 is being made en data is returned.
With refit 4.x i see the same connection but the call never returns
I just created a new sample app using Refit 4.0.1. Making a POST call to https://requestb.in which works as expected. The call returns just fine. Do you have a reproduction sample we can use?
Also this was without ModernHttpClient. Not going to add it since it is not maintained and broken on Android. You shouldn't use it...
Both HttpClientHandler and NSUrlSessionHandler work as expected.
Edit: Now also tried against typicode.com, this also works and returns as expected.
Do you have a reproduction sample we can use?
Yes see the end of my first post: https://github.com/paulcbetts/refit/files/1283667/RefitTest.zip
One small update, change the line:
mainLabel.Text = post1.title
into
Device.BeginInvokeOnMainThread(() => mainLabel.Text = post1.title);
The issue is with ModernHttpClient, not Refit.
You are right, when I remove ModernHttpClient it does work indeed!
Also this was without ModernHttpClient. Not going to add it since it is not maintained and broken on Android. You shouldn't use it...
Do you have any reference of the above? I thought that ModernHttpClient was improving everything by using the native httpclient but it if you are right it makes things worse.
Just go to the modernhttpclient repo, and see that it has been inactive for ages.
Xamarin provides its own native client handlers, which you should use instead.
For now I removed ModernHttpClient and all works fine.
Xamarin provides its own native client handlers, which you should use instead.
Does this mean I can replace modernhttpclient with an other "native" httpclient to improve the performance? Do you have an example or where can I find the documentation?
Both HttpClientHandler and NSUrlSessionHandler work as expected.
Is this what you mean with "Xamarin provides its own native client handlers, which you should use instead." ? How should I use this? Can you share the example project you made to test this issue?
I too have been using the ModernHttpClient based on a number of posts on the web. Can I respectively suggest that the repo and maybe nuget pages for ModernHttpClient be updated to reflect your advice that it isn't maintained and to avoid using it. Thanks.
I don't have access to that repo, nor the nugets.
This blog posts describe using Xamarin Native handlers: http://jonathanpeppers.com/Blog/improving-http-performance-in-xamarin-applications
Closing as external