摘要:WCF - 小呆的第一支 WCF 程式誕生
最近開始要接觸 WCF 的開發,坦白說對我來說這是一項新的東西。以往都是以 Web 為主,現在除了要熟悉 WinForm 外,還要多了解 WCF 這項技術。一般來說,第一支程式總是簡單且容易完成,以下就來實做一下...
步驟一:建立一個空白方案,並命名為「WCFSample」
步驟二:加入一個新的網站,並且使用所產生出的方法


步驟三:可以執行一下「Service.svc」
步驟四:建立一個新專案


步驟五:對 WCFClient 加入服務參考

步驟六:撰寫程式
Code:
using WCFClient.ServiceReference1;
namespace WCFClient
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceClient sc = new ServiceClient();
Console.WriteLine(sc.GetData(123456789));
            CompositeType ct = new CompositeType();
            ct.BoolValue = true;
            ct.StringValue = "Danny Chang";
Console.WriteLine(sc.GetDataUsingDataContract(ct).StringValue);
            Console.ReadKey();
        }
    }
}
結果: