C# 在Windows CE 6.0中使用opennetcf RAS创建持久RAS连接

C# 在Windows CE 6.0中使用opennetcf RAS创建持久RAS连接,c#,compact-framework,windows-ce,opennetcf,ras,C#,Compact Framework,Windows Ce,Opennetcf,Ras,我需要在带有windows ce 6的PDA中创建GPRS连接。现在通常我必须使用制造商的dll来创建它,但是他们说他们使用ras来实现这一点。使用它的唯一问题是,我在.NETC#中编程,而该库是非托管代码库 幸运的是,我得到了opennetcf ras库,它已经为windows ras库提供了必要的Pinvoke,唯一的问题是糟糕的文档 然后我创建了一个库,可以在windows上调用和设置必要的GPRS连接。我使用的葡萄牙电信运营商使用以下定义: Operator Name: Optimus

我需要在带有windows ce 6的PDA中创建GPRS连接。现在通常我必须使用制造商的dll来创建它,但是他们说他们使用ras来实现这一点。使用它的唯一问题是,我在.NETC#中编程,而该库是非托管代码库

幸运的是,我得到了opennetcf ras库,它已经为windows ras库提供了必要的Pinvoke,唯一的问题是糟糕的文档

然后我创建了一个库,可以在windows上调用和设置必要的GPRS连接。我使用的葡萄牙电信运营商使用以下定义:

Operator Name: Optimus P
Apn:  umts
Password: *******
User: ******
参考gsm模块定义,我有以下调制解调器设置:

Connection Name: GPRS
Device: Hayes Compatible on COM1:
Baund Rate:115200
Data Bits: 8
Parity:1
Stop Bits: 1
Flow Control: Hardware
当然还有额外的设置(或者我称之为atCall)

当我使用控制面板并使用该配置文件进行连接时,它会连接,并且我能够无错误地调用所有Web服务。它还显示调制解调器的额外配置文件,其中显示设备的设置,包括IP地址、子网掩码甚至默认网关

问题是,当我使用我创建的库以编程方式创建gprs连接,然后在某个时候调用web服务时,它会引发一个web异常:无法解析远程名称。我也检查了,额外的图标没有出现,但如果我看到GPRS状态,它会在连接时出现

创建、销毁和查询是否存在连接的代码如下:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using OpenNETCF.Net;
using OpenNETCF.Diagnostics;

namespace gsmAdapterNet
{
/// <summary>
/// GPRS Connection class
/// </summary>
public class GPRS
{
    private static string connectionName = "GPRS";


    /// <summary>
    /// Connects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static bool ConnectGPRS()
    {

            //precisamos de obter as connecoes e ligar

            RasEntryCollection connecoesPossiveis = Ras.Entries;
            RasEntry _currentEntry = connecoesPossiveis[connectionName];
            _currentEntry.RasStatus += new RasNotificationHandler(RasStatusHandler);
            RasError resultado = _currentEntry.Dial(false);
            if (resultado == RasError.Success)
                return true;
            else
                return false;


    }

    static void RasStatusHandler(int hConn, RasConnState State, RasError ErrorCode)
    {
        Logger.WriteLine("");
        Logger.WriteLine("RAS STATUS: " + ErrorCode.ToString() + " , State: " + State.ToString());
    }


    /// <summary>
    /// Disconnects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static void DisconnectGPRS()
    {
        RasEntryCollection entradas = Ras.Entries;
        foreach (RasEntry possivelEntrada in entradas)
        {
            if (possivelEntrada.Name == connectionName)
            {
                possivelEntrada.Hangup();
            }
        }


    }

    /// <summary>
    /// Determines whether this instance is connected.
    /// </summary>
    /// <returns>
    ///     <c>true</c> if this instance is connected; otherwise, <c>false</c>.
    /// </returns>
    public static bool isConnected()
    {

        RasConnection[] conecoes = Ras.ActiveConnections;
        foreach (RasConnection conecao in conecoes)
        {
            if (conecao.Name == connectionName)
                return true;
        }
        return false;

    }

    /// <summary>
    /// Dumps the ras entries.
    /// </summary>
    public static void DumpRasEntries()
    {
        foreach (RasEntry entry in Ras.Entries)
        {
            Logger.DumpRasEntry(entry);
        }
    }

}
使用系统;
使用System.Linq;
使用System.Collections.Generic;
使用系统文本;
使用OpenNETCF.Net;
使用OpenNETCF.Diagnostics;
名称空间gsmAdapterNet
{
/// 
///GPRS连接类
/// 
公共类GPRS
{
专用静态字符串连接name=“GPRS”;
/// 
///连接GPRS。
/// 
/// 
公共静态bool ConnectGPRS()
{
//这是一个很好的例子
RasEntryCollection connecosespossiveis=Ras.Entries;
RasEntry _currentEntry=connecoesPossiveis[connectionName];
_currentEntry.RasStatus+=新的RasNotificationHandler(RasStatusHandler);
RasError resultado=\u currentEntry.Dial(false);
if(resultado==RasError.Success)
返回true;
其他的
返回false;
}
静态无效RasStatusHandler(int hConn、RASCONSTATE状态、RasError错误代码)
{
Logger.WriteLine(“”);
WriteLine(“RAS状态:“+ErrorCode.ToString()+”,状态:“+State.ToString()”);
}
/// 
///断开GPRS连接。
/// 
/// 
公共静态void DisconnectGPRS()
{
RasEntryCollection entradas=Ras.Entries;
foreach(在entradas中可以输入)
{
if(possivelEntrada.Name==连接名)
{
可能的;可能的;可能的;
}
}
}
/// 
///确定此实例是否已连接。
/// 
/// 
///如果此实例已连接,则为true;否则为false。
/// 
公共静态布尔值已断开()
{
RasConnection[]conecoes=Ras.ActiveConnections;
foreach(连接conecoes中的conecao)
{
if(conecao.Name==connectionName)
返回true;
}
返回false;
}
/// 
///转储ras条目。
/// 
公共静态void DumpRasEntries()
{
foreach(Ras.Entries中的RasEntry条目)
{
Logger.DumpRasEntry(条目);
}
}
}
}

因此,继续讨论的问题是,我如何能够创建与opennetcf ras库的可行连接


最好的问候

您在拨号时获得的GPRS连接的网络接口似乎没有配置正确的DNS服务器。或者,服务调用所需的域名可能是错误的

要验证这一点,请执行以下操作:


它是否只是一个域名无法解析的特定web服务?总是一样吗?其他人工作吗?你能在建立连接后通过编程方式简单地通过HTTP获取类似的内容吗?

域名是正确的,因为我可以对www.google.com进行HTTP获取并获取页面,而且如果我通过控制面板进行连接,我的程序工作得很好。只有当我通过编程进行连接时,才会发生这种情况。
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using OpenNETCF.Net;
using OpenNETCF.Diagnostics;

namespace gsmAdapterNet
{
/// <summary>
/// GPRS Connection class
/// </summary>
public class GPRS
{
    private static string connectionName = "GPRS";


    /// <summary>
    /// Connects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static bool ConnectGPRS()
    {

            //precisamos de obter as connecoes e ligar

            RasEntryCollection connecoesPossiveis = Ras.Entries;
            RasEntry _currentEntry = connecoesPossiveis[connectionName];
            _currentEntry.RasStatus += new RasNotificationHandler(RasStatusHandler);
            RasError resultado = _currentEntry.Dial(false);
            if (resultado == RasError.Success)
                return true;
            else
                return false;


    }

    static void RasStatusHandler(int hConn, RasConnState State, RasError ErrorCode)
    {
        Logger.WriteLine("");
        Logger.WriteLine("RAS STATUS: " + ErrorCode.ToString() + " , State: " + State.ToString());
    }


    /// <summary>
    /// Disconnects the GPRS.
    /// </summary>
    /// <returns></returns>
    public static void DisconnectGPRS()
    {
        RasEntryCollection entradas = Ras.Entries;
        foreach (RasEntry possivelEntrada in entradas)
        {
            if (possivelEntrada.Name == connectionName)
            {
                possivelEntrada.Hangup();
            }
        }


    }

    /// <summary>
    /// Determines whether this instance is connected.
    /// </summary>
    /// <returns>
    ///     <c>true</c> if this instance is connected; otherwise, <c>false</c>.
    /// </returns>
    public static bool isConnected()
    {

        RasConnection[] conecoes = Ras.ActiveConnections;
        foreach (RasConnection conecao in conecoes)
        {
            if (conecao.Name == connectionName)
                return true;
        }
        return false;

    }

    /// <summary>
    /// Dumps the ras entries.
    /// </summary>
    public static void DumpRasEntries()
    {
        foreach (RasEntry entry in Ras.Entries)
        {
            Logger.DumpRasEntry(entry);
        }
    }

}