0

I can work with .net remoting hosted in console application. But is there any way to host remote object in a form application rather than in console application? So that a server admin can see the requests and responses in live.

Any idea will help.

Regards SKPaul

s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • Why would it be done any differently? –  Aug 12 '11 at 03:53
  • i want a server admin monitoring the activities. – s.k.paul Aug 12 '11 at 04:07
  • It might be better to log the activity to a database or something searchable. You can do it in a Form as my answer states, but if you need to search logs or refer to them later, you need something more permenant. The activity in the form will be lost when the app crashes, and if you're just appending text to a textbox, you'll run out of memory eventually and crash. – David Aug 12 '11 at 04:12
  • Many many many thanks David. I have got some valuable tips from you regarding .net remoting. – s.k.paul Aug 12 '11 at 04:26

1 Answers1

1

Yes. It is exactly the same, only instead of instantiating and starting your host in the Main() you'd instantiate and start it in Form_Load or a button click event, or however you choose to start it. It's no different whatsoever.

Just create a WinForms app and copy your code from the console app.

As responses come in, write to a Label or a TextBox instead of Console.WriteLine() if you want to see the messages at they come in.

The only caveat is that likely the service host will be running on a different thread than the Form UI, so you'll need to know about the InvokeRequired property of the TextBox, Label, or other controls or you'll get errors when you try to write to the control from the other thread.

Invoke Required property: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx

How to make thread-safe calls to Windows Forms controls: http://msdn.microsoft.com/en-us/library/ms171728.aspx

David
  • 72,686
  • 18
  • 132
  • 173
  • if i work with console application, dont i need to work with thread? – s.k.paul Aug 12 '11 at 04:04
  • Not in the same way. Console.Writeline is thread-safe. http://stackoverflow.com/questions/1079980/calling-console-writeline-from-multiple-threads – David Aug 12 '11 at 04:09
  • Thanks a lot David. Now i am reading "How to: Make Thread-Safe Calls to Windows Forms Controls". Hope that msdn article will help me to learn. – s.k.paul Aug 12 '11 at 04:12