WCF服務(wù)系統(tǒng)主要組成部分詳解
WCF開發(fā)工具的應(yīng)用,在實際程序開發(fā)中起到了非常大的作用,能為編程人員輕松的創(chuàng)建一個企業(yè)級的安全性極高的互聯(lián)應(yīng)用解決方案。在這里,WCF服務(wù)由IIS托管,且客戶端也是asp.net應(yīng)用。其實,這只不過是WCF服務(wù)系統(tǒng)的一種特殊的實現(xiàn)方式,即Client和Host都是Asp.net。#t#
和其它WCF系統(tǒng)一樣,它包括三個部分:服務(wù)(Service)、主機(Host)和客戶端(Client)。
一、WCF服務(wù)系統(tǒng)之服務(wù)和主機
1、在VS2008中,新建一個Asp.net網(wǎng)站:WCFserver。
2、在WCFserver工程中添加新的WCF服務(wù):ServiceWCF,其實也可以直接創(chuàng)建WCF服務(wù)網(wǎng)站。
3、 在ServiceWCF中添加一個操作:OnHello()用以返回"Hello World!!”
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.Text;
- public class ServiceWCF : IServiceWCF
- {
- public string OnHello()
- {
- return "Hello World!!";
- }
- }
4、發(fā)布網(wǎng)站
在IIS中創(chuàng)建相應(yīng)的虛擬目錄,發(fā)布網(wǎng)站,即把WCF服務(wù)交由IIS托管
二、WCF服務(wù)系統(tǒng)之客戶端
1、創(chuàng)建一個Asp.net網(wǎng)站:WEBAJAX,在default.aspx中添加一個Textbox和一個Button控件。
2、在工程WEBAJAX中添加“服務(wù)引用”。
3、創(chuàng)建客戶端代理,調(diào)用WCF服務(wù)的操作。
- using System;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- ServiceReference1.ServiceWCFClient client =
new ServiceReference1.ServiceWCFClient();- string Msg = client.OnHello();
- this.TextBox1.Text = Msg;
- }
- }
以上就是針對WCF服務(wù)系統(tǒng)做的詳細介紹。