Although WCF is a fairly complex platform, it seems fairly straightforward for a casual learner. As you can see in the Hello WC example, building an acceptance program simplifies the configuration of one or more endpoints using addresses, bindings, and leases. Building a sender can be simply understood to send a message to the receiving endpoint using an address, binding, and contract. If we want to modify the process of the sender or receiver, we can do it casually, using our own behavior configuration or using WCF's own behavior (such as increasing metadata support). Figure 4-1 shows the relationship between endpoints, addresses, bindings, contracts, and behaviors.
Figure 4-1:endpoints, addresses, bindings, contracts and behaviors
Address
All programs that send or receive messages must use an address on the endpoint. For example, the receiving program listens for a request message on an address, and the dispatcher sends a message to the destination address. The WCF receive infrastructure relies on the System.Uri type to build the receive endpoint. WCF sends the infrastructure, in other words, relies on the System.ServiceModel.EndpointAddress type to send messages to the final recipient. The System.ServiceModel.EndpointAddress type is the CLR abstraction of the Endpoint reference specification in Ws-addressing, which is used by the sender to add endpoint information to the request message and to receive The endpoint establishes a connection (if there is a receive endpoint) Chapter 5th contains a detailed description of the EndpointAddress type.
In WCF, the address is in some form a URI (the EndpointAddress object wraps a System.Uri object). A key part is the scheme name in the URI. Scheme is an abstraction of the identifier represented by a URI, and the scheme name is a way of identifying scheme. In many cases, the scheme name matches the protocol that can locate the resource, so the URI is used as the URL. For example, the URI Http://localhost:5000/IHelloWCF identifies HTTP as the scheme name, and so incidentally HTTP (Hypertext Transfer Protocol) is also a transport mode. Internally, the WCF infrastructure must be able to use urinate to build the send or receive infrastructure.
Binding
Binding is the primary way we represent how message applications handle, send, and receive messages. Rather, it represents the primary means of transmission, ws-* protocol, security requirements, transaction requirements, and endpoints. WCF contains 9 kinds of bindings for covering transports, ws-* protocols, security requirements, transaction requirements. If these bindings do not meet our needs, we can also define bindings that meet our specific needs.
Typically, a binding is a type that defines a message infrastructure; it is an abstraction layer of our program's support for transport and protocols. For developers, this abstraction means that the code that sends messages over TCP/IP looks very similar to the code that sends messages through MSMQ, so that our programs are decoupled from specific transmissions or protocols. Loose coupling in this way means that developers can develop, change, and customize an application to meet customer requirements faster than ever before.
All binding types are System.ServiceModel.Channels.Binding subtypes, so they all have the same properties. A common attribute is the list of their maintainers as a private System.ServiceModel.Channels.BindingElement object. A bindingelement is the abstraction of a particular aspect of message exchange, such as a transmission or a ws-* protocol. All bindings expose a method named Createbindingelements that can build and return a list of specific binding elements. Here's a simple program that contains 9 kinds of bindings in WCF and iterates through their bindingelement lists:
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Reflection;
using System.Collections.Generic;
using System.ServiceModel.MsmqIntegration;
Sealed class bindingelementsshow
{
static void Main () {
List<binding> bindings = new Lis T<binding> ();
Bindings. ADD (New BasicHttpBinding ());
Bindings. ADD (New netnamedpipebinding ());
Bindings. ADD (New NetTcpBinding ());
Bindings. ADD (New wsdualhttpbinding ());
Bindings. ADD (New Wshttpbinding ());
Bindings. ADD (New NetMsmqBinding ());
Bindings. ADD (New msmqintegrationbinding ());
Bindings. ADD (New wsfederationhttpbinding ());
//throws if Peer networking not installed
bindings. ADD (New NetPeerTcpBinding ());
Showbindingelements (bindings);
}
private static void Showbindingelements (List<binding> bindings) {
foreach (Binding binDing in bindings) {
Console.WriteLine (' Showing Binding Elements for {0} ',
Binding. GetType (). Name);
foreach (bindingelement element in binding. Createbindingelements ()) {
Console.WriteLine ("\t{0}", element. GetType (). Name);
}
}
}
}