xamarin 응용 프로그램에서 사용하는 웹 API가 있습니다. 웹 API 호출을 처음 실행할 때마다 성공합니다. 그러나, 모든 연속적인 호출이 실패 : 응용 프로그램 자 마린Xamarin 응용 프로그램에서 두 번째 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)
{
}
};
}
}
첫 번째 호출이 반환 "값 1"과 "값 2"를
초 전화, 나는 다시 버튼 (및 이후를 클릭 할 때 하나는) :
{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
그러나 이것은 단지 아이폰 OS 응용 프로그램이 제대로 작동, 안드로이드 응용 프로그램에서 발생합니다.
컨트롤러의 중단 점에 절대로 도달하지 않습니다. 컨트롤러에 도달하기 전에 요청이 취소 된 것 같습니다.