【问题标题】:ConnMgrEstablishConnectionSync frequently fails with 'WaitingForConnection'ConnMgrEstablishConnectionSync 经常因“WaitingForConnection”而失败
【发布时间】:2013-08-06 10:04:40
【问题描述】:

我们有一个在 WM 6.5 上运行的解决方案,它连接到我们的服务器,但我们的一位客户经常遇到问题,即我们的软件失去了 gprs 连接,并且在手机重新启动之前无法获得新的连接。

我们知道手机位于 gprs 区域,因为我们可以远程桌面进入手机并使用 Internet Explorer 浏览。我们的日志显示,尽管我们指定了 2 分钟的超时时间,但 ConnMgrEstablishConnectionSync 以 waitingForConnection 状态返回。有人知道可能出了什么问题吗?例如,是否有可能某些 3rd 方软件正在窃取我们的连接?

非常感谢。

private void Connect()
    {
        if (_connectionHandle != IntPtr.Zero)
        {
            EventLog.AddLogEntry(LogSeverity.Trace, "connmgr - current handle was:" + _connectionHandle);
            CloseConnection();
        }

        const int connectionTimeout = 120000;

        const int CONNMGR_PARAM_GUIDDESTNET = 1;
        const int CONNMGR_PRIORITY_USERINTERACTIVE = 0x8000;
        const int CONNMGR_FLAG_SUSPEND_AWARE = 0x10; // suspended connections supported
        const int CONNMGR_FLAG_NO_ERROR_MSGS = 0x40; // don't show any error messages for failed connections
        const int CONNMGR_proxies = 0x3;
        const string testUrl = "http://www.bbc.co.uk";

        ConnectionInfo info = new ConnectionInfo();
        info.cbSize = (uint)Marshal.SizeOf(info);
        info.bExclusive = 0;
        info.dwFlags = CONNMGR_proxies | CONNMGR_FLAG_NO_ERROR_MSGS | CONNMGR_FLAG_SUSPEND_AWARE;
        info.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;

        Guid networkGuid = Guid.Empty;
        int hResult = MobileNativeMethods.ConnMgrMapURL(testUrl, ref networkGuid, IntPtr.Zero);

        if (hResult != 0)
        {
            EventLog.AddLogEntry(LogSeverity.Trace, "<<Dllimport - ConnMgrMapURL (error) " + hResult.ToString());
            throw new ConnectionUnavailableException("Unable to open connection");
        }

        info.guidDestNet = networkGuid;
        info.dwParams = CONNMGR_PARAM_GUIDDESTNET;
        uint status = 0;
        hResult = MobileNativeMethods.ConnMgrEstablishConnectionSync(ref info, out _connectionHandle, (uint)connectionTimeout, out status);
        if (hResult != 0)
        {
            EventLog.AddLogEntry(LogSeverity.Trace, "<<Dllimport - ConnMgrEstablishConnectionSync (error) " + networkGuid.ToString());
            throw new ConnectionUnavailableException("Unable to open connection: " + (ConnectionStatus) status);
        }
        EventLog.AddLogEntry(LogSeverity.Trace, "<<Dllimport - ConnMgrMapURL Connection OK");
    }

【问题讨论】:

  • 什么是 ConnMgrProxy = 0x03,msdn.microsoft.com/en-us/library/bb840031.aspx 中未列出此 const 值。由于通过 ConnMgr 建立的连接通常是共享的,您是否考虑过使用 bExclusive?另一个问题是,如果用户尝试使用提供的连接在设备上手动连接会发生什么,这意味着:如果用户尝试在 InternetExplorerMobile 中打开网站会发生什么? - 如果手机在语音模式下使用,ConnMgr 无法正常建立数据连接。
  • 嗨,josef,在我试图解决问题时,我补充说,它是启用 HTTP 和 WAP 代理的合并。无论有没有它,我都会遇到同样的问题。我没有尝试独占,因为我们的软件保持长期连接,所以它会杀死其他应用程序。我突然想到其他一些应用程序可能设置了独占标志。有什么方法可以检查吗?用户报告说他可以在我们的通讯中断时使用 Internet Explorer
  • 那么,你的意思是另一个应用打开了独占连接?如果是这样,为什么用户可以使用现有连接浏览互联网?可能你可以在开始你自己的 connmgr 连接之前尝试一个 http 请求。如果 http 请求失败(这不应该发生,因为这应该会启动 Internet 连接),您可以启动 connmgr 连接请求。可能您的连接设置有误。也许您可以尝试 MSDN connmgr C# 示例 msdn.microsoft.com/en-us/library/bb840031.aspx 或 OpenNetCF。我会寻找一个 ConnMgr 记录器。
  • 我做了一个 ConnMgr 日志工具(C#,OpenNetCF)。您可以下载 www.hjgode.de/temp/ConnectionManagerLog.zip 的源代码和二进制文件。它列出了已知的连接,并将所有 30 秒记录到一个日志文件中。

标签: c# .net windows-mobile gprs


【解决方案1】:

最后我发现将注册表中的 AlwaysOn 设置设置为 false 可以解决问题。我怀疑霍尼韦尔设备存在更深层次的问题,而摩托罗拉设备的这种设置似乎无论其价值如何都可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 2020-11-14
    • 2011-03-01
    • 2018-03-12
    • 2014-07-29
    • 1970-01-01
    相关资源
    最近更新 更多