升级到Xamarin.iOS 9.8.0.323后,NameResolutionFailure带有外部IP地址

时间:2016-06-17 13:42:25

标签: xamarin httpwebrequest ip-address fqdn

我的Xamarin应用在与后端Web服务通信时使用外部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)上运行

1 个答案:

答案 0 :(得分:4)

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

目前,最好的选择是继续使用第6周期或(如果可能)使用完全合格的域名。

谢谢!