0

ローカルに接続しましたが、c# を使用KepServerEXしてリモートに接続しようとしています。KepServerEX

コンピューターがリモート サーバーに接続するように構成DCOMしましたが、残念ながらまだリモート サーバーに接続できませんKepServerEx

私はこのコマンドを使用しました:

KepServer.Connect("KEPware.KEPServerEx.V4", remoteServerIP) 

私のPC用にDCOMを構成しました。

これは私のコードです:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    OPCServer KepServer;
    OPCGroups KepGroups;
    OPCGroup KepGroup;
    OPCItems KepItems;
    OPCItem KepItem;
    string strHostIP = "";
    string strHostName = "";
    bool opc_connected = false;
    int itmHandleClient = 0;
    int itmHandleServer = 0;

    private void GetLocalServer()
    {

        IPHostEntry IPHost = Dns.Resolve(Environment.MachineName);
        if (IPHost.AddressList.Length > 0)
        {
            strHostIP = IPHost.AddressList[0].ToString();
        }
        else
        {
            return;
        }
        IPHostEntry ipHostEntry = Dns.GetHostByAddress(strHostIP);
        strHostName = ipHostEntry.HostName.ToString();

        try
        {

            KepServer = new OPCServer();
            object serverList = KepServer.GetOPCServers(strHostName);
            foreach (string turn in (Array)serverList)
            {
                bool bl = turn.Contains("KEPware");
                if (bl == true)
                    cmbServerName.Items.Add(turn);
            }
            cmbServerName.SelectedIndex = 0;
            btnConnLocalServer.Enabled = true;

        }
        catch (Exception)
        {
        }

    }

    private bool CreateGroup()
    {
        try
        {
            KepGroups = KepServer.OPCGroups;
            KepGroup = KepGroups.Add("OPCDOTNETGROUP");
            SetGroupProperty();
            KepGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(KepGroup_DataChange);
            KepGroup.AsyncWriteComplete += new DIOPCGroupEvent_AsyncWriteCompleteEventHandler(KepGroup_AsyncWriteComplete);
            KepItems = KepGroup.OPCItems;

        }
        catch (Exception)
        {
            return false;

        }
        return true;
    }

    private void SetGroupProperty()
    {
        KepServer.OPCGroups.DefaultGroupIsActive = true;
        KepServer.OPCGroups.DefaultGroupDeadband = 0;
        KepGroup.UpdateRate = 1000;
        KepGroup.IsActive = true;
        KepGroup.IsSubscribed = true;
    }

    private void GetServerInfo()
    {
        tsslServerStartTime.Text = "Start time:" + KepServer.StartTime.ToString() + "      ";
        tsslversion.Text = "version:" + KepServer.MajorVersion.ToString() + "." + KepServer.MinorVersion.ToString() + "." + KepServer.BuildNumber.ToString();
    }

    private bool ConnectRemoteServer(string remoteServerIP, string remoteServerName)
    {
        try
        {
            KepServer.Connect(remoteServerName, remoteServerIP);
            if (KepServer.ServerState == (int)OPCServerState.OPCRunning)
            {
                tsslServerState.Text = "Is connected to the -" + KepServer.ServerName + " ";
            }
            else
            {
                tsslServerState.Text = "State: " + KepServer.ServerState.ToString() + "     ";

            }

        }
        catch (Exception ex)
        {
            return false;
        }

        return true;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        GetLocalServer();
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (!opc_connected)
        {
            return;
        }

        if (KepGroup != null)
        {
            KepGroup.DataChange -= new DIOPCGroupEvent_DataChangeEventHandler(KepGroup_DataChange);
        }

        if (KepServer != null)
        {
            KepServer.Disconnect();
            KepServer = null;
        }

        opc_connected = false;

    }

    private void btnSetGroupPro_Click(object sender, EventArgs e)
    {
        SetGroupProperty();

    }

    private void btnConnLocalServer_Click(object sender, EventArgs e)
    {
        try
        {
            if (!ConnectRemoteServer(txtRemoteServerIP.Text, "KEPware.KEPServerEx.V4"))
            {
                return;
            }

            btnSetGroupPro.Enabled = true;
            opc_connected = true;

            GetServerInfo();

            RecurBrowse(KepServer.CreateBrowser());

            if (!CreateGroup())
            {
                return;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("" + ex);
        }
    }
}
4

1 に答える 1

1

最後に私は私の問題を解決しました。私の問題をあなたと共有できることをとてもうれしく思います。

まず、KepServer.Connect(remoteServerName, remoteServerIP);メソッドを使用してリモート サーバーに接続します。

クライアントとサーバー コンピューターの DCOM を構成する必要があります。リンクを参照できます: http://support.sas.com/rnd/itech/doc9/admin_oma/sasserver/comdcom/xpsp2.html

ここで重要なのは、サーバー上のユーザー名とパスワードと同じユーザー名とパスワードを持つローカル ユーザーをクライアント コンピューターに作成する必要があることです。

次のリンクを参照しhttp://www.elmajdal.net/win7/how_to_create_a_password_for_a_user_account_in_windows_7.aspxて、ユーザー名パスワードを作成できます。

これがお役に立てば幸いです。

于 2015-07-16T03:18:51.497 に答える