Professional WCF 4: Windows Communication Foundation with .NET 4

Book description

A guide to architecting, designing, and building distributed applications with Windows Communication Foundation

Windows Communication Foundation is the .NET technology that is used to build service-oriented applications, exchange messages in various communication scenarios, and run workflows. This guide enables developers to create state-of-the-art applications using this technology.

Written by a team of Microsoft MVPs and WCF experts, this book explains how the pieces of WCF 4.0 build on each other to provide a comprehensive framework to support distributed enterprise applications. Experienced developers will learn both theory and practical application using the familiar Wrox approach.

.NET developers will learn to design services, create a hosting environment with Dublin, build cloud-based integrations, and much more.

Coverage Includes:

  • Design Principles and Patterns

  • Service Contracts and Data Contracts

  • Bindings

  • Clients

  • Instancing

  • Workflow Services

  • Understanding WCF Security

  • WCF Security in Action

  • Federated Authentication in WCF

  • Windows Azure Platform AppFabric

  • Creating a SOA Case

  • Creating the Communication and Integration Case

  • Creating the Business Process

  • Hosting

  • Table of contents

    1. Copyright
    2. ABOUT THE AUTHORS
    3. CREDITS
    4. ACKNOWLEDGMENTS
    5. INTRODUCTION
      1. WHO THIS BOOK IS FOR
      2. WHAT THIS BOOK COVERS
      3. HOW THIS BOOK IS STRUCTURED
      4. WHAT YOU NEED TO USE THIS BOOK
      5. CONVENTIONS
      6. SOURCE CODE
      7. ERRATA
      8. P2P.WROX.COM
    6. 1. Design Principles and Patterns
      1. 1.1. WHAT IS SOA?
      2. 1.2. FOUR TENETS OF SOA
        1. 1.2.1. Boundaries Are Explicit
        2. 1.2.2. Services Are Autonomous
        3. 1.2.3. Services Share Schema and Contract, Not Class
        4. 1.2.4. Service Compatibility Is Based On Policy
      3. 1.3. ANATOMY OF A SERVICE
        1. 1.3.1. Service Ecosystem
          1. 1.3.1.1. Applications Are Composed of Services
          2. 1.3.1.2. Services Manage State
          3. 1.3.1.3. Services Enforce Policies
          4. 1.3.1.4. Policies Enforce Operational Requirements
          5. 1.3.1.5. Services Are Bound by Contracts
          6. 1.3.1.6. Contracts Describe Message Exchange Patterns
          7. 1.3.1.7. Contracts Contain Schemas and Schemas Define Message Structure
          8. 1.3.1.8. A Message Exchange Pattern Is a Set of Messages
          9. 1.3.1.9. Services Exchange Messages
      4. 1.4. ORCHESTRATING SERVICES IN BUSINESS PROCESSES
      5. 1.5. TECHNOLOGIES BEHIND SOA
        1. 1.5.1. SOAP
        2. 1.5.2. WS-* Protocols
        3. 1.5.3. WSDL
      6. 1.6. CONTRACT-FIRST PRINCIPLE
      7. 1.7. HOW WCF AND .NET SERVICES IMPLEMENT SOA PATTERNS
        1. 1.7.1. Patterns
        2. 1.7.2. Decoupled Contract: Interface vs. Implementation
        3. 1.7.3. Proxy Pattern
        4. 1.7.4. OperationContext Pattern
        5. 1.7.5. Concurrent Contracts
        6. 1.7.6. Data Confidentiality
        7. 1.7.7. Atomic Service Transactions
        8. 1.7.8. Session Facade
        9. 1.7.9. Exception Shielding
      8. 1.8. COMMUNICATION AND INTEGRATION PATTERNS
        1. 1.8.1. Integration Styles
          1. 1.8.1.1. Import/Export Files
          2. 1.8.1.2. Shared Database
          3. 1.8.1.3. Remote Procedure Calls
          4. 1.8.1.4. Message Bus
        2. 1.8.2. Message Exchange Patterns
          1. 1.8.2.1. Request-Response
          2. 1.8.2.2. One-Way
          3. 1.8.2.3. Duplex Messaging
          4. 1.8.2.4. Streaming
          5. 1.8.2.5. Pub-Sub
          6. 1.8.2.6. Implied Order Invocation
        3. 1.8.3. Messaging Patterns
          1. 1.8.3.1. WCF Runtime Architecture
          2. 1.8.3.2. Content Enricher
          3. 1.8.3.3. Message Routing
          4. 1.8.3.4. Protocol Bridging
          5. 1.8.3.5. Message Filters
          6. 1.8.3.6. Backup Endpoint
          7. 1.8.3.7. Multicast Behavior
          8. 1.8.3.8. Discovery
          9. 1.8.3.9. Intercepting Filters
          10. 1.8.3.10. Context Objects
      9. 1.9. BUSINESS PROCESS PATTERNS
        1. 1.9.1. Process Manager
          1. 1.9.1.1. Start-Listen-Action Pattern
        2. 1.9.2. Patterns in Workflows Declaration
          1. 1.9.2.1. Sequence
          2. 1.9.2.2. Parallel Split
          3. 1.9.2.3. Synchronization
          4. 1.9.2.4. Listen Pattern
          5. 1.9.2.5. Listen for Incoming Messages during a Predefined Time
          6. 1.9.2.6. Convoy Patterns
            1. 1.9.2.6.1. Sequential Convoy
            2. 1.9.2.6.2. Parallel Convoy
    7. 2. Service Contracts and Data Contracts
      1. 2.1. SERVICE CONTRACTS
      2. 2.2. DATA CONTRACTS
      3. 2.3. MESSAGE CONTRACTS
      4. 2.4. CONTRACTS AND CODE
      5. 2.5. CAR RENTAL SERVICE — IMPLEMENTATION EXAMPLE
        1. 2.5.1. Step 1: Service Contract Definition
        2. 2.5.2. Step 2: Extract the Service Metadata
        3. 2.5.3. Step 3: Service Implementation
        4. 2.5.4. Step 4: The Client
        5. 2.5.5. [ServiceContract] and [OperationContract]
      6. 2.6. DATA CONTRACTS
        1. 2.6.1. Data Contract in Detail
        2. 2.6.2. KnownTypes
      7. 2.7. SERVICE AND DATA CONTRACT VERSIONING
        1. 2.7.1. Data Contract Versioning
        2. 2.7.2. Round-Trip Versioning
          1. 2.7.2.1. IExtensibleDataObject
        3. 2.7.3. Best Practices of Service Contract Versioning
        4. 2.7.4. Best Practices of Data Contract Versioning
      8. 2.8. MESSAGE CONTRACTS
        1. 2.8.1. XML Serialization
    8. 3. Bindings
      1. 3.1. HOW THE BINDINGS WORK
      2. 3.2. ADDRESSES
        1. 3.2.1. Transport Protocols
      3. 3.3. BEHAVIORS
        1. 3.3.1. Service Behaviors
        2. 3.3.2. Operation Behaviors
        3. 3.3.3. Endpoint Behaviors
        4. 3.3.4. Contract Behaviors
      4. 3.4. THE BINDINGS
        1. 3.4.1. BasicHttpBinding and WSHttpBinding
        2. 3.4.2. NetTcpBinding
        3. 3.4.3. NetMsmqBinding
        4. 3.4.4. Context-Enabled Bindings
        5. 3.4.5. So Many Bindings to Choose From
      5. 3.5. CONFIGURING BINDINGS
        1. 3.5.1. Base Addresses
        2. 3.5.2. Default Configurations
          1. 3.5.2.1. Automatic Endpoints
          2. 3.5.2.2. Default Bindings
          3. 3.5.2.3. Default Behaviors
          4. 3.5.2.4. Standard Endpoints
        3. 3.5.3. Setting Multiple Bindings
      6. 3.6. MODIFYING BINDINGS
        1. 3.6.1. Bindings Properties
        2. 3.6.2. Creating Custom Bindings
          1. 3.6.2.1. Binding Elements
        3. 3.6.3. A Reusable Custom Binding
      7. 3.7. DUPLEX DURABLE SERVICES
        1. 3.7.1. Configuring the Bindings for Duplex Durable Services
      8. 3.8. POLLINGDUPLEXHTTPBINDING: HTTP POLLING
        1. 3.8.1. NetTcpBinding in Silverlight 4
    9. 4. Clients
      1. 4.1. BASIC PROFILE 1.1
      2. 4.2. .NET CLIENTS
        1. 4.2.1. Sharing WSDL-Contracts
        2. 4.2.2. Sharing WSDL-Contracts and DataContract-DLLs
        3. 4.2.3. Sharing Interfaces and DataContract-DLLs
      3. 4.3. REST
        1. 4.3.1. REST and WCF
        2. 4.3.2. Working with REST Clients
        3. 4.3.3. Using the REST Starter Kit
      4. 4.4. AJAX AND WCF
      5. 4.5. WCF 4.0 AND SILVERLIGHT
    10. 5. Instancing
      1. 5.1. INSTANCECONTEXTMODE
        1. 5.1.1. PerCall
        2. 5.1.2. Singleton
        3. 5.1.3. PerSession
      2. 5.2. SERVICE LIFE
        1. 5.2.1. SessionId
      3. 5.3. PERFORMANCE
        1. 5.3.1. Throttling
        2. 5.3.2. Best Practices
        3. 5.3.3. Load Balancing
    11. 6. Workflow Services
      1. 6.1. ANATOMY OF A WORKFLOW SERVICE
      2. 6.2. DECLARATIVE SERVICES
      3. 6.3. SEND AND RECEIVE ACTIVITIES
        1. 6.3.1. Receive Activity
        2. 6.3.2. Send Activity
          1. 6.3.2.1. The Easy Way to Execute External Services
        3. 6.3.3. SendAndReceiveReply and ReceiveAndSendReply Activities
      4. 6.4. IMPLEMENTING YOUR FIRST WORKFLOW SERVICE
      5. 6.5. CONFIGURING A WORKFLOW SERVICE
        1. 6.5.1. WF Runtime Settings
          1. 6.5.1.1. WorkflowIdle Service Behavior
          2. 6.5.1.2. SqlWorkflowInstanceStore Service Behavior
          3. 6.5.1.3. WorkflowUnhandledException Service Behavior
          4. 6.5.1.4. WorkflowRuntime Service Behavior
      6. 6.6. IMPLEMENTING MESSAGE CORRELATION
        1. 6.6.1. Correlation in Action
          1. 6.6.1.1. Context-Based Correlation
            1. 6.6.1.1.1. Step 1: Implementing the Workflow Service
            2. 6.6.1.1.2. Step 2: Configuring the Workflow Service
            3. 6.6.1.1.3. Step 3: Implementing the Client Application
            4. 6.6.1.1.4. Step 4: Configuring the Client Application
          2. 6.6.1.2. Content-Based Correlation
            1. 6.6.1.2.1. Step 1: Implementing the Workflow Service
            2. 6.6.1.2.2. Step 2: Configuring the Workflow Service
            3. 6.6.1.2.3. Step 3: Implementing the Client Application
      7. 6.7. HOSTING THE WORKFLOW SERVICES
    12. 7. Understanding WCF Security
      1. 7.1. THE EVOLUTION OF SECURITY IN WEB SERVICES
      2. 7.2. MAIN PRINCIPLES IN WEB SERVICE SECURITY
        1. 7.2.1. Authentication
        2. 7.2.2. Authorization
        3. 7.2.3. Message Integrity
        4. 7.2.4. Message Confidentiality
      3. 7.3. TRANSPORT SECURITY AND MESSAGE SECURITY
        1. 7.3.1. Transport Security
        2. 7.3.2. Message Security
      4. 7.4. WCF SECURITY OVERVIEW
        1. 7.4.1. Configuring Security in WCF
          1. 7.4.1.1. Security Mode
          2. 7.4.1.2. Protection Level
          3. 7.4.1.3. Algorithm Suite
          4. 7.4.1.4. Client Credential Type
          5. 7.4.1.5. Service Credentials Authentication and Negotiation
          6. 7.4.1.6. Secure Sessions
    13. 8. WCF Security in Action
      1. 8.1. FIRST STEPS IN AUTHENTICATION
        1. 8.1.1. Claims-Based Identity Model
        2. 8.1.2. Authentication in Action
          1. 8.1.2.1. Username Authentication Over Message Security
            1. 8.1.2.1.1. Step 1: Create the Service Implementation
            2. 8.1.2.1.2. Step 2: Configure the Service with WsHttpBinding, Username Authentication, and Message Security
            3. 8.1.2.1.3. Step 3: Implement the Client Application
            4. 8.1.2.1.4. Step 4: Configure the Client with WsHttpBinding, Message Security, and Username Authentication
          2. 8.1.2.2. Variant 1: Using a Custom Membership Provider as the Identity Store
            1. 8.1.2.2.1. Step 1: Implement a Custom ASP.NET Membership Provider
            2. 8.1.2.2.2. Step 2: Configure the Service to Use the Custom Membership Provider
          3. 8.1.2.3. Variant 2: Using a Custom UserNamePasswordValidator Implementation
            1. 8.1.2.3.1. Step 1: Implement a Custom UserNamePasswordValidator
            2. 8.1.2.3.2. Step 2: Configure the Service to Use the Custom UserNamePasswordValidator
          4. 8.1.2.4. Username Authentication Over Transport Security
            1. 8.1.2.4.1. Step 1: Configure a Virtual Directory in IIS for SSL
            2. 8.1.2.4.2. Step 2: Create a Virtual Directory in IIS Configured with Basic Authentication
            3. 8.1.2.4.3. Step 3: Configure the Service with WsHttpBinding, Basic Authentication, and Transport Security
            4. 8.1.2.4.4. Step 4: Configure the Client with WsHttpBinding, Transport Security, and Basic Authentication
          5. 8.1.2.5. Mutual X509 Certificate Authentication Over Message Security
            1. 8.1.2.5.1. Step 1: Create the Service Implementation
            2. 8.1.2.5.2. Step 2: Configure the Service with WsHttpBinding, Certificate Authentication, and Message Security
            3. 8.1.2.5.3. Step 3: Implement the Custom X509CertificateValidator
            4. 8.1.2.5.4. Step 4: Implement the Client Application
            5. 8.1.2.5.5. Step 5: Configure the Client with WsHttpBinding, Message Security, and Certificate Authentication
          6. 8.1.2.6. Kerberos Authentication Over Message Security
            1. 8.1.2.6.1. Step 1: Create the Service Implementation
            2. 8.1.2.6.2. Step 2: Configure the Service with WsHttpBinding, Windows Authentication, and Message Security
            3. 8.1.2.6.3. Step 3: Implement the Client Application
            4. 8.1.2.6.4. Step 4: Configure the Client with WsHttpBinding, Message Security, and Windows Authentication
        3. 8.1.3. Claims Transformation and Security Context Initialization
        4. 8.1.4. Service Authorization
          1. 8.1.4.1. Role-Based Authorization
            1. 8.1.4.1.1. Using an ASP.NET Role Provider
            2. 8.1.4.1.2. Using a Custom Principal
          2. 8.1.4.2. Claim-Based Authorization and the Authorization Context
          3. 8.1.4.3. Authorization Managers
    14. 9. Federated Authentication in WCF
      1. 9.1. FEDERATED AUTHENTICATION
        1. 9.1.1. What Is a Security Token Service (STS)?
        2. 9.1.2. Federation Authentication Between Multiple Domains
        3. 9.1.3. Security Assertions Markup Language (SAML)
      2. 9.2. WINDOWS IDENTITY FOUNDATION (WIF)
        1. 9.2.1. Claims-Based Model in WIF
          1. 9.2.1.1. The New IClaimsIdentity and IClaimsPrincipal Interfaces
          2. 9.2.1.2. Building an Active STS
          3. 9.2.1.3. Security Token Handlers
          4. 9.2.1.4. Configuring Federated Authentication in WCF
    15. 10. Windows Azure Platform AppFabric
      1. 10.1. GETTING STARTED WITH THE SERVICE BUSAND ACCESS CONTROL
      2. 10.2. PLAYING WITH THE SERVICE BUS
        1. 10.2.1. Creating Your First Service Bus Application
      3. 10.3. THE RELAY SERVICE
      4. 10.4. WCF RELAY BINDINGS
        1. 10.4.1. NetOneWayRelayBinding
        2. 10.4.2. NetEventRelayBinding
        3. 10.4.3. NetTcpRelayBinding
        4. 10.4.4. Http Relay Bindings
      5. 10.5. PLAYING WITH THE ACCESS CONTROL SERVICE (ACS)
        1. 10.5.1. Service Namespaces
        2. 10.5.2. Scopes
        3. 10.5.3. Issuers
        4. 10.5.4. Rules
        5. 10.5.5. Integrating Your First Service with Access Control
    16. 11. Creating a SOA Case
      1. 11.1. THE REQUIREMENTS FOR THE CASE
        1. 11.1.1. Additional Requirements
      2. 11.2. SETTING UP THE SOLUTION
      3. 11.3. CREATING THE INTERFACES
        1. 11.3.1. Creating the CarManagement Interface
        2. 11.3.2. Creating the Customer Interface
        3. 11.3.3. Creating the Rental Interface
        4. 11.3.4. Creating the External Interface
      4. 11.4. CREATING THE SERVICES
      5. 11.5. CREATING THE HOST
      6. 11.6. CREATING THE DATABASE
      7. 11.7. IMPLEMENTING THE SERVICE
        1. 11.7.1. Creating Database Access for the CustomerService and the RentalService
        2. 11.7.2. Creating the CarManagement Service
      8. 11.8. EXPOSING METADATA
      9. 11.9. CREATING THE CARMANAGEMENT CLIENT
      10. 11.10. CREATING THE RENTALAPPLICATION
      11. 11.11. ADDING CORRECT ERROR HANDLING
      12. 11.12. IMPERSONATING THE CLIENT
      13. 11.13. EXTENDING THE CARMANAGEMENT INTERFACE TO ACCEPT THE SUBTYPES OF CARS
      14. 11.14. IMPLEMENTING THE EXTERNALINTERFACEFACADE
        1. 11.14.1. Using the ExternalInterfaceFacade
        2. 11.14.2. Setting Transaction Support at the Methods Participating in the Transaction
        3. 11.14.3. Configuring Additional Endpoints for the servicehost
    17. 12. Creating the Communication and Integration Case
      1. 12.1. DEFINING THE REQUIREMENTS
      2. 12.2. SETTING UP THE SOLUTION
      3. 12.3. CREATING THE HQORDERENTRYINTERFACE
      4. 12.4. CREATING THE HELPERLIB
      5. 12.5. CREATING THE ORDERENTRYIMPLEMENTATION
      6. 12.6. CREATING THE HQORDERENTRYSERVICEHOST
      7. 12.7. CREATING THE ORDERENTRYAPPLICATION
      8. 12.8. CREATING THE LOCALORDERENTRYINTERFACE
      9. 12.9. CONTINUING THE ORDERENTRYIMPLEMENTATION
      10. 12.10. CREATING THE HQPRODUCTSERVICEASMX
        1. 12.10.1. Creating the Web Service
        2. 12.10.2. Adding the HQProductServiceASMX as Service Reference to the OrderEntryServiceImplementation
        3. 12.10.3. Coding the CheckIfOrderIsValid Method
        4. 12.10.4. Coding the TranslateProductDescription Method
        5. 12.10.5. Coding the ConvertOrderEntrySchema Method
      11. 12.11. CREATING THE HQLOCALIZATIONSERVICE
      12. 12.12. CODING THE ROUTERORDERENTRY METHOD
      13. 12.13. CREATING THE REALTIMEORDERTRACKINGAPPLICATION
        1. 12.13.1. Coding the RealTimeOrderTrackingApplication Method
        2. 12.13.2. Adding the ISubscribeToOrderTrackingInfo Interface
        3. 12.13.3. Implementing the SubscribeService Method
        4. 12.13.4. Calling the Subscribers When the Order Is Processed
        5. 12.13.5. Opening the SubscribeService
        6. 12.13.6. Subscribing from the RealTimeOrderTrackingApplication
        7. 12.13.7. Configuring the HQOrderEntryServiceHost
      14. 12.14. CREATING THE ROUTER
      15. 12.15. CONFIGURING THE HQORDERENTRYSERVICEHOST
    18. 13. Creating the Business Process
      1. 13.1. DEFINING THE REQUIREMENTS
      2. 13.2. SETTING UP THE SOLUTION
      3. 13.3. CREATING THE DATA CONTRACTS
      4. 13.4. CREATING THE CALCULATEREFERENCEIDSERVICE
      5. 13.5. CREATING THE RECEIVEAPPROVEDHOLIDAYREQUESTSSERVICE
      6. 13.6. ADDING SERVICE REFERENCES TO THE HOLIDAYREQUESTACTIVITYLIBRARY PROJECT
        1. 13.6.1. Adding the CalculateReferenceIDService
        2. 13.6.2. Adding the ReceiveApprovedHolidayRequestsService
        3. 13.6.3. Developing the HolidayRequestProcess
        4. 13.6.4. Adding the Workflow
        5. 13.6.5. Creating Variables
        6. 13.6.6. Configuring the Receive Activity
        7. 13.6.7. Configuring the Send Activity
        8. 13.6.8. Configuring the ApproveRequest ReceiveAndSendReply Activity
      7. 13.7. DEVELOPING THE HOLIDAYREQUESTHOST
      8. 13.8. TESTING TO SEE IF THIS SERVICE HOST EXPOSES THE METADATA CORRECTLY
      9. 13.9. DEVELOPING THE MANAGERSHOLIDAYREQUESTAPPROVALAPPLICATION
      10. 13.10. CREATING THE SQLWORKFLOWINSTANCESTORE
    19. 14. Hosting
      1. 14.1. SELF-HOSTING APPLICATIONS
        1. 14.1.1. The ServiceHost and the ServiceHostBase
        2. 14.1.2. Implementing a Custom ServiceHost
      2. 14.2. IIS HOSTING
        1. 14.2.1. The ServiceHostFactory and the ServiceHostFactoryBase
        2. 14.2.2. Use the CustomServiceHostFactory
        3. 14.2.3. The SVC File-less Activation
        4. 14.2.4. Windows Activation Services
      3. 14.3. MANAGING AND TRACKING ENDPOINTS WITH WINDOWS APPFABRIC
        1. 14.3.1. Setting Up Windows Server AppFabric
        2. 14.3.2. Monitoring Services with AppFabric
        3. 14.3.3. Enabling the Event Viewer
      4. 14.4. ROUTING SERVICES
        1. 14.4.1. Content-Based Routing
        2. 14.4.2. Protocol and Security Bridging
        3. 14.4.3. Error Handling
      5. 14.5. CLOUD-BASED HOSTING
        1. 14.5.1. Hosting WCF Services in Windows Azure
        2. 14.5.2. The Azure AppFabric Service Bus
        3. 14.5.3. Relaying Through the Cloud

    Product information

    • Title: Professional WCF 4: Windows Communication Foundation with .NET 4
    • Author(s): Pablo Cibraro, Kurt Claeys, Fabio Cozzolino, Johann Grabner
    • Release date: June 2010
    • Publisher(s): Wrox
    • ISBN: 9780470563144