ITPub博客

首页 > 应用开发 > IT综合 > WCF Essentials (3)

WCF Essentials (3)

原创 IT综合 作者:yuzhangqi 时间:2010-05-28 11:51:30 0 删除 编辑

8. Bindings

There are multiple aspects of communication with any given service, and there are many possible communication patterns: messages can be synchronous request/reply or asynchronous fire-and-forget; messages can be bidirectional; messages can be delivered immediately or queued; and the queues can be durable or volatile. There are many possible transport protocols for the messages, such as HTTP (or HTTPS), TCP, P2P (peer network), IPC (named pipes), or MSMQ. There are a few possible message encoding options: you can chose plain text to enable interoperability, binary encoding to optimize performance, or MTOM (Message Transport Optimization Mechanism) for large payloads. There are a few options for securing messages: you can choose not to secure them at all, to provide transport-level security only, to provide message-level privacy and security, and of course there are numerous ways for authenticating and authorizing the clients. Message delivery might be unreliable or reliable end-to-end across intermediaries and dropped connections, and the messages might be processed in the order they were sent or in the order they were received. Your service might need to interoperate with other services or clients that are only aware of the basic web service protocol, or they may be capable of using the score of WS-* modern protocols such as WS-Security and WS-Atomic Transactions. Your service may need to interoperate with legacy clients over raw MSMQ messages, or you may want to restrict your service to interoperate only with another WCF service or client.

To simplify these choices and make them more manageable, WCF groups together a set of such communication aspects in bindings. A binding is merely a consistent, canned set of choices regarding the transport protocol, message encoding, communication pattern, reliability, security, transaction propagation, and interoperability. Ideally, you would extract all these "plumbing" aspects out of your service code and allow the service to focus solely on the implementation of the business logic. Binding enables you to use the same service logic over drastically different plumbing.

The Standard Bindings

Basic bindingOffered by the BasicHttpBinding class
TCP bindingOffered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet.
Peer network bindingOffered by the NetPeerTcpBinding class, this uses peer networking as a transport.
IPC bindingOffered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication.
Web Service (WS) bindingOffered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.
Federated WS bindingOffered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.
Duplex WS bindingOffered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client
MSMQ bindingOffered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.
MSMQ integration bindingOffered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.

Format and Encoding

Transport and encoding for standard bindings (default encoding is in bold)

Name

Transport

Encoding

Interoperable

BasicHttpBinding

HTTP/HTTPS

Text, MTOM

Yes

NetTcpBinding

TCP

Binary

No

NetPeerTcpBinding

P2P

Binary

No

NetNamedPipeBinding

IPC

Binary

No

WSHttpBinding

HTTP/HTTPS

Text, MTOM

Yes

WSFederationHttpBinding

HTTP/HTTPS

Text, MTOM

Yes

WSDualHttpBinding

HTTP

Text, MTOM

Yes

NetMsmqBinding

MSMQ

Binary

No

MsmqIntegrationBinding

MSMQ

Binary

Yes


Having a text-based encoding enables a WCF service (or client) to communicate over HTTP with any other service (or client) regardless of its technology. Binary encoding over TCP or IPC yields the best performance but at the expense of interoperability, by mandating WCF-to-WCF communication.

Choosing a Binding

Choosing a binding for your service should follow the decision-activity diagram shown below.

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13651903/viewspace-1033989/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: WCF Essentials (2)
下一篇: WCF Essentials (4)
请登录后发表评论 登录
全部评论

注册时间:2008-06-10

  • 博文量
    102
  • 访问量
    763305