The System.ServiceModel.Channels namespace provides a means by which developers determine how their service will communicate. The System.ServiceModel namespace, discussed previously, provides the developer a way to define and model the service from the communication aspect.
The following table lists some of the more commonly used classes used to define the communication of your service.
Class | Description |
---|---|
AddressHeader | A header that contains address information used to identify and communicate with an endpoint |
AddressHeaderCollection | A collection of address headers |
Binding | A collection of binding elements, each binding defining how an endpoint will communicate with the outside world |
BindingContext | Provides address and binding information needed to build channel factories and channel listeners |
CustomBinding | Used to define and build a custom binding from a set of binding elements |
Message | A unit of communication between endpoints |
MessageHeader | The content of a message SOAP header |
MessageHeaders | A collection of message headers |
Obviously if you were to look at the list of classes in the System.ServiceModel.Channels namespace you would see close to 10 times the number of classes than those listed here. The point of this list is to provide a base for you to start with and build from, and to point out those classes that might be most beneficial to you as you begin modeling your service.
For example, the following code snippet illustrates a number of the classes listed in both the System.ServiceModel and System.ServiceModel.Channels namespaces:
class TestWCFApp { static void Main() { Uri baseAddress = new Uri(ConfigurationManager.AppSettings["address"]); AddressHeader ah = AddressHeader.CreateAddressHeader(“service1”, "http://localhost:8080/service"); EndpointAddress ea = new EndpointAddress(new Uri("http://localhost:8081/testservice/service"), ah); ServiceEndpoint se = new ServiceEndpoint(ContractDescription.GetContract(typeof (BookOrderService)), new WSHttpBinding), ea); ServiceHost sh = new ServiceHost(typeof (BookOrderService), baseAddress); sh.Description.Endpoints.Add(se); sh.Open(); sh.close(); } }
In this small example, the AddressHeader class is used to define an address header for the endpoint. The endpoint is then defined using the address header. A service endpoint is then defined, followed by the defining of a service host, which is used to provide a host for the service being created. The endpoint description is then set, and finally the service host is opened, which creates listeners and starts listening for messages.