昨天,進行了.net Remoting的初步學習,雖然在之前就已經接觸過這個概念,并且也了解一些,可是真正的.net Remoting程式還真從未曾真正的編寫過。昨天看了lovecherry的一步一步學Remoting序列文章,總算是邁出了.net Remoting程式的第一步,是以将這個過程記錄下來,以免以後遺忘掉了!
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/-->using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RemoteObject;
namespace RemoteClient
{
class MyClient
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("開始接受服務端資訊!");
MyObject app = (MyObject)Activator.GetObject(typeof(RemoteObject.MyObject), System.Configuration.ConfigurationSettings.AppSettings["ServiceURL"]);
Console.WriteLine("第一次測試使用的函數");
Console.WriteLine(app.Add(1, 2));
Console.WriteLine("第二次測試使用的函數");
Console.WriteLine(app.Count());
Console.WriteLine("接受資訊");
Console.ReadLine();
}
}
}
在這裡可能會出現找不到MyObject的問題,這裡的用戶端和伺服器端都需要引用RemoteObject類庫才行!如下圖所示:
<a target="_blank" href="http://blog.51cto.com/attachment/201203/224908761.jpg"></a>
本文轉自程興亮 51CTO部落格,原文連結:http://blog.51cto.com/chengxingliang/821156