Share Library:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime;
namespace DotNetRemoteTest
{
public class ResumeLoader : System.MarshalByRefObject
{
public ResumeLoader()
{
System.Console.WriteLine("Hello,it 's a dot net remoting test");
}
public Resume GetResumeByUserID(decimal userID)
{
Resume resume = new Resume(userID);
resume.UserID = userID;
resume.Title = "BackHam";
resume.ResumeID = 1001;
// resume.Body = "M U";
return resume;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace DotNetRemoteTest
{
[Serializable]
public class Resume
{
private decimal resumeID, userID;
private String body, title;
public Resume(decimal resumeID)
{
this.ResumeID = resumeID;
this.UserID = 1;
this.Body = "This is the default body of the resume";
this.Title = "This is the default Title";
}
public decimal ResumeID
{
get { return resumeID; }
set { this.resumeID = value; }
}
public decimal UserID
{
get { return userID; }
set { this.userID = value; }
}
public String Body
{
get { return body; }
set
{
this.body = value;
}
}
public String Title
{
get { return title; }
set
{ this.title = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using DotNetRemoteTest;
using System.IO;
namespace ResumeClient
{
public class ResumeClient
{
public static void Main(String[] args)
{
try
{
ChannelServices.RegisterChannel(new TcpClientChannel(), false);
ResumeLoader loader = (ResumeLoader)Activator.GetObject(typeof(ResumeLoader), "tcp://10.167.28.158:9932/ResumeLoader");
if (loader == null)
{
Console.WriteLine("unable get remote referance");
}
else
{
Resume resume = loader.GetResumeByUserID(1002);
Console.WriteLine("resumeid = " + resume.ResumeID);
Console.WriteLine("userid = " + resume.UserID);
Console.WriteLine("title = " + resume.Title);
Console.WriteLine("body = " + resume.Body);
}
Console.ReadLine();
}
catch (Exception e)
{
StreamWriter sw;
sw = File.AppendText("log.txt");
sw.WriteLine("["+ System.DateTime .Now .ToLongTimeString() + "] " );
sw.WriteLine(e.ToString() + "/n");
sw.Flush();
sw.Close();
StreamReader reader = File.OpenText("log.txt");
String line;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
reader.Close();
Console.ReadLine();
}
}
}
}
本文介绍了一个使用.NET Remoting实现的远程对象服务示例。服务端提供简历加载功能,并通过TCP通道暴露服务;客户端则通过获取远程引用调用该服务,展示获取到的简历详细信息。

1041

被折叠的 条评论
为什么被折叠?



