What is SOA?
SOA or Service oriented architecture is an architecture style for building business applications by means of services. Application comprises collection of services which communicate through messages.
SOA或面向服务的架构是一种以服务的形式构建企业应用的架构形式,应用由通过消息通信的服务组成。
Service 服务
- Services are logical encapsulation of self-contained business functionality
- 服务是业务功能字自包含的逻辑封装
- Every Service encapsulates one action such as Register User, Send Email etc.
- 每个服务封装了一个动作,如用户注册,邮件发送等
Messages 消息
Services communicate with each other using messages. Messages are standard formats which everyone (every service) can read and understand.
服务之间使用消息通信。消息是一些任何人(服务)可以读取并理解的标准的格式。
Characteristics of SOA SOA的特点
- In SOA, Services should be independent of other services.
Altering a service should not affect calling service. - 在SOA中,服务之间应保持独立。更改一个服务不能影响到服务的调用。
- Services should be self-contained.
When we talk about a RegisterCusomer service it means, service will do all the necessary work for us, we are not required to care about anything. - 服务应该是自包含的
当我们讨论一个客户注册服务时,服务将为我们完成所有必须的工作,而我们不必要关心任何事情。 - Services should be able to define themselves.
Services should be able to answer a question what is does? It should be able to tell client what all operations it does, what all data types it uses and what kind of responses it will return. - 服务应该能定义自身
服务应该能够回答其是什么的问题,能够告诉客户它所有的操作,所有它使用的数据类型和返回的类型 - Services should be published into a location (directory) where anyone can search for it.
- 服务应该发布在一个任何人可以获取到的区域(目录)中
- As I said, SOA comprises of collection services which communicate via standard Messages.
Standard messages make them platform independent.
(Here standard doesn’t mean standard across Microsoft it means across all programming languages and technologies.) - 像我所说的,SOA由一些通过标准消息通信的服务组成
标准消息机制让他们彼此独立。
(这里所说的标准并不意味只是在微软之间,它意味着跨所有编程语言和技术的标准) - Services should be able to communicate with each other asynchronously.
- 服务之间应该能进行异步通信
- Services should support reliable messaging.
Means there should be a guarantee that request will be reached to correct destination and correct response will be obtained. - 服务应该提供可靠的消息服务
消息应该是一个保证请求能到达正确的目的地并正确的返回 - Services should support secure communication.
- 服务应该提供安全的通信
WCF and Web services
WCF is a Microsoft framework for building Service-Oriented applications.
Comparing Web services with WCF will not be a good idea. Can you compare yourself with yourself in past(let's say two year before)? Obviously in two year you might have learned new things, improved somewhat,right? WCF and Web service are related to each other in same manner. WCF has evolved from Web services and so WCF can do all which a web services is capable of, plus can do some more.
WCF是为构建面向服务应用所构建的一个微软框架。
用WCF与其他Web servie对比不是一个好主意。你能用自己的现在和过去(两年前)进行对比吗?很明显,在两年里你可能学到新东西,改善些什么。对吧?WCF和Web service 彼此之间是相同的方式。WCF从Web service进化而来,所以WCF有Web service的能力,而且还可以做的更多。
Features of WCF WCF特点
- WCF hosting WCF宿主- If we are working with web services then only option we are having is hosting it inside web server such as IIS using http or wshttp protocols. But WCF supports four types of hosting
如果我们使用Web service技术,我们只有一个宿主,就是将其放在Web服务器中,如IIS使用http或wshttp协议。但是WCF支持4种类型的宿主
- IIS
- WAS (Windows process activation services)
- Self-hosting 自宿
- Windows services
更多关于WCF宿主资料:
http://msdn.microsoft.com/en-us/library/bb332338.aspx - Message transmission - Messages can be transmitted between clients and service via various transport protocols and encodings such as SOAP using http and binary data using TCP.
- 消息传输- 消息可以在客户与服务之间通过多种传输协议进行传输并封装成如使用http协议的SOAP和使用TCP的二进制数据。
- Serialization - Web services uses XmlSerializer for transferring data between service calls whereas WCF supports multiple serializers
- 序列化-Web services使用XmlSerializer在服务调用时进行数据传输,而WCF支持多种序列化
- DataContractSerializer(faster and supports versioning)
- NetDataContractSerializer(when it required to include CLR type information in the serialized XML)
- XmlSerializes(mostly to support backward compatibility).
- Multiple technologies at one place - WCF unites following four technologies
- 一个地方多种技术-WCF联合了以下四种技术:
- .NET remoting
- MSMQ
- Web Services
- COM+
- Message Contract - In Web services customizing the headers of the SOAP message was a tedious task. For that we were supposed to derive a class from SoapHeader and then SoapHeaderAttribute is used to indicate the presence of the header.
But with WCF we can make it easily with the help of simple attributes like MessageContractAttribute, MessageHeaderAttribute, and MessageBodyMemberAttribute. - 消息契约 - 在Web services定制的SOAP消息头是一项乏味的任务。为此,我们应该得出一个从SoapHeader类,然后SoapHeaderAttribute用来表示标头的存在。但是使用WCF我们可以使用一些简单的属性如: MessageContractAttribute, MessageHeaderAttribute, and MessageBodyMemberAttribute.让这些变得很容易。
- Multiple Message Patterns - WCF supports three message patterns that describe how client and service pass messages
- 多消息模式-WCF支持三种消息模式用来描述客户端和服务端如何传递消息
- Request-Reply Pattern – Client sends message to service and waits for reply. 客户端发送消息到服务端等待回复。
- One-Way Message Pattern – Client sends message to service but service does not reply message to client. 客户端发送消息但服务端不回复
- Duplex pattern – Both client and the service can initiate communication. The client calls a method of the service. The service can then use a client callback to call a method in the client. 客户端和服务均可以发起通信,客户端调用服务的一个方法,服务可以使用客户端的回调调用客户端的方法。
- Security - In WCF security can be implemented with the help of well-known standards such as SSL.
- 安全性-WCF安全性可以实现众所周知的标准如SSL
- Reliable - WCF supports reliable messages with the help of Queues and reliable sessions.
- 可靠性-WCF使用队列和可靠会话的支持来提供可靠的消息。
- REST - WCF can be extended to support plain xml data that is not wrapped in a soap envelope, xml formats such as ATOM and non xml standard such as JSON.
- REST-WCF可以被扩展来支持不需要在SOAP信封中的简单XML数据,XML格式如ATOM和无XML标准的格式如JSON。
- WCF Transaction - - WCF supports to create distributed transactions for your service application. Transaction is a collection of logical operations which need to be run as a single logical unit.
(Either all operations will successfully execute and completes or in case any of them fail others will rollback). - WCF 事物处理-WCF支持为服务应用创建分布式事物处理。事物处理是逻辑操作的集合,需要以一个单独的逻辑单元来运行。
- WCF instancing - In WCF we can control the way WCF service objects are instantiated in the WCF server. WCF Framework comes up with following instancing models
- Per Call - A new instance will be created for every client request.
- Per session - A new instance is created for each new client session and maintained for the lifetime of that session.
- Single - A single instance handles all client requests for the lifetime of the application.
- WCF Concurrency - With WCF Concurrency features we can control how service instances can serve multiple requests at the same time. We have three choices
WCF 并发--使用WCF并发机制我们可以控制服务的实例如何在同一时间响应多个请求,我们有三个选择:
- Single – Only one request will be served at a time. 同一时间只处理一个请求
- Multiple - Multiple requests can be handled by the WCF service object at any given moment of time. 在任意给定时间内服务可以处理多个请求
- Reentrant - A single request thread has access to the WCF service object, but the thread can exit the WCF service to call another WCF service or can also call a WCF client through callback and reenter without deadlock.一个单独的请求线程访问WCF服务,但是线程可以退出服务去调用另一个WCF服务或也可以通过回调程序调用一个WCF客户端并在无死锁的情况下再次执行。
What is ABC in WCF
We had gone through the feature of WCF and understood why its termed as advanced version of web services. Now it’s time to answer a very basic question related to WCF i.e., what is ABC of WCF?
When we say WCF, we came across end points. Service endpoint can be a part of continuously hosted service hosted in IIS or service hosted in an application.
当我们谈及WCF,我们会碰到end points,服务端点可以是连续托管服务托管在IIS或者托管在一个应用程序中的一部分。
ABC or Address, Binding and Contract are the three elements which constitutes and Service Endpoint.
- Address - Where Service is residing (URL of the service.)
- Binding – How to talk to the service? Example – basicHttpBinding, wsHttpBinding, webHttpBinding etc.
- Contract – What can the service do for me?
Conclusion
We have understood
- What is Service oriented architecture?
- Why SOA required?
- What are the characteristics of SOA?
- How WCF can be differentiated from Web service?
- What are the characteristics of WCF?
- What is mean by ABC of WCF?
In the coming up article we will try to talk about each of the WCF feature in more detail.
------------------------------------------------分割线-------------------------------------------------------------------
Ends, Contract, Address, and Bindings?
以上这些术语是SOA标准的核心。每个服务必须使用对于客户端可用的服务暴露一个或多个端(ends),包含了三个重要的信息: where, what and how:
Contract (What)
契约是一个双方或多方达成的一致,定义了客户端如何和服务通信的协议。典型的,它描述方法的参数和返回值。
Address (Where)
地址指示怎样可以找到这个服务,地址是一个URL,指向服务的位置。
Binding (How)
绑定决定这个端怎样被使用。他决定通信如果完成,例如,你暴露出自己的服务,可以使用http之上的SOAP或者TCP之上的二进制方式访问。因此,对于这些通信方式,将创建两个绑定。
The Important Principles of SOA?
WCF基于SOA,SOA基于4个重要的概念:
Boundaries are Well Defined 良好的边界定义
在SOA中,一切都是正规化的。消费服务的客户端不需要知道服务是如何实现的。如果你看一些像DCOM老式的通信方法,服务器层发生任何变化客户端也需要跟着变。因此,服务端和客户端实现有很强的约束,更改需要在所以的地方进行。在SOA中,规则是如果你在服务端有更改在客户端无需改变任何东西。基于SOA的应用只需要知道终点、契约、绑定。
注意:只需要简短的声明终点和契约,任意一个SOA服务是通过重点暴露出来,重点定义包含三个重要的方面即数据,在哪和怎么做。
Services Evolve 服务封装
变化是自然界的法则,服务也是一样。则SOA中,服务可以有版本,并且你可以将那些服务托管到新的终点下。例如,你有一个提供基于票号的细节信息服务叫做“Search Tickets”,它暴露在终点“ep1”上。明天你想要让搜索票的服务通过提供一个额外的允许他使用乘客姓名进行搜索的选项而更加有用,因此,你只为服务“Search Tickets”声明了一个新的终点“ep2”。
Services Share Only Schemas and Contracts 服务只共享结构和契约
服务使用Schemas来表示数据和契约以理解行为。为了理解数据和行为,他们不使用独立的语言类型或者类。XML是一个用来描述schemas和契约的工具,因为这样各个环境之间没有比较重的耦合。
Service Compatibility is Policy Based 基于策略的服务兼容性
策略描述了系统的能力。依靠策略,服务可以降级来为客户端匹配服务。例如,你的服务需要托管在可以为两种客户端,一个使用远程作为通信方法,而另一个客户端使用DCOM,理想的SOA服务可以根据通信策略兼顾他们二者。
---------------------------------------------------------------------------------------------------------------------
5种简化SOA的方法
SOA方式的解决方案看起来很复杂;然而,进行做一些简单的事情可以让SOA项目简单很多。
在正确的问题上使用SOA
SOA不是一个解决所有集成问题的方案。在错误的问题中应用SOA可能会增加更多的问题。
考虑组织边界 – 部门, 卫星办事处,贸易伙伴。组织间通常有重复的数据让他们能方便的获取和传输相关信息。SOA让共享业务组件变得容易-像消费者、生产者以及产品信息。SOA是解涉及到一系列感兴趣的业务流程信息获取和分发的理想选择。
购买工具前应关注业务过程
设计并构建正确的服务
当我们决定服务构建,关注服务对业务和组织的价值,关注组织、业务伙伴和其他地区办事处之间的信息共享(而不是数据共享)。开始理想的模型之前考虑时间,技术能力等等因素
以正确的方式暴露服务
SOAP 和 REST 是两个暴露服务的关键方式。考虑服务客户端,调用模式,安全性以及网络架构。考虑你的业务过程-它们复杂到需要协调服务吗?另一个极端是,业务流程简单到你可以使用你们组织的基础设施来实现服务吗?传统的系统在你的业务过程中,并且他们需要的消息是什么?
建立一个SOA平台
一个SOA平台就是一个框架,支持:
- 服务管理 – 健康和活动追踪,部署能力
- 可靠的消息 – 支持事物处理, 持久的消息,可靠的队列
- 服务注册 – 支持你业务的方式定义和安放服务,提供人和程序或系统的访问方式
- SOA 安全 – 充分利用现有的基础设施,引进一种新的安全基础设施,或创建一个混合的解决方案