You are previewing WCF Multi-layer Services Development with Entity Framework Fourth Edition.
O'Reilly logo
WCF Multi-layer Services Development with Entity Framework Fourth Edition

Book Description

Create and deploy complete solutions with WCF and Entity Framework

In Detail

This book will teach you all the essentials to develop WCF services using Entity Framework as the backend. You will be guided right through the creation of six WCF and Entity Framework solutions.

You will start off by creating, implementing, and hosting a basic HelloWorld WCF Service followed by deploying the service and publishing it to IIS. Next, you will learn how to create and test a layered service, and then enhance it further by adding a data access layer and exception handling. Next, you will be introduced to LINQ. Starting with the basics, you will then dive into the advanced concepts and features of LINQ to Entities, including Entity Framework, deferred execution, querying a view, and mapping a procedure. Finally, you will get to grips with the RESTful WCF services and security.

What You Will Learn

  • Create a WCF service without using the built-in WCF templates so you can understand the versatility of what's going on under the hood
  • Explore the different methods for hosting and debugging options for a WCF service
  • Build a multi-layer, real-world WCF service from scratch by using WCF templates and Test Client
  • Learn the basic and advanced features of Entity Framework and LINQ to Entities, and apply LINQ to Entities to the data access layer of a WCF service
  • Convert a SOAP WCF service to a RESTful WCF service and create a Windows 8 app to consume a RESTful WCF service
  • Configure the authorization and authentication security settings of WCF and get the details of hosting Windows authentication
  • Explore the extension point architecture of WCF and extend a WCF service with custom behaviors
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. WCF Multi-layer Services Development with Entity Framework Fourth Edition
      1. Table of Contents
      2. WCF Multi-layer Services Development with Entity Framework Fourth Edition
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
          3. Instant updates on new Packt books
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Implementing a Basic HelloWorld WCF Service
        1. The basic WCF concepts
          1. Address
          2. Binding
          3. Contract
            1. The service contract
            2. The operation contract
            3. The message contract
            4. The data contract
            5. The fault contract
          4. Endpoint
          5. Behavior
          6. Hosting
          7. Channels
          8. Metadata
          9. WCF environments
        2. Creating the HelloWorld solution and project
        3. Defining the HelloWorldService service contract interface
        4. Implementing the HelloWorldService service contract
        5. Hosting the WCF service in IIS Express
          1. Creating the host application
          2. Testing the host application
          3. IIS Express
          4. Modifying the Web.config file
          5. Starting the host application
        6. Creating a client to consume the WCF service
          1. Creating the client application project
          2. Generating the proxy and configuration files
          3. Customizing the client application
          4. Running the client application
          5. Setting the service application to autostart
        7. Summary
      9. 2. Hosting the HelloWorld WCF Service
        1. WCF hosting options
          1. Hosting the service in a managed application
          2. Hosting the service in a console application
            1. Consuming the service hosted in a console application
          3. Hosting the service in a Windows service
          4. Hosting the service in IIS using the HTTP protocol
            1. Preparing the folders and files
            2. Starting IIS
            3. Enabling WCF services on Windows 8
            4. Creating the IIS application
            5. Starting the WCF service in IIS
            6. Testing the WCF service hosted in IIS using the HTTP protocol
          5. Hosting the service in IIS using the TCP protocol
            1. Benefits of hosting a WCF service using the TCP protocol
            2. Preparing the folders and files
            3. Enabling the TCP WCF activation for the host machine
            4. Creating the IIS application
            5. Testing the WCF service hosted in IIS using the TCP protocol
        2. Summary
      10. 3. Deploying the HelloWorld WCF Service
        1. Publishing the HelloWorldService from Visual Studio
          1. Publishing from Visual Studio to an on-premise computer
            1. Creating the publishing project
            2. Publishing the HelloWorldService
            3. Testing the service
          2. Publishing to the cloud
            1. Creating the profile to be published
            2. Creating the cloud website
            3. Publishing the HelloWorldService to the cloud website
            4. Testing the service
        2. Publishing the HelloWorldService using a deployment package
          1. Creating the package
          2. Installing the package
          3. Testing the service
        3. Summary
      11. 4. Debugging the HelloWorld WCF Service
        1. Debugging a WCF service from a client application
          1. Starting the debugging process
          2. Debugging the client application
          3. Stepping into the WCF service
        2. Directly debugging the WCF service
          1. Starting the WCF service in the debugging mode
          2. Starting the client application
        3. Attaching the debugger to a running WCF service process
          1. Running the WCF service and client applications in a non-debugging mode
          2. Debugging the WCF service hosted in IIS
        4. Debugging a WCF service hosted in the cloud
          1. Enabling debugging of the service
          2. Attaching to the cloud service process
          3. Debugging the service
        5. Summary
      12. 5. Implementing a Three-layer WCF Service
        1. Why layer a service?
        2. Creating a new solution and project using the built-in WCF service template
          1. Creating the WCF service project
        3. Creating the service interface layer
          1. Creating service interfaces
          2. Creating data contracts
          3. Implementing the service contracts
          4. Modifying the App.config file
          5. Testing the service using the WCF Test Client
          6. Testing the service using your own client
        4. Adding a business logic layer
          1. Adding the business domain object project
          2. Adding the business logic project
          3. Calling the business logic layer from the service interface layer
          4. Testing the WCF service with a business logic layer
        5. Summary
      13. 6. Adding Database Support and Exception Handling
        1. Adding a data access layer
          1. Creating the data access layer project
          2. Calling the data access layer from the business logic layer
          3. Preparing the database
          4. Adding the connection string to the configuration file
          5. Querying the database using GetProduct
          6. Testing the GetProduct method
          7. Updating the database using UpdateProduct
          8. Testing the UpdateProduct method
        2. Adding error handling to the service
          1. Adding a fault contract
          2. Throwing a fault contract exception
          3. Updating the client program to catch the fault exception
          4. Changing the exception options
          5. Testing the fault exception
        3. Summary
      14. 7. LINQ to Entities – Basic Concepts and Features
        1. LINQ to Entities
        2. Creating a LINQ to Entities test application
        3. Creating the data model
          1. Installing Entity Framework
          2. Adding a LINQ to Entities item to the project
          3. The generated LINQ to Entities classes
        4. Querying and updating a database table
          1. Querying records
          2. Updating records
          3. Inserting records
          4. Deleting records
          5. Running the program
        5. Viewing the generated SQL statements
          1. Viewing the SQL statements using ToString
          2. Viewing the SQL statements using SQL Profiler
        6. Deferred execution
          1. Checking deferred execution with SQL Profiler
          2. Deferred execution for aggregation methods
          3. Deferred execution for aggregation methods within sequence expressions
        7. Deferred execution – lazy loading versus eager loading
          1. Lazy loading by default
          2. Eager loading with the Include method
          3. Comparing lazy loading and eager loading
        8. Joining two tables
        9. Querying a view
        10. Summary
      15. 8. LINQ to Entities – Advanced Concepts and Features
        1. Calling a stored procedure
          1. Mapping a stored procedure to a new entity class
            1. Adding a stored procedure to the model
            2. Querying a stored procedure
          2. Mapping a stored procedure to an existing entity class
        2. Handling simultaneous (concurrent) updates
          1. Detecting conflicts using a data column
            1. The Concurrency Mode property
            2. Adding another entity data model
            3. Writing the test code
            4. Testing the conflicts
            5. Turning on concurrency verification
          2. Detecting conflicts using a version column
            1. Adding a version column
            2. Modeling the Products table with a version column
            3. Writing the test code
            4. Testing the conflicts
        3. Transaction support
          1. Implicit transactions
          2. Explicit transactions
        4. Summary
      16. 9. Applying LINQ to Entities to a WCF Service
        1. Creating the LINQNorthwind solution
        2. Installing Entity Framework
        3. Modeling the Northwind database
        4. Creating the business domain object project
        5. Using LINQ to Entities in the data access layer
          1. Adding a reference to the BDO project
          2. Creating GetProduct in the data access layer
          3. Creating UpdateProduct in the data access layer
        6. Creating the business logic layer
        7. Creating the service interface layer
        8. Testing the service with the WCF Test Client
        9. Testing concurrency with our own client
        10. Hosting the WCF service in IIS
          1. Creating the test client
            1. Implementing the GetProduct functionality
            2. Implementing the UpdateProduct functionality
          2. Testing the GetProduct and UpdateProduct operations
          3. Testing concurrent updates manually
          4. Testing concurrent updates automatically
        11. Summary
      17. 10. Distributed Transaction Support of WCF
        1. Creating the DistNorthwind solution
        2. Hosting the WCF service in IIS
        3. Testing the transaction behavior of the existing WCF service
          1. Creating a client to call the WCF service sequentially
          2. Testing the sequential calls to the WCF service
          3. Wrapping the WCF service calls in one transaction scope
          4. Testing the multiple database support of the WCF service
            1. Configuring a remote database on a remote machine
            2. Creating a new WCF service
            3. Calling the new WCF service in the client application
            4. Testing the WCF service with two databases
        4. Enabling distributed transaction support
          1. Enabling transaction flow in service binding
            1. Enabling transaction flow on the service hosting the application
          2. Modifying the service operation contract to allow a transaction flow
          3. Modifying the service operation implementation to require a transaction scope
        5. Understanding the distributed transaction support of a WCF service
        6. Testing the distributed transaction support of the new WCF service
          1. Configuring the Microsoft Distributed Transaction Coordinator
          2. Configuring the firewall
          3. Propagating a transaction from the client to the WCF service
            1. Testing the distributed transaction support with one database
            2. Testing the distributed transaction support with two databases
        7. Trade-offs of distributed transactions
        8. Summary
      18. 11. Building a RESTful WCF Service
        1. SOAP versus REST
        2. WCF REST versus the ASP.NET Web API
        3. Creating the RESTNorthwind solution
        4. Creating the RESTful service
          1. Defining RESTful service contracts
          2. Implementing the RESTful service
          3. Modifying the configuration file
        5. Testing the RESTful service in a browser
        6. Testing the RESTful WCF service with a C#/XAML client
          1. Creating the C#/XAML client
          2. Implementing the GetProduct method of the C#/XAML client
          3. Testing the GetProduct method of the C#/XAML client
          4. Implementing the UpdateProduct method of the C#/XAML client
          5. Testing the UpdateProduct method of the C#/XAML client
        7. Testing the RESTful WCF service with a JavaScript client
          1. Creating the JavaScript client
          2. Testing the service with jQuery
            1. Installing jQuery to the client project
            2. Implementing the GetProductJQuery method
            3. Testing the GetProductJQuery method of the JavaScript client
            4. Implementing the UpdateProductJQuery method
            5. Testing the UpdateProductJQuery method of the JavaScript client
          3. Testing the service with WinJS
            1. Implementing the GetProductWinJS method
            2. Testing the GetProductWinJS method of the JavaScript client
            3. Implementing the UpdateProductWinJS method
            4. Testing the UpdateProductWinJS method of the JavaScript client
        8. Summary
      19. 12. WCF Security
        1. WCF security components
          1. WCF authorization
          2. WCF auditing
          3. WCF transfer security
            1. WCF security modes
            2. WCF transport security
            3. WCF message security
            4. WCF mixed security
            5. WCF transport and message security
            6. Authentication options for transport security
            7. Authentication options for message security
        2. Hosting a WCF service using basic authentication
          1. Setting up the service
          2. Enabling the Basic Authentication feature
          3. Configuring basic authentication on IIS
          4. Configuring the HTTPS protocol
          5. Configuring basic authentication on the service
          6. Testing the service with basic authentication
        3. Hosting a WCF service with Windows authentication
        4. Summary
      20. 13. Extending WCF Services
        1. The WCF runtime architecture
        2. Why extend WCF services?
        3. WCF extension points
          1. Client-side extension points
          2. Service-side extension points
        4. Extending a WCF service
          1. WCF extension classes
          2. WCF behavior classes
          3. WCF behavior element classes
          4. Applying the extensions
        5. Extending HelloWorldService
          1. Setting up the service
          2. Creating the extension project
          3. Creating an extension class
          4. Creating a behavior class
          5. Creating a behavior element class
          6. Applying the extension to HelloWorldService
          7. Testing the extended HelloWorldService
        6. Summary
      21. Index