1 什么是SOA:面向服务架构(service oriented architecture),他属于一种组件架构模式。SOA追求的是服务提供方和服务使用方的高度解耦。

服务必须是自解释的,也就是说必须以某种标准的方式告诉整个soa系统该服务提供的功能。

2 什么是WCF(windows communication foundation)

本质上它是一套软件开发包。

设计目的:为分布式计算提供可管理的方法,提供广泛的互操作性,为服务定位提供直接的支持

提供的功能:托管,服务实例管理,异步,安全,事务管理,离线队列

3 WCF体系框架

契约:(数据契约,消息契约,服务契约,策略与绑定)定义服务端公开的方法,使用的传输协议,可访问的地址,传输的消息格式

服务运行:(事物,调度,并发,参数筛选,限流,错误,元数据,实例行为,消息行为)

消息:ws安全通道

激活与宿主:自寄宿,iis寄宿,windows激活服务,windows服务和com+组件等

4 wcf中的概念

1 地址:每个服务都具有唯一的地址。

2 绑定:

3 契约:服务契约,数据契约,错误契约,消息契约

5 终结点:(地址,绑定,契约)发送或接收消息的构造,每个服务可以拥有一个或者多个终结点

6 元数据:服务公开的元数据包括xml架构文档(用于定义服务的数据协定)和wsdl文档(用于描述服务的方法)

7 宿主:服务必须承载与某个进程中

8 知道了wcf的概念那么如何创建wcf服务

1 定义服务契约如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel; namespace HelloWorldService
{
[ServiceContract]
public interface IService
{
[OperationContract]
string HelloWorld(string name);
}
}

2 实现服务契约

像实现接口一样实现服务契约:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace HelloWorldService
{
public class Service : IService
{
public string HelloWorld(string name)
{
return name + "说:helloWorld";
}
}
}

3 创建服务的宿主

终结点中的地址和绑定都会在宿主程序中定义,一个服务契约(servicecontract)是由一组服务操作(operationcontract)组成的,当选择iis作为宿主时,iis会自动创建serviceHost类型对象,一个绑定就代表了服务和外界通信的方式。

基地址:一般包括通信协议和主机名

可选地址:定义了服务的具体位置

下面就使用servicehost对象来构建服务,以编程方式来简单的实现:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Channels; namespace HelloWorldService
{
public class MyServiceHost : IDisposable
{
private ServiceHost _myService; //使用netNamedPipeBingding协议,此协议不能跨主机进行通信,但是能够跨越应用程序域和进程通信
public const string BaseAddress = "net.pipe://localhost";//基地址
public const string HelloWorldServiceAddress = "HelloWorld";//服务的可选地址 //服务契约定义类型
public static readonly Type contractType = typeof(HelloWorldService.IService);
//服务契约实现类型
public static readonly Type serviceType =typeof( HelloWorldService.Service); //服务只定义了一个绑定
public static readonly Binding HelloWorldBinding = new NetNamedPipeBinding(); //构造servicehost对象
protected void ConstructServiceHost()
{
//初始化servicehost对象
_myService = new ServiceHost(serviceType, new Uri[] { new Uri(BaseAddress) });
//添加一个终结点,可以添加多个
_myService.AddServiceEndpoint(contractType, HelloWorldBinding, HelloWorldServiceAddress); } //servicehost只读属性
public ServiceHost Host
{
get { return _myService; }
} //打开服务
public void Open()
{
Console.WriteLine("开始启动服务");
_myService.Open();
Console.WriteLine("服务已经启动.....");
} //构造方法
public MyServiceHost()
{
ConstructServiceHost();
}
public void Dispose()
{
if (_myService!=null)
{
(_myService as IDisposable).Dispose();
}
}
}
}

然后使用入口方法来启动服务:

 class Program
{
static void Main(string[] args)
{
MyServiceHost host = new MyServiceHost();
host.Open();
}
}

如下显示:

4 下面手动编程来实现客户端访问服务端的工作

首先客户端需要将服务的元数据导入,wcf提供clientbase<T>类型来创建代理类型,t为实际的服务契约类型实例化,绑定和地址则在构造方法中传入,代理类的定义如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Channels; namespace ProxyService
{
//硬编码定义服务契约
[ServiceContract]
interface IService
{
[OperationContract]
string HelloWorld(string name);
}
class HelloWorldServiceProxy : ClientBase<IService>, IService
{
//硬编码定义绑定
public static readonly Binding helloWorldBinding = new NetNamedPipeBinding();
//硬编码定义地址
public static readonly EndpointAddress helloWorldAddress = new EndpointAddress(new Uri("net.pipe://localhost/HelloWorld"));
public HelloWorldServiceProxy() : base(helloWorldBinding, helloWorldAddress)
{ } public string HelloWorld(string name)
{
return Channel.HelloWorld(name);
}
}
}

WCF和SOA的简介的更多相关文章

  1. 使用WCF实现SOA面向服务编程—— 架构设计

    原文地址:http://www.cnblogs.com/leslies2/archive/2011/03/29/1997889.html SOA本身就是一种面向企业级服务的系统架构,简单来说,SOA就 ...

  2. js调用wcf 的SOA

    jquery 调用wcf 的SOA架构,将三层架构运用到SOA的架构中来 经过前面3天的学习,我想大家应该对SOA的架构有了初步的了解,其实 SOA与三层架构并不冲突,而是三层架构的升级版. 来看下传 ...

  3. jquery 调用wcf 的SOA架构,将三层架构运用到SOA的架构中来(第四天)

    经过前面3天的学习,我想大家应该对SOA的架构有了初步的了解,其实 SOA与三层架构并不冲突,而是三层架构的升级版. 来看下传统的三层架构! 一共可以分为4个层: 模型层(可有可无),客户端,服务端, ...

  4. SOA架构简介

    一. 什么是SOA 架构 SOA是一种架构模型,它可以根据需求通过网络对松散耦合的粗粒度应用组件进行分布式部署.组合和使用.服务层是SOA的基础,可以直接被应用调用,从而有效控制系统中与软件代理交互的 ...

  5. SOA、ESB、NServiceBus、云计算 总结

    SOA SOA 是通过功能组件化.服务化,来实现系统集成.解决信息孤岛,这是其主要目标.而更进一步则是实现更快响应业务的变化.更快推出新的应用系统.与此同时,SOA 还实现了整合资源,资源复用. SO ...

  6. RDIFramework.NET框架SOA解决方案(集Windows服务、WinForm形式与IIS形式发布)-分布式应用

    RDIFramework.NET框架SOA解决方案(集Windows服务.WinForm形式与IIS形式发布)-分布式应用 RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架 ...

  7. NET框架SOA解决方案(集Windows服务、WinForm形式与IIS形式发布)-分布式应用

    NET框架SOA解决方案(集Windows服务.WinForm形式与IIS形式发布)-分布式应用 RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,给用户和开发者最佳的.N ...

  8. 基于WCF 的远程数据库服务访问技术

    原文出处:http://www.lw80.cn/shuji/jsjlw/13588Htm.Htm摘要:本文介绍了使用WCF 建立和运行面向服务(SOA)的数据库服务的系统结构和技术要素,分析了WCF ...

  9. SOA相关资料整理分享

    昨@幸福框架同学问能否推荐SOA一些资,.想想之前看过不少资料文档,就整理分享下,有需要的可以参考下. 文章链接 理解面向服务的体系结构中企业服务总线场景和解决方案,第 1 部分 SOA 和 web ...

随机推荐

  1. linux 查看网络流量命令

    转: linux 查看网络流量命令 2019年01月31日 14:22:00 weixin_33894992 阅读数 893   sar命令参数很多,有时间man一下. -n参数很有用,他有6个不同的 ...

  2. sql控制流if()、case when then

    tb_user: 1.if (expr1,expr2,expr3) #如果expr1成立,则返回expr2,否则返回expr3示例:select  name, if (sex=1,'男','女')  ...

  3. kubernetes 之kubelet客户端证书过期问题处理 KubeClientCertificateExpiration apiserver (monitoring/k8s warning) Kubernetes API certificate is expiring in less than 7 days.

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4gAAAKMCAYAAAAZj+XuAAABfGlDQ1BJQ0MgUHJvZmlsZQAAKJFjYG ...

  4. RESTful架构(Representational State Transfer资源表现层状态转换)

    1. 什么是REST REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. 它首次出现在2000年Roy Fielding的 ...

  5. Flutter的闪屏动画案例AnimationController

    打开一个APP,经常会看到精美的启动页,这种启动页也称为闪屏动画.它是从无到有有一个透明度的渐变动画的.图像展示完事后,才跳转到用户可操作的页面. AnimationController Animat ...

  6. 相机用的 SD Card 锁Lock 烂掉了,无法正常写入

    没错,又碰到奇奇怪怪的SD Card  Lock 烂掉了 , 无法正常写入,不要急,千万不要扔了,拿起透明胶粘在 Lock 处,注意不要粘住金手指哦,再放回去就可以读写了,但是透明胶不耐摩擦,用了几次 ...

  7. tf.contrib.layers.fully_connected参数笔记

    tf.contrib.layers.fully_connected 添加完全连接的图层. tf.contrib.layers.fully_connected(    inputs,    num_ou ...

  8. Bootstrap 控制台示例

    1.打开https://getbootstrap.com/docs/4.3/examples/ 2.选择Dashboard 3.右键查看源代码,另存为 4.通过源代码界面下载JS和CSS 5.修改绝对 ...

  9. ajax head带参数两次请求

    ajax请求head里带数据 客户端先发一次option看看能不能登录,然后再发一次post

  10. Linux中tftp安装及使用笔记

    tftp命令用在本机和tftp服务器之间使用TFTP协议传输文件. TFTP是用来下载远程文件的最简单网络协议,它其于UDP协议而实现. linux服务器端tftp-server的配置 1.安装tft ...