WCF服务系统主要组成部分详解

开发 开发工具
WCF服务系统中主要包括三个部分,分别为:服务(Service)、主机(Host)和客户端(Client)。在这里将会做一个详细介绍。

WCF开发工具的应用,在实际程序开发中起到了非常大的作用,能为编程人员轻松的创建一个企业级的安全性极高的互联应用解决方案。在这里,WCF服务由IIS托管,且客户端也是asp.net应用。其实,这只不过是WCF服务系统的一种特殊的实现方式,即Client和Host都是Asp.net。#t#

和其它WCF系统一样,它包括三个部分:服务(Service)、主机(Host)和客户端(Client)。

一、WCF服务系统之服务和主机

1、在VS2008中,新建一个Asp.net网站:WCFserver。

 

2、在WCFserver工程中添加新的WCF服务:ServiceWCF,其实也可以直接创建WCF服务网站。

 

3、 在ServiceWCF中添加一个操作:OnHello()用以返回"Hello World!!”

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Runtime.Serialization;  
  5. using System.ServiceModel;  
  6. using System.Text;  
  7. public class ServiceWCF : IServiceWCF  
  8. {  
  9. public string OnHello()  
  10. {  
  11. return "Hello World!!";  
  12. }  

4、发布网站

在IIS中创建相应的虚拟目录,发布网站,即把WCF服务交由IIS托管

二、WCF服务系统之客户端

1、创建一个Asp.net网站:WEBAJAX,在default.aspx中添加一个Textbox和一个Button控件。

2、在工程WEBAJAX中添加“服务引用”。

 

3、创建客户端代理,调用WCF服务的操作。

 

 

  1. using System;  
  2. using System.Configuration;  
  3. using System.Data;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.HtmlControls;  
  9. using System.Web.UI.WebControls;  
  10. using System.Web.UI.WebControls.WebParts;  
  11. using System.Xml.Linq;  
  12. public partial class _Default : System.Web.UI.Page   
  13. {  
  14. protected void Page_Load(object sender, EventArgs e)  
  15. {  
  16. }  
  17. protected void Button1_Click(object sender, EventArgs e)  
  18. {  
  19. ServiceReference1.ServiceWCFClient client = 
    new ServiceReference1.ServiceWCFClient();  
  20. string Msg = client.OnHello();  
  21. this.TextBox1.Text = Msg;  
  22. }  

以上就是针对WCF服务系统做的详细介绍。

责任编辑:曹凯 来源: CSDN
相关推荐

2009-09-08 09:37:03

LINQ重要组成部分

2009-07-07 17:39:26

JSP系统

2009-06-04 07:55:08

Struts框架简介Struts

2010-03-02 13:23:11

Android手机程序

2009-07-28 15:28:35

ASP.NET AJA

2010-06-29 19:31:48

UML建模技术

2010-06-30 10:02:05

UML建模技术

2010-01-22 18:41:32

Visual C++

2023-03-20 15:51:49

综合布线结构化布线

2018-10-25 15:03:13

2021-12-12 08:35:13

数据策略数据数据分析

2016-11-25 09:48:54

Hadoop生态圈MapReduce

2023-09-06 10:33:44

2023-07-04 15:54:39

数据测试数据质量开发

2023-04-03 11:28:11

智能建筑物联网

2019-01-07 14:38:22

混合云IaaS微软

2010-03-02 10:36:05

Android窗体

2022-09-08 08:44:16

数字化转型技术

2009-06-15 08:43:46

2023-05-26 09:34:25

SDN网络
点赞
收藏

51CTO技术栈公众号