O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

WCF 4.0 Multi-tier Services Development with LINQ to Entities

Book Description

Build SOA applications on the Microsoft platform with this hands-on guide updated for VS2010

  • Master WCF and LINQ to Entities concepts by completing practical examples and applying them to your real-world assignments

  • The first and only book to combine WCF and LINQ to Entities in a multi-tier real-world WCF service

  • Ideal for beginners who want to build scalable, powerful, easy-to-maintain WCF services

  • Rich with example code, clear explanations, interesting examples, and practical advice – a truly hands-on book for C++ and C# developers

  • In Detail

    WCF is the Microsoft model for building services, whereas LINQ to Entities is the Microsoft ORM for accessing underlying data storage. Want to learn both? You would normally have to dig through huge reference tomes—so wouldn't you agree that a simple-to-follow practical tutorial on WCF and LINQ to Entities is the way to get ahead?

    This book is the quickest and easiest way to learn WCF and LINQ to Entities in Visual Studio 2010. WCF and LINQ to Entities are both powerful yet complex technologies from Microsoft—but you will be surprised at how easily this book will get you get up and running with them.

    Mastery of these two topics will quickly enable you to create Service-Oriented applications, and allow you to take your first steps into the world of Service Oriented Architecture without becoming overwhelmed.

    Through this book, you will learn what's going on behind the scenes with WCF, and dive into the basic yet most useful techniques for LINQ to Entities. You will develop three real-world multi-tiered WCF services from beginning to end, with LINQ to Entities being used in the data access layer of the services. Various clients including windows console applications, the WCF Test Client, Windows Form applications and WPF applications will be created to test these WCF services. By the end of this book, you will be 100% confident that you know WCF and LINQ to Entities, not only in theory, but with sound real-world experience.

    Table of Contents

    1. WCF 4.0 Multi-tier Services Development with LINQ to Entities
      1. WCF 4.0 Multi-tier Services Development with LINQ to Entities
      2. Credits
      3. About the Author
      4. About the Reviewers
      5. 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. Errata
          2. Piracy
          3. Questions
      6. 1. Introducing Web Services and Windows Communication Foundation
        1. What is SOA?
        2. Web services
          1. What is a web service?
          2. Web service WSDL
          3. Web service proxy
          4. SOAP
        3. Web services: standards and specifications
          1. WS-I Profiles
          2. WS-Addressing
          3. WS-Security
          4. WS-ReliableMessaging
          5. WS-Coordination and WS-Transaction
        4. WCF: Windows Communication Foundation
        5. What is WCF?
        6. Why is WCF used for SOA?
        7. WCF architecture
        8. Basic WCF concepts—WCF ABCs
          1. Address
          2. Binding
          3. Contract
            1. Service contract
            2. Operation contract
            3. Message contract
            4. Data contract
            5. Fault contract
          4. Endpoint
          5. Behavior
          6. Hosting
            1. Self hosting
            2. Windows services hosting
            3. IIS hosting
            4. Windows Activation Services hosting
          7. Channels
          8. Metadata
        9. WCF production and development environments
        10. Summary
      7. 2. Implementing a Basic HelloWorld WCF Service
        1. Creating the HelloWorld solution and project
        2. Creating the HelloWorldService service contract interface
        3. Implementing the HelloWorldService service contract
        4. Hosting the WCF service in ASP.NET Development Server
          1. Creating the host application
          2. Testing the host application
          3. ASP.NET Development Server
          4. Adding an SVC file to the host application
          5. Modifying the web.config file
          6. Starting the host application
        5. 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
        6. Summary
      8. 3. Hosting and Debugging the HelloWorld WCF Service
        1. Hosting the HelloWorld WCF service
          1. Hosting the service in a managed application
            1. Hosting the service in a console application
            2. Consuming the service hosted in a console application
          2. Hosting the service in a Windows service
          3. Hosting the service in Internet Information Server
            1. Preparing the folders and files
            2. Turn on Internet Information Services
            3. Creating the IIS application
            4. Starting the WCF service in IIS
            5. Testing the WCF service hosted in IIS
          4. Other WCF service hosting options
        2. Debugging the HelloWorld WCF service
          1. Debugging from the client application
            1. Starting the debugging process
            2. Debugging on the client application
            3. Attaching to ASP.NET Development Server
            4. Stepping into the WCF service
          2. Debugging only the WCF service
            1. Starting the WCF Service in debugging mode
            2. Starting the client application in non-debugging mode
            3. Starting the WCF service and client applications in debugging mode
          3. Attaching to a WCF service process
            1. Running the WCF service and client applications in non-debugging mode
            2. Debugging the WCF service hosted in IIS
          4. Just-In-Time debugger
        3. Summary
      9. 4. Implementing a WCF Service in the Real World
        1. Why layer a service?
        2. Creating a new solution and project using WCF templates
          1. Using the C# WCF service library template
          2. Using the C# WCF service application template
        3. Creating the service interface layer
          1. Creating the service interfaces
          2. Creating the data contracts
          3. Implementing the service contracts
          4. Modifying the app.config file
          5. Testing the service using WCF Test Client
          6. Testing the service using our own client
        4. Adding a business logic layer
          1. Adding the product entity 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
      10. 5. Adding Database Support and Exception Handling to the RealNorthwind WCF Service
        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 (GetProduct)
          6. Testing the GetProduct method
          7. Updating the database (UpdateProduct)
        2. Adding error handling to the service
          1. Adding a fault contract
          2. Throwing a fault exception
          3. Updating the client program to catch the fault exception
          4. Testing the fault exception
        3. Summary
      11. 6. LINQ—Language Integrated Query
        1. What is LINQ
        2. Creating the test solution and project
        3. New data type var
        4. Automatic properties
        5. Object initializer
        6. Collection initializer
        7. Anonymous types
        8. Extension methods
        9. Lambda expressions
        10. Built-in LINQ extension methods and method syntax
        11. LINQ query syntax and query expression
        12. Built-in LINQ operators
        13. Summary
      12. 7. LINQ to Entities: Basic Concepts and Features
        1. ORM—Object-Relational Mapping
        2. Entity Framework
        3. LINQ to Entities
        4. Comparing LINQ to Entities with LINQ to Objects
          1. LINQ to SQL
        5. Comparing LINQ to SQL with LINQ to Entities
        6. Creating a LINQ to Entities test application
        7. Creating the Data Model
          1. Adding a LINQ to Entities item to the project
          2. Generated LINQ to Entities classes
        8. Querying and updating the database with a table
          1. Querying records
          2. Updating records
          3. Inserting records
          4. Deleting records
          5. Running the program
        9. View Generated SQL statements
          1. View SQL statements using ToTraceString
          2. View SQL statements using Profiler
        10. Deferred execution
          1. Checking deferred execution with SQL profiler
          2. Deferred execution for singleton methods
          3. Deferred execution for singleton methods within sequence expressions
        11. Deferred (lazy) loading versus eager loading
          1. Lazy loading by default
          2. Eager loading the with Include method
        12. Joining two tables
        13. Querying a view
        14. Summary
      13. 8. LINQ to Entities: Advanced Concepts and Features
        1. Calling a stored procedure
          1. Mapping a stored procedure to a new entity class
            1. Modeling a stored procedure
            2. Querying a stored procedure
          2. Mapping a stored procedure to an existing entity class
        2. Compiled query
        3. Direct SQL
        4. Dynamic query
          1. Dynamic query with expressions
          2. Dynamic query with parameters
        5. Inheritance
          1. LINQ to Entities Table per Hierarchy inheritance
            1. Modeling the BaseCustomer and USACustomer entities
            2. Modeling the UKCustomer entity
            3. Generated classes with TPH inheritance
            4. Testing the TPH inheritance
          2. LINQ to Entities Table per Type inheritance
            1. Preparing database tables
            2. Modeling USACustomer1 and UKCustomer1 entities
            3. Generated classes with TPT inheritance
            4. Testing the TPT inheritance
        6. Handling simultaneous (concurrent) updates
          1. Detecting conflicts using a data column
            1. Explaining the Concurrency Mode property
            2. Adding another Entity Data Model
            3. Writing the test code
            4. Testing the conflicts
            5. Turning on concurrency control
          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
        7. Transaction support
          1. Implicit transactions
          2. Explicit transactions
        8. Adding validations to entity classes
        9. Debugging LINQ to Entities programs
        10. Summary
      14. 9. Applying LINQ to Entities to a WCF Service
        1. Creating the LINQNorthwind solution
        2. Modeling the Northwind database
        3. Copying the connection string to the service layer
        4. Using LINQ to Entities in the data access layer
          1. Modifying GetProduct in the data access layer
          2. Modifying UpdateProduct in the data access layer
          3. Testing LINQ to Entities with the WCF Test Client
        5. Adding concurrency support
          1. Turning on RowVersion concurrency mode
          2. Modifying the ProductEntity class
          3. Modifying the ProductDAO class
            1. Modifying the GetProduct method
            2. Modifying UpdateProduct method
          4. Modifying the business logic layer classes
          5. Modifying the service interface layer classes
        6. Testing concurrency with WCF Test Client
        7. Testing concurrency with our own client
          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 update manually
          4. Testing concurrent update automatically
        8. Summary
      15. 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 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 multiple database support of the WCF service
            1. Creating a new WCF service
            2. Calling the new WCF service in the client application
            3. 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 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 WCF service
          1. Configuring the Distributed Transaction Coordinator
          2. Configuring the firewall
          3. Propagating a transaction from the client to the WCF service
            1. Testing distributed transaction support with one database
            2. Testing distributed transaction support with two databases
        7. Summary