与后端Web服务通信时,我的Xamarin应用程序使用外部IP地址。使用Xamarin.iOS 9.6.2.4,调用成功。升级到Xamarin.iOS 9.8.0.323后,我现在遇到异常,消息为“Error:NameResolutionFailure”。

如果切换到使用内部IP地址或FQDN,则呼叫成功。

这似乎是最新Xamarin更新中的错误,还是应该以发出请求的方式更改某些内容?

try
{
  //Exception message - Error:NameResolutionFailure
  string url = "http://[External-IP-Address]:8081/MyWebService/api/GetByID/1";

  //The following two URLs are successful
  //string url = "http://[Internal-IP-Address]:8081/MyWebService/api/GetByID/1";
  //string url = "http://[Fully-Qualified-Domain-Name]:8081/MyWebService/api/GetByID/1";

  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
  request.ContentType = "application/json";
  request.Method = "GET";
  request.Timeout = 10 * 60 * 1000;

  using (WebResponse response = await request.GetResponseAsync())
  {
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
      string jsonData = reader.ReadToEnd();
    }
  }
}
catch (Exception e)
{
  Console.WriteLine(e.Message);
}

异常堆栈跟踪
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1005
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (IAsyncResult iar, System.Func`2 endFunction, System.Action`1 endAction, System.Threading.Tasks.Task`1 promise, Boolean requiresSynchronization) [0x00014] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at TestURL.ViewController+<ViewDidLoad>c__async0.MoveNext () [0x000b0] in /Users/Administrator/Projects/TestURL/TestURL/ViewController.cs:26

附加信息:
  • 在iPhone 6s模拟器(iOS 9.3)上运行
  • 最佳答案

    经过研究,这是Cycle 7基准发布的一个已知问题。我们正在跟踪以下公共错误:https://bugzilla.xamarin.com/show_bug.cgi?id=41782

    此时,最好的选择是保留第6个周期或(如果可能)使用完全限定的域名。

    谢谢!

    09-11 02:47
    查看更多