|
using System;
using System.Diagnostics;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Contexts;
namespace MyRemoteObject
{
[Serializable]
public class User : ILogicalThreadAffinative
{
private string FirstName;
private string LastName;
public string lastname{ get{ return LastName; } set{LastName = value;}}
public string firstname{ get{ return FirstName; } set{FirstName = value;}}
}
public class RemoteObject : MarshalByRefObject
{
private string _name = "Mike";
private int _id = 0;
public string Name { get{ return _name; } set{ _name = value; }}
public int Id { get{ return _id; } set{ _id = value; }}
public RemoteObject()
{
Trace.WriteLine("RemoteObject ctor");
}
public object SayHello(string reqmsg, out string rspmsg, int i, out object str)
{
User user = null;
try
{
user = (User)CallContext.GetData("User");
if(user == null)
{
user = new User();
user.firstname = "Admin";
user.lastname = "";
}
if(reqmsg == "throw")
throw new Exception(string.Format("Hi {0}, this is an Exception test", user.firstname));
rspmsg = string.Format("[#{0}] Hello {1}. You've typed '{2}'.", i, user.firstname, reqmsg);
str = string.Format("State: {0}, {1}", _name, _id++);
user.firstname = user.firstname.ToUpper();
Trace.WriteLine(string.Format("RemObject.SayHello({0}, user is {1} {2})", reqmsg, user.firstname, user.lastname));
}
catch(Exception ex)
{
Trace.WriteLine(string.Format("RemoteObject.SayHello cautch: {0}",ex.Message));
throw ex;
}
return "Done";
}
[OneWay]
public void OneWay(string msg, int ms)
{
Thread.Sleep(ms);
Console.WriteLine("RemoteObject.OneWay({0})", msg);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.