- Platform for building distributed, service-oriented applications
- Define services and hosts for those services
- Define clients to connect to services
- Secure, Scalable, robust, and flexible
- SOAP messaging
- WCF Configuration
- Endpoints:
- Address
- Binding
- Contract
- Behaviors
- Bindings
- Endpoints:
- WCF allows you to easily connect clients and services for remote communications.
- The service boundary is defined through a combination of the service contract, data contracts, and configuration.
- Behaviors configure aspects about how the service behaves when service messages are received
- Bindings configure aspects about how the service behaves when sevice messages are received
- Binding configure aspects of the communication pipe shared with the client
- Create a WCF Service Library project
- Define Service Contract
- Define Data Contracts for operation parameters and return types
- Define the Service implementation class
- Service implementation class can use ServiceBehavior annotation to drive aspects of its behavior when called as a service.
- Service instance lifetime:
- Per call (favored)
- Per session (default)
- Singleton
- Services need to run in a host process
- The host listens for incoming messages and dispatches calls to the appropriate service method
- How the service is exposed by the host is driven through configuration
- Hosting Options:
- Self Host:
- Any .NET process
- User ServiceHost class
- IIS Host:
- can only handle HTTP traffic
- When using IIS hosting, there is no need to specify address in endpoint
- WCF Service Library
- OK for quick "smoke testing"
- Generally want to debug and develop with a self host or IIS host
- Self Host:
- To consume WCF services from .NET clients, you need a client proxy
- Proxies can be code generated by Visual Studio based on metadata exposed by the service
- Service must enable metadata either through WSDL or WS-MetadataExchange endpoint
- Proxies can also be hand-coded for more control over the code in the proxy
- Encapsulate repeating patterns of usage, leverage WCF extensibility features
- Make calls through proxy instance methods
- Opens connection to the service
- Dispatches the call through SOAP messages
- Gets a response message back - completes method
- Add Service Reference makes implementing a client proxy simple
- Generated proxies have both synchronous and asynchronous methods
- Generated client configuration may need to be tweaked to work with service
- Manually implemented proxies may make sense to have more control over the proxy implementation
- Service calls should be secured
- Authentication & Authorization