Class1.cs
Upload User: jasonxu888
Upload Date: 2007-03-28
Package Size: 4316k
Code Size: 1k
Category:

.net

Development Platform:

C#

  1. using System;
  2. using System.Runtime.Remoting;
  3. using General;
  4. using System.Runtime.Remoting.Channels.Http;
  5. using System.Runtime.Remoting.Channels;
  6. namespace Server
  7. {
  8. class MyRemoteObject: MarshalByRefObject, IMyRemoteObject
  9. {
  10. int myvalue;
  11. public MyRemoteObject() 
  12. {
  13. Console.WriteLine("MyRemoteObject.Constructor: New Object created");
  14. }
  15. public MyRemoteObject(int startvalue) 
  16. {
  17. Console.WriteLine("MyRemoteObject.Constructor: .ctor called with {0}",startvalue);
  18. myvalue = startvalue;
  19. }
  20. public void setValue(int newval) 
  21. {
  22. Console.WriteLine("MyRemoteObject.setValue(): old {0} new {1}",myvalue,newval);
  23. myvalue = newval;
  24. }
  25. public int getValue() 
  26. {
  27. Console.WriteLine("MyRemoteObject.getValue(): current {0}",myvalue);
  28. return myvalue;
  29. }
  30. }
  31. class ServerStartup
  32. {
  33. static void Main(string[] args)
  34. {
  35. Console.WriteLine ("ServerStartup.Main(): Server started");
  36. HttpChannel chnl = new HttpChannel(1234);
  37. ChannelServices.RegisterChannel(chnl);
  38. MyRemoteObject obj = new MyRemoteObject(4711);
  39. RemotingServices.Marshal(obj,"MyRemoteObject.soap");
  40. // the server will keep running until keypress.
  41. Console.ReadLine();
  42. }
  43. }
  44. }