Application Architecture Guide 2.0 学习笔记(一)前言 - Services

 Services

The following guidelines will help you to understand the fundamental factors you need to consider when designing the service layer for your application. Use these guidelines as a starting point toward understanding the key concerns, such as when to use business entities, how to design your service interface, how to choose a Web service technology, and how to think about Representational State Transfer (REST) and SOAP.


• How to design a service(如何设计服务)


When designing services, you must consider the availability and stability of the service(设计服务时,必须考虑可用性与稳定性), and ensure that it is configurable and can be aggregated so that it can accommodate changes to the business requirements(还要确保它是可配置的和可被聚合的,这样能够适应业务需求的改变). In most cases, you want to design services that are autonomous, provide explicit boundaries, do not expose internal classes, and use policy to define interaction requirements(大多数情况下,希望服务是自治的,提供明确的边界,不要暴露内部类并使用策略来定义交互需求). You should also design for idempotency so that the service can manage messages that arrive more than once; design for commutativity so that the service can handle messages that arrive in the wrong order; and design for invalid requests by validating them against a schema or known format(要设计idempotency这样服务可以对到达的消息进行多次处理,要做可换性设计,这样服务能处理没有按照次序达到的消息;做非法请求的处理,通过对已知格式的架构进行验证). Consider using standard elements to compose the complex types used by your service(考虑使用标准元素来组成服务中的复杂类型).


For more information, see Chapter 13, “Service Layer Guidelines.”


• How to expose your application as a service(如何将永远作为服务公开)


The approach you take to exposing an application as a service depends on where you are in the development life cycle of the application. If you already have an application and want to expose operations as services, you should identify the necessary operations and then define interface contracts that combine operations in order to produce application-scoped procedures(如果你已经有一个原因,并想要将操作公开为服务,你应该识别必要的操作然后为了产生应用程序范围内的操作 定义组合操作的接口协定). The main thing you do not want to do is expose component- or object-based operations as service operations(你不想做的事情主要是 公开基于组件或者对象的操作为服务操作). When starting from scratch, you should first define the service interface contracts that an application needs to support(从头开始时,你应该首先定义应用需要支持的服务接口协定). The main goal is to provide coarse-grained interface contracts that support business-process or client requirements without focusing on the implementation (主要目标是提供粗粒度的接口协定,这些协定不需要专注于具体实现,就可以支持业务处理或者客户需求). Once you have defined the contracts, you can then focus on how to implement code that supports the contracts.(一旦你定义了这些协定,然后你就可以专注于如何去实现支持他们的代码了)


For more information, see Chapter 13, “Service Layer Guidelines.”


• How to choose between ASP.NET Web services and WCF services for services(如何在Asp.net Web服务与WCF服务之间作出选择)


ASP.NET Web services are a good choice for simple HTTP-based services hosted in Internet Information Services (IIS)(ASP.net Web服务对于基于HTTP,以IIS为载体的服务是一个好的选择). WCF is a good choice if you need the performance of Transmission Control Protocol (TCP) communication over HTTP(如果你需要在HTTP上获得更好的TCP传输性能), or if you need to host the service without a Web server(或者你需要不用Web服务器承载这个服务,那么WCF会更好). WCF provides support for the WS* specification, which includes support for end-to-end security and reliable  communication(WCF提供对于WS*规格的支持,其中包含端到端的安全支持和可靠通信支持). WCF allows you to implement duplex communication(WCF允许实现全双工通信), and you can also use it with Windows Message Queuing and as a Windows service(你还可以与Windows消息队列一起使用WCF,还可以将WCF作为一个Windows服务). In addition, you have more options with regard to protocols, bindings, and formats(另外,关于协议、绑定和格式,你还有更多的选择). Keep in mind that WCF requires the .NET Framework 3.0 or higher(但是要记住,WCF需要.net Framework3.0或更高).


For more information, see Chapter 13, “Service Layer Guidelines.”


• How to choose between REST and SOAP(如何选择REST还是SOAP)


Representational State Transfer (REST) (表象化状态转变)and SOAP represent two different styles for implementing services(REST与SOAP代表了两种实现服务的方式). REST uses HTTP, which means that it works very much like a Web application(REST使用HTTP协议,这就意味着它非常像一个Web应用), while SOAP is an XML-based messaging protocol that can be used with any communication protocol(而SOAP是基于XML的,这样它就可以与所有的通信协议一起使用). Although both REST and SOAP can be used with most service implementations, the REST architectural style is better suited for public services or cases where a service can be accessed by unknown consumers(虽然REST与SOAP都可以用来实现大多数的服务,但是REST结构更适合公共服务和那些能被不明消费者访问的情况). SOAP is better suited for implementing a loosely coupled Remote Procedure Call (RPC) interface between layers of an application(SOAP更适合在应用程序的层此之间实现松耦合的远程过程调用RPC结构). With SOAP, you are not restricted to HTTP, and it provides the underlying framework for more advanced Web Service standards, such as the ability to enlist in transactions(使用SOAP,并不局限与HTTP协议,它为更多的先进Web服务标准提供了下层框架,例如ability to enlist in transactions).


For more information, see Chapter 13, “Service Layer Guidelines.”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值