WCF概要
来源:互联网 发布:qq自动加人软件 编辑:程序博客网 时间:2024/05/25 19:56
WCF:Windows Communication Foundation
一、特点概述:
1.统一ASMX, .NET Remoting, 与EnterpriseServices的开发模型:①为各种应用提供单一的编程模型;②基于配置驱动的协议选择,消息格式,进程分配等等
2.面向服务:①构建面向服务的系统设计② 简化实现SOA的方法
3.松耦合:①并没有限制在特定的协议,编码格式,或者主机环境上②所有的选项都可配置
4.可交互:支持Web Services的核心标准
5.已经批准和还未被批准的内容:在可扩展性方面能够快速适用新的协议和更新
6.整合性: 整合Microsoft早期的技术如:COM, Enterprise Services, MSMQ
二、原理示意图:
实现代码:
代码结构
简单的业务逻辑类:HelloIndigoService.cs
using System;using System.ServiceModel;namespace HelloIndigo{ [ServiceContract(Namespace="http://www.monkeyfu.net")] public interface IHelloIndigoService { [OperationContract] string HelloIndigo(string message); } public class HelloIndigoService : IHelloIndigoService { #region IHelloIndigoService Members public string HelloIndigo(string message) { return string.Format("Receivied message at{0}:{1}", DateTime.Now, message); } #endregion }}
服务端:
using System;using System.Collections.Generic;using System.Text; //WCF使用到的命名空间using System.ServiceModel;using System.ServiceModel.Dispatcher;namespace Host{ class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService))) { host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new NetTcpBinding(), "net.tcp://localhost:9000/HelloIndigo"); host.Open(); Console.ReadLine(); } } }}
客户端:
using System;using System.Collections.Generic;using System.Text;using System.ServiceModel;using Client.localhost;namespace Client{ [ServiceContract(Namespace = "http://www.monkeyfu.net")] public interface IHelloIndigoService { [OperationContract] string HelloIndigo(string message); } class Program { static void Main(string[] args) { IHelloIndigoService proxy = ChannelFactory<IHelloIndigoService>.CreateChannel(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:9000/HelloIndigo")); string s = proxy.HelloIndigo("Hello from client..."); Console.WriteLine(s); Console.ReadLine(); } }}
原理概述:客户端和服务器端保存相同的接口(契约),至于这个契约可以由服务器端直接发布为服务,这个需要在Config里进行配置:
<endpoint binding="mexHttpBinding" contract="IMetadataExchange" address="mex"/>
- WCF概要
- WCF的技术特点和优点概要
- WCF的技术特点和优点概要
- 一步一个脚印学习WCF之一WCF概要(上)之WCF与SOA
- 【学习】构建WCF面向服务的应用程序系列课程笔记:(1) WCF概要
- 一步一个脚印学习WCF之一WCF概要(中)之客户端与服务
- 一步一个脚印学习WCF之一WCF概要(下)之生成元数据与代理
- 一步一个脚印学习WCF之一WCF概要(中)之客户端与服务-WCF服务的创建与调用Demo
- 概要
- 概要
- 概要
- 概要
- Wcf
- WCF
- WCF
- WCF
- Wcf
- Wcf
- FIRST集和FOLLOW集
- How to use even ?
- Oracle中十进制与十六进制转换程序
- WM_DRAWITEM与DrawItem()的讨论
- SQL 语言支持
- WCF概要
- 精品之路
- 读书笔记[Android Beginning 2] chapter 4 Using XML-Based Layouts
- 1011 诗一样的石子
- ubuntu man手册完善
- 1013 喝醉的选手
- Android 读取资源文件
- 1014 碰撞的机器人
- Android日志系统驱动程序Logger源代码分析