實現(xiàn)思路: 建立一個WCF Service,然后將其Host到一個Console 程序中,然后在另外一個Console程序中引用WCF的Service,并使用Client調(diào)用Interface中定義好的方法。
具體實現(xiàn):
1. 創(chuàng)建一個WCF Service Libraray。
1.1) File -> New -> New Project -> WCF -> WCF Service Library.)
1.2) 修改Service名和IServcie名為WillWcfService
2. 創(chuàng)建Console程序,并且把WCF Service host 到這個Console程序中。
2.1) 添加引用 System.ServiceModel, 1步中創(chuàng)建的Project (Library).
2.2) 修改App.config ( 添加 Endpoints. ( Address, Binding, Contract ). ) 便捷的方法就是直接復制第一步創(chuàng)建的WCF Service Libraray 項目中的App.config 文件里的內(nèi)容,這里面已經(jīng)有提示了。
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. -->
2.3) 在Console程序中插入代碼創(chuàng)建 Host.
using (ServiceHost host = new ServiceHost(typeof(WillWcfService)))
{
host.Open();
Console.WriteLine("Host started @" + DateTime.Now.ToString());
}
3. 創(chuàng)建Console client 程序。
3.1)運行啟動第2步創(chuàng)建的Host程序,啟動WCF Service。
3.2) 添加Service引用 (Add Service Reference), 輸入在Host程序里App.config中定義的的Address。
3.3)在Console程序里面插入代碼創(chuàng)建Client.
WillWcfServiceReference.WillWcfServiceClient client = new WillWcfServiceReference.WillWcfServiceClient();
string data = client.GetData(8);
Console.WriteLine("Get data: {0}", data);
分享標題:(WCF)利用WCF實現(xiàn)兩個Process之間的通訊。-創(chuàng)新互聯(lián)
當前URL:http://jinyejixie.com/article48/csoihp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設、響應式網(wǎng)站、建站公司、動態(tài)網(wǎng)站、標簽優(yōu)化、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容