私はxamarinアプリケーションによって消費されるWeb APIを持っています。 Web API呼び出しを初めて実行するたびに成功します。しかし、すべての連続した呼び出しが失敗します。アプリケーションxamarinXamarinアプリケーションからの2番目のapi呼び出しが失敗します(最初の呼び出しは常にokを返します)
例:
[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)
{
}
};
}
}
最初の呼び出しが戻る正しく「をvalue1」と「value2の」
2番目の呼び出しを、私はもう一度ボタンをクリックしてください(以降いかなるときその1):
{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.Func
2 endFunction, System.Action1 endAction, System.Threading.Tasks.Task
1 promise, Boolean requiresSynchronization) [0x00014] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550
ただし、これはAndroidアプリケーションでのみ発生し、iOSアプリケーションは正常に動作します。
コントローラのブレークポイントは決してヒットしません。コントローラに到達する前にリクエストがキャンセルされたようですか?