locked
Remoting - Application Crashes RRS feed

  • Question

  • Hello there, i have an Multi-Project application consist of service and UI, and some other parts..

    For testing reason, i install my application on a company file server, which is a Win 2003 Server OS.
    On My application...what i did previously, to only register the channel once, i did this:

    calling this in Main Form Constructor:

    try
    {
       _errorListenerServer = new ErrorListenerServer(global::SharedStorage.Properties.Settings.Default.Port, "FileEventReaderChannel");
    }
    catch (Exception ex)
    {
       MessageBox.Show("Error:\n" + " Message: " + ex.Message.ToString() + "\n Stack Trace: " + ex.StackTrace.ToString(), "Interface Remote Errors");
    }

    And Define a Class which extends my Class Library

    public class ErrorListenerServer:Server
        {
            public event EventHandler<NotifyEventArgs> OnNotify;
    
            public ErrorListenerServer(int port, string url) : base(port, url)
            {
            }
    
            public override void Notify(object message)
            {
                if (this.OnNotify != null) this.OnNotify(this, new NotifyEventArgs(message));
            }
        }

    And my library, server class was like :

    public abstract class Server : IObserver
        {
            private RemotableObject _remotableObject;
            static private TcpChannel channel = null;
    
            public Server(int port, string url)
            {
                _remotableObject = new RemotableObject();
    
                //************************************* TCP *************************************//
                channel = new TcpChannel(port);
    
                ChannelServices.RegisterChannel(channel, true);
     RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotableObject), url, WellKnownObjectMode.Singleton);
                //************************************* TCP *************************************//
                Cache.Attach(this);
            }
    
            public abstract void Notify(object message);
        }


    The Issue begin after one or two day of testing, once i opened a remote to the server, after some day, i saw that the service is stopped...
    one day, i clicked over DEBUG, and fortunately Visual Studio show my own code, and i find out the cursor in my constructor class :|

    how possible?? a constructor called twist?

    ok, i see that seem there's no way i run from this...
    so i changed my code to this:

    public abstract class Server : IObserver
        {
            private RemotableObject _remotableObject;
            static private TcpChannel channel = null;
            /// <summary>
            /// Configure Server Class
            /// </summary>
            /// <param name="port">port number like: 8080</param>
            /// <param name="url">Object url like: HelloWorld</param>
            public Server(int port, string url)
            {
                _remotableObject = new RemotableObject();
    
                //************************************* TCP *************************************//
                // using TCP protocol
                if (channel == null)
                    channel = new TcpChannel(port);
                try
                {
                    ChannelServices.UnregisterChannel(channel);
                }
                catch { }
    
                ChannelServices.RegisterChannel(channel, true);
    
                if (RemotingConfiguration.GetRegisteredWellKnownServiceTypes().Length > 0)
                {
                    RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotableObject), url, WellKnownObjectMode.Singleton);
                }
                //************************************* TCP *************************************//
                Cache.Attach(this);
            }
    
            public abstract void Notify(object message);
        }


    i'm not sure if i did a right thing, but at last i can unregister the channel, also take channel it self an static object to make sure that i dont need to make it twice and it will be available, and i gain no error, and i have some thing to give to next node of code (RegisterChannel/Unregister Channel), even if the constructor called more than once...

    now when i call this method, whole service seem to stop, though no error happen:

    I have a timer class based on THreading:
    which call this event every hour:

    void _subtleTime_OnHourChangedTestForwarding(object sender, EventArgs e)
            {
                int h = ((SubtleTime)sender).Hours;
                if ((h % 4).Equals(0))
                {
                    ((EventLogger)_logProvider).Log("Testing Remoting\nApplication runing for " + h.ToString() + "Hour", "Application Testing", EventLogEntryType.Warning, 0x0, true);
                }
            }


    and the method called here based on this code :

    public interface ILogProvider
        {
            bool Log(string msg, string title, EventLogEntryType type, int id, bool sendToInterface);
        }

    and

    using System;
    using System.Diagnostics;
    using FileEventReaderService.Services.Remotable;
    using Remoting;
    using SharedStorage;
    
    namespace FileEventReaderService.Services.Logger
    {
        class EventLogger:ILogProvider
        {
            private Client _client;
    
            private string Source { get; set; }
            private string LogName { get; set; }
    
            /// <summary>
            /// Configure Log system
            /// </summary>
            /// <param name="source">Log source</param>
            /// <param name="logName">Log Name</param>
            /// <param name="url">url for remoting client</param>
            public EventLogger(string source, string logName)
            {
                Source = source;
                LogName = logName;
    
                _client = SingletonClient.GetSingletonClient().GetClient();
            }
    
            public bool Log(string msg, string title, EventLogEntryType type, int id, bool sendToInterface)
            {
    
                //CreateLogSourceIfNotExist(); only with administrative permissions
    
                string log = title + ": " + msg;
    
                WriteToEventLog(log, type, id);
    
                return (!sendToInterface) ? true : SendLogToUI(msg, title, type, id, sendToInterface);
            }
    
            /// <summary>
            /// Sends Logs to User Interface of Application using Remoting
            /// </summary>
            /// <param name="msg">Message</param>
            /// <param name="title">Title</param>
            /// <param name="type">Type</param>
            /// <param name="id">ID</param>
            /// <param name="sendToInterface">Should message be send to UI?</param>
            /// <returns>If SendToInterface is false, return false, else return value depending to its success</returns>
            private bool SendLogToUI(string msg, string title, EventLogEntryType type, int id, bool sendToInterface)
            {
                if (sendToInterface)
                {
                    bool successful;
                    try
                    {
    
                    
                    RemoteMessageType messageType = RemoteMessageEntity.ParseEventLogEntryTypeToRemoteMessageType(type);
    
                    RemoteMessageEntity message = new RemoteMessageEntity(msg, title, messageType, id);
    
                    _client.SetMessage(message);
    
                        successful = true;
                    }
                    catch (Exception)
                    {
                        successful = false;
                    }
                    return successful;
                }
                else
                {
                    return false;
                }
            }
    
            private void WriteToEventLog(string log, EventLogEntryType type, int id)
            {
                EventLog myLog = new EventLog();
                myLog.Source = Source;
                myLog.Log = LogName;
    
                myLog.WriteEntry(log, type, id);
            }
    
            /// <summary>
            /// Need Administrative permission.
            /// Times we have only application persmission we use eventLogInstaller component instead.
            /// </summary>
            private void CreateLogSourceIfNotExist()
            {
                if (!EventLog.SourceExists(Source))
                {
                    EventLog.CreateEventSource(Source, LogName);
                }
            }
        }
    }
    

    now tell me?! what should i do :'(

    • Moved by Bob Shen Monday, December 10, 2012 7:51 AM (From:Visual C# General)
    Thursday, December 6, 2012 9:45 PM

All replies

  • the caller is on Service, and The host of remoting is the UI application


    and let me add, the service exactly execute till it write event log entry on EventLogFile, and then it doesnt send any thing to UI
    • Edited by deadManN Thursday, December 6, 2012 9:49 PM
    Thursday, December 6, 2012 9:48 PM
  • Hi deadManN,

    According to your description, I'd like to move this thread to .NET Remoting and Runtime Serialization Forum for better support, where more experts live.
     
    Thanks for your understanding.


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 10, 2012 7:50 AM
  • any help?

    Thursday, December 13, 2012 6:51 PM