2

ネットワーク経由で Web サーバーに接続するソフトウェアを開発しようとしています。ソフトウェアを保護するためにドングルを使用するまでは、すべて正常に動作します。私のドングルにはいくつかのネットワーク機能があり、ネットワーク インフラストラクチャの下で API が動作します。wドングル チェック コードをプログラムに追加すると、次のエラーが発生しました。

"Either the application has not called WSAStartup, or WSAStartup failed"  

例外をスローするコードのブロックを配置します。私が例外を得たシナリオは次のとおりです。プログラムにログインし(すべて正常に動作)、ドングルを差し込むと、プログラムが停止してドングルを要求し、ドングルを再度差し込んでログインしようとしましたが、オンラインで例外が発生しました

応答 = (HttpWebResponse)request.GetResponse();

DongleService unikey = new DongleService();

                checkDongle = unikey.isConnectedNow();

                if (checkDongle)
                {
                    isPass = true;
                    this.username = txtbxUser.Text;
                    this.pass = txtbxPass.Text;
                    this.IP = combobxServer.Text;
                    string uri = @"https://" + combobxServer.Text + ":5002num_events=1";
                    request = (HttpWebRequest)WebRequest.Create(uri);
                    request.Proxy = null;
                    request.Credentials = new NetworkCredential(this.username, this.pass);
                    ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
                    response = (HttpWebResponse)request.GetResponse();

                    Properties.Settings.Default.User = txtbxUser.Text;
                    int index = _servers.FindIndex(p => p == combobxServer.Text);
                    if (index == -1)
                    {
                        _servers.Add(combobxServer.Text);
                        Config_Save.SaveServers(_servers);
                        _servers = Config_Save.LoadServers();
                    }

                    Properties.Settings.Default.Server = combobxServer.Text;
                    // also save the password
                    if (checkBox1.CheckState.ToString() == "Checked")
                        Properties.Settings.Default.Pass = txtbxPass.Text;

                    Properties.Settings.Default.settingLoginUsername = this.username;
                    Properties.Settings.Default.settingLoginPassword = this.pass;
                    Properties.Settings.Default.settingLoginPort = "5002";
                    Properties.Settings.Default.settingLoginIP = this.IP;
                    Properties.Settings.Default.isLogin = "guest";

                    Properties.Settings.Default.Save();
                    response.Close();
                    request.Abort();
                    this.isPass = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please Insert Correct Dongle!", "Dongle Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
4

1 に答える 1

0

WSAStartup はソケット ライブラリの最初の関数で、ネットでの作業開始時に実行されます。インポートすることができます

 [DllImport("ws2_32.dll", CharSet = CharSet.Auto, SetLastError=true)]
 static extern Int32 WSAGetLastError();

例外が発生した場合は、WSAGetLastError を実行し、ここからエラー コードを確認します。それがあなたを助けることを願っています。Win32Exception を取得する特定のケースでは、 @Patrickのコメントに書かれているように、例外から NativeErrorCode を使用できます。

于 2012-09-22T08:58:15.577 に答える