1

管理された Windows サービスを介して展開される wcf サービスを作成しました。onstart() が行うことは、wcf サービスの tcp ホストを作成して開くことです。

Windows 7ではすべて正常に動作しますが、Windows Server 2008 R2にサービスをインストールしようとすると、サービスが開始され、何もすることがないときにサービスが停止することがあるというエラーで停止します。これは、ネットワーク サービス アカウントで実行されます。

Windows ログに有用なものが見つかりません。

dubug ビルドをインストールして debugger.launch() を呼び出してみましたが、機能しません。プロセスがアタッチするのに十分な時間開いたままにならないため、リモード デバッグを使用できません。どうすればいいのか本当にわかりません。これが私のコードです:

    protected override void OnStart(string[] args)
    {
        System.Diagnostics.Debugger.Launch();

        try
        {

            //if (!System.Diagnostics.EventLog.SourceExists("i2s CU Service (eng)"))
            //{
            //    System.Diagnostics.EventLog.CreateEventSource("i2s CU Service", "Application");
            //}
            System.Diagnostics.EventLog.CreateEventSource("i2s CU Service", "Application");
        }
        catch (Exception)
        {
            //throw;
        }
        eventLog1.Source = "i2s CU Service";
        eventLog1.Log = "Application";

        if (serviceHost != null)
        {
            serviceHost.Close();
        }

        System.Configuration.AppSettingsReader reader = new System.Configuration.AppSettingsReader();
        Uri tcpUri = null;
        try
        {
            tcpUri = new Uri((string)reader.GetValue("Uri", typeof(string))); //net.tcp://localhost:8008/i2sServer

            serviceHost = new ServiceHost(typeof(ConcurrentUsers), tcpUri);

            // Create a binding that uses TCP and set the security mode to none.
            NetTcpBinding b = new NetTcpBinding();
            b.Security.Mode = SecurityMode.None;

            // Add an endpoint to the service.
            serviceHost.AddServiceEndpoint(typeof(IConcurrentUsers), b, "");

            // Open the ServiceHostBase to create listeners and start 
            // listening for messages.
            serviceHost.Open();
        }
        catch (Exception ex)
        {
            eventLog1.WriteEntry(ex.Message, EventLogEntryType.Error);
        }


        if (serviceHost.State == CommunicationState.Opened)
        {
            eventLog1.WriteEntry("Service started.", EventLogEntryType.Information);
        }
    }

    protected override void OnStop()
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
            serviceHost = null;
        }
        eventLog1.WriteEntry("Service stopped.", EventLogEntryType.Information);
    }

このコードは、Windows 7 で問題なく動作しますが、win 2008 R2 サーバーでは実行できません。

前もって感謝します

4

1 に答える 1

0

アプリケーションをコンソールアプリケーションとしてリファクタリングし、目的の環境で実行して、簡単にデバッグできるようにします。

Windows サービスに割り当てられているのと同じユーザー アカウントでコンソールのレプリカを実行すると、問題が明らかになると確信しています。

于 2012-03-07T18:35:42.967 に答える