In this chapter, we will cover:
- Configuring Default Endpoints
- Setting up two-way communication over MSMQ
- Building a Publish-Subscribe service with dual binding
- Creating a multiple-endpoint service
- Implementing a POX HTTP service
- Defining a
CustomBinding
without a timestamp header - Suppressing
mustUnderstand
validation on unknown SoapHeaders - Sharing a physical address between multiple endpoints
WCF services are exposed through service endpoints, which provide the basic access point for client to utilize the functionality offered by a given WCF service. Service endpoints consist of ABC and a set of behaviors. What is ABC? Well, A stands for Address, which tells service consumers “Where is the service?”, B stands for Binding, which describes “How to talk to the service?” and C stands for Contract, which shows “What functionality can the service provide?”
WCF provides plenty of built-in bindings (such as BasicHttpBinding, NetTcpBinding, NetMsmqBinding, and so on), which can help developers host service endpoints over various transport protocols. Behaviors also play an important role in WCF. By using behaviors, we can gain further manipulation over the WCF service at service or endpoint level.
This chapter provides eight recipes on using the built-in binding and behaviors to build various service endpoints, which represent some of the useful scenarios in general WCF service development. We will start from the Default Endpoint feature introduced in WCF 4.0. Then, we will use two built-in bindings (NetMsmqBinding and WSDualHttpBinding) to demonstrate how to build a two-way communication and build a Publish-Subscribe pattern service through system bindings. The fourth recipe shows how WCF allows a single service to expose multiple endpoints layered on heterogeneous transport and message settings. The fifth recipe demonstrates how to build a POX-style WCF service that can talk with the application, which only supports plain XML-based message communication. The last three recipes come from some common and tricky scenarios in service endpoint customization. The sixth recipe shows how to disable the replay detection and remove a timestamp header in a WCF-generated SOAP message, the seventh recipe demonstrates how to make a WCF service/client tolerant to anonymous SoapHeaders, and the final recipe provides an example of how to make multiple WCF endpoints share a single transport address.