c# - MonoTouch 不支持在设备上运行时打开 Web 服务连接的 OpenAsync 方法(在模拟器上运行)

标签 c# ios wcf xamarin.ios aot

我将 MonoTouch 4.0.7 与 MonoDevelop 2.8 Beta 2 和 XCode 4 一起使用(顺便说一句,有人知道如何获得 MonoTouch 4.2 版本吗?)。我们试图通过 slsvcutil 代理生成器生成的类调用 .Net Web 服务方法。

在 iPhone 模拟器上测试应用程序时,代码正常运行,我们成功连接到服务器并发送网络服务请求。

然而,当在设备上测试应用程序时(iPhone 4 和 iOS 4.3.5),应用程序在调用 OpenAsynch() 方法(代理生成器生成的代码中调用的方法)时无法连接到服务器,我们得到一个奇怪的错误:

正在尝试 JIT 编译方法 '(wrapper delegate-begin-invoke) '(wrapper delegate-begin-invoke) :begin_invoke_IAsyncResult_this__TimeSpan_AsyncCallback_object (System.TimeSpan,System.AsyncCallback,object)' while running with --aot-only.

我的错误堆栈:

Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method '(wrapper delegate-begin-invoke) <Module>:begin_invoke_IAsyncResult__this___TimeSpan_AsyncCallback_object (System.TimeSpan,System.AsyncCallback,object)' while running with --aot-only.
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.OnBeginOpen (TimeSpan timeout, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
at System.ServiceModel.Channels.CommunicationObject.BeginOpen (TimeSpan timeout, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
at System.ServiceModel.Channels.CommunicationObject.BeginOpen (System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
at System.ServiceModel.ClientBase`1+ChannelBase`1[ICommandMgr,ICommandMgr].System.ServiceModel.ICommunicationObject.BeginOpen (System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
at System.ServiceModel.ClientBase`
1[ICommandMgr].System.ServiceModel.ICommunicationObject.BeginOpen (System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
at CommandMgrClient.OnBeginOpen (System.Object[] inValues, System.AsyncCallback callback, System.Object asyncState) [0x00000] in CommandMgrStaticProxyClient.cs:1156
 at System.ServiceModel.ClientBase`1[ICommandMgr].InvokeAsync (System.ServiceModel.BeginOperationDelegate beginOperationDelegate, System.Object[] inValues, System.ServiceModel.EndOperationDelegate endOperationDelegate, System.Threading.SendOrPostCallback operationCompletedCallback, System.Object userState) [0x00000] in <filename unknown>:0 
at CommandMgrClient.OpenAsync (System.Object userState) [0x00057] in CommandMgrStaticProxyClient.cs:1193 

有人知道这是 MonoTouch 错误还是有办法修复此崩溃?提前致谢!

---- 编辑----

我找到了一个解决方法:用 Open() 替换 OpenAsync() 调用。因此,我认为这是 MonoTouch 的一个限制/错误,它不支持异步调用来打开 Web 服务连接。我将在 bugzilla.xamarin.com 中输入错误

 private void DoNotificationMgrOpenAsync(string address, int port)
{
  this.SystemUIHandler.LogInfo(">>>>>> NotificationMgr Open");
  m_notificationMgrClient = new NotificationMgrClient(
    new System.ServiceModel.BasicHttpBinding() { Namespace = "http://schema.dartfish.com/2011/05/RemoteControl" },
    new System.ServiceModel.EndpointAddress(
      string.Format(System.Globalization.CultureInfo.InvariantCulture, "http://{0}:{1}/Dartfish/RemoteControlServices/",
      address, port)));
  //m_notificationMgrClient.OpenCompleted += new System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(NotificationMgrClient_OpenCompleted);
  //m_notificationMgrClient.OpenAsync();

  m_notificationMgrClient.Open();
  DoGetLastMessageId();
}

void NotificationMgrClient_OpenCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
  this.SystemUIHandler.LogInfo("<<<<<< NotificationMgr Open");
  System.Diagnostics.Debug.Assert(m_notificationMgrClient != null);
  if (m_notificationMgrClient != null)
  {
    m_notificationMgrClient.OpenCompleted -= NotificationMgrClient_OpenCompleted;
    // init messageId
    DoGetLastMessageId();
  }
}

最佳答案

我认为具体问题与 Unity 3D 论坛中的这篇帖子相同:

AOT issue with += event handler syntax

在这篇文章中,生成的异步代理代码使用 += 事件语法,这需要 JIT 编译。我已确认帖子中的修复程序解决了该问题。

我没有测试过 OpenAsyc,所以您在解决事件处理程序问题后可能会遇到其他困难。

关于c# - MonoTouch 不支持在设备上运行时打开 Web 服务连接的 OpenAsync 方法(在模拟器上运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7501689/

相关文章:

c# - 我应该怎么做才能在 .NET 2.0 中使用 Task<T>?

ios - 行数在部分

iOS 8.4 MPNowPlayingInfoCenter 跳过/上一个消失

wcf - Web 引用和服务引用之间有什么区别?

.net - 我无法修改的库中类的 Wcf 数据契约(Contract)

c# - 在 "PDFsharp"中将第二个数字签名添加到 PDF 时出错

c# - XML 编写器和内存流 c#

c# - 排序 ConcurrentDictionary 有意义吗?

ios - 如何修复错误 : 'The app identifier "com. example.apple-samplecode.BreakfastFinder“无法注册到您的开发团队。”

.net - 如何以声明方式指定 AddressFilterMode.Any