I have a web api, that is consumed by a xamarin application. Whenever I execute the web api call for the first time, it succeeds. However, every successive call fails:
Example xamarin application:
[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += async delegate
{
var cl = new HttpClient();
cl.BaseAddress = new Uri("http://10.0.5.220/api/");
var request = new HttpRequestMessage(HttpMethod.Get, "values");
HttpResponseMessage res = null;
button.Text = "";
try
{
res = await cl.SendAsync(request);
var stream = await res.Content.ReadAsStreamAsync();
StreamReader sr = new StreamReader(stream);
button.Text = await sr.ReadToEndAsync();
}
catch (Exception ex)
{
}
};
}
}
first call returns properly "value1" and "value2"
second call, when I click the button again (and any after that one):
{System.Net.WebException: Error: ConnectFailure (No route to host) ---> System.Net.Sockets.SocketException: No route to host at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000cb] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1313 at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0019b] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/System/System.Net/WebConnection.cs:195 --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1005 at System.Threading.Tasks.TaskFactory
1[TResult].FromAsyncCoreLogic (IAsyncResult iar, System.Func2 endFunction, System.Action1 endAction, System.Threading.Tasks.Task1 promise, Boolean requiresSynchronization) [0x00014] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550
However, this only happens in android application, iOS application works properly.
And the breakpoint in the controller never gets hit. It seems like request gets canceled before it gets to controller?