Top Banner

of 206

Visual Estudio 2008 6461 Labs

Nov 04, 2015

Download

Documents

Giraldo Ocampo

Labs Curso Visual Estudio 2008
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    O F F I C I A L M I C R O S O F T L E A R N I N G P R O D U C T

    6461A Visual Studio 2008: Windows Communication Foundation

    Be sure to access the extended learning content on your Course Companion CD enclosed on the back cover of the book.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    ii Visual Studio 2008: Windows Communication Foundation

    Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

    Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

    The names of manufacturers, products, or URLs are provided for informational purposes only and Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links may be provided to third party sites. Such sites are not under the control of Microsoft and Microsoft is not responsible for the contents of any linked site or any link contained in a linked site, or any changes or updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission received from any linked site. Microsoft is providing these links to you only as a convenience, and the inclusion of any link does not imply endorsement of Microsoft of the site or the products contained therein.

    2008 Microsoft Corporation. All rights reserved.

    Microsoft, Active Directory, Internet Explorer, MSDN, PowerPoint, SQL Server, Visual Basic, Visual C#, Visual Studio, Windows, Windows CardSpace, Windows Server, Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

    All other trademarks are property of their respective owners.

    Product Number: 6461A

    Released: 04/2008

  • MICROSOFT LICENSE TERMS OFFICIAL MICROSOFT LEARNING PRODUCTS - TRAINER EDITION Pre-Release and Final Release Versions These license terms are an agreement between Microsoft Corporation and you. Please read them. They apply to the Licensed Content named above, which includes the media on which you received it, if any. The terms also apply to any Microsoft

    updates,

    supplements,

    Internet-based services, and

    support services

    for this Licensed Content, unless other terms accompany those items. If so, those terms apply.

    By using the Licensed Content, you accept these terms. If you do not accept them, do not use the Licensed Content.

    If you comply with these license terms, you have the rights below.

    1. DEFINITIONS.

    a. Academic Materials means the printed or electronic documentation such as manuals, workbooks, white papers, press releases, datasheets, and FAQs which may be included in the Licensed Content.

    b. Authorized Learning Center(s) means a Microsoft Certified Partner for Learning Solutions location, an IT Academy location, or such other entity as Microsoft may designate from time to time.

    c. Authorized Training Session(s) means those training sessions authorized by Microsoft and conducted at or through Authorized Learning Centers by a Trainer providing training to Students solely on Official Microsoft Learning Products (formerly known as Microsoft Official Curriculum or MOC) and Microsoft Dynamics Learning Products (formerly know as Microsoft Business Solutions Courseware). Each Authorized Training Session will provide training on the subject matter of one (1) Course.

    d. Course means one of the courses using Licensed Content offered by an Authorized Learning Center during an Authorized Training Session, each of which provides training on a particular Microsoft technology subject matter.

    e. Device(s) means a single computer, device, workstation, terminal, or other digital electronic or analog device.

    f. Licensed Content means the materials accompanying these license terms. The Licensed Content may include, but is not limited to, the following elements: (i) Trainer Content, (ii) Student Content, (iii) classroom setup guide, and (iv) Software. There are different and separate components of the Licensed Content for each Course.

    g. Software means the Virtual Machines and Virtual Hard Disks, or other software applications that may be included with the Licensed Content.

    h. Student(s) means a student duly enrolled for an Authorized Training Session at your location.

  • i. Student Content means the learning materials accompanying these license terms that are for use by Students and Trainers during an Authorized Training Session. Student Content may include labs, simulations, and courseware files for a Course.

    j. Trainer(s) means a) a person who is duly certified by Microsoft as a Microsoft Certified Trainer and b) such other individual as authorized in writing by Microsoft and has been engaged by an Authorized Learning Center to teach or instruct an Authorized Training Session to Students on its behalf.

    k. Trainer Content means the materials accompanying these license terms that are for use by Trainers and Students, as applicable, solely during an Authorized Training Session. Trainer Content may include Virtual Machines, Virtual Hard Disks, Microsoft PowerPoint files, instructor notes, and demonstration guides and script files for a Course.

    l. Virtual Hard Disks means Microsoft Software that is comprised of virtualized hard disks (such as a base virtual hard disk or differencing disks) for a Virtual Machine that can be loaded onto a single computer or other device in order to allow end-users to run multiple operating systems concurrently. For the purposes of these license terms, Virtual Hard Disks will be considered Trainer Content.

    m. Virtual Machine means a virtualized computing experience, created and accessed using Microsoft Virtual PC or Microsoft Virtual Server software that consists of a virtualized hardware environment, one or more Virtual Hard Disks, and a configuration file setting the parameters of the virtualized hardware environment (e.g., RAM). For the purposes of these license terms, Virtual Hard Disks will be considered Trainer Content.

    n. you means the Authorized Learning Center or Trainer, as applicable, that has agreed to these license terms.

    2. OVERVIEW.

    Licensed Content. The Licensed Content includes Software, Academic Materials (online and electronic), Trainer Content, Student Content, classroom setup guide, and associated media.

    License Model. The Licensed Content is licensed on a per copy per Authorized Learning Center location or per Trainer basis.

    3. INSTALLATION AND USE RIGHTS.

    a. Authorized Learning Centers and Trainers: For each Authorized Training Session, you may:

    i. either install individual copies of the relevant Licensed Content on classroom Devices only for use by Students enrolled in and the Trainer delivering the Authorized Training Session, provided that the number of copies in use does not exceed the number of Students enrolled in and the Trainer delivering the Authorized Training Session, OR

    ii. install one copy of the relevant Licensed Content on a network server only for access by classroom Devices and only for use by Students enrolled in and the Trainer delivering the Authorized Training Session, provided that the number of Devices accessing the Licensed Content on such server does not exceed the number of Students enrolled in and the Trainer delivering the Authorized Training Session.

    iii. and allow the Students enrolled in and the Trainer delivering the Authorized Training Session to use the Licensed Content that you install in accordance with (ii) or (ii) above during such Authorized Training Session in accordance with these license terms.

  • i. Separation of Components. The components of the Licensed Content are licensed as a single unit. You may not separate the components and install them on different Devices.

    ii. Third Party Programs. The Licensed Content may contain third party programs. These license terms will apply to the use of those third party programs, unless other terms accompany those programs.

    b. Trainers:

    i. Trainers may Use the Licensed Content that you install or that is installed by an Authorized Learning Center on a classroom Device to deliver an Authorized Training Session.

    ii. Trainers may also Use a copy of the Licensed Content as follows:

    A. Licensed Device. The licensed Device is the Device on which you Use the Licensed Content. You may install and Use one copy of the Licensed Content on the licensed Device solely for your own personal training Use and for preparation of an Authorized Training Session.

    B. Portable Device. You may install another copy on a portable device solely for your own personal training Use and for preparation of an Authorized Training Session.

    4. PRE-RELEASE VERSIONS. If this is a pre-release (beta) version, in addition to the other provisions in this agreement, these terms also apply:

    a. Pre-Release Licensed Content. This Licensed Content is a pre-release version. It may not contain the same information and/or work the way a final version of the Licensed Content will. We may change it for the final, commercial version. We also may not release a commercial version. You will clearly and conspicuously inform any Students who participate in each Authorized Training Session of the foregoing; and, that you or Microsoft are under no obligation to provide them with any further content, including but not limited to the final released version of the Licensed Content for the Course.

    b. Feedback. If you agree to give feedback about the Licensed Content to Microsoft, you give to Microsoft, without charge, the right to use, share and commercialize your feedback in any way and for any purpose. You also give to third parties, without charge, any patent rights needed for their products, technologies and services to use or interface with any specific parts of a Microsoft software, Licensed Content, or service that includes the feedback. You will not give feedback that is subject to a license that requires Microsoft to license its software or documentation to third parties because we include your feedback in them. These rights survive this agreement.

    c. Confidential Information. The Licensed Content, including any viewer, user interface, features and documentation that may be included with the Licensed Content, is confidential and proprietary to Microsoft and its suppliers.

    i. Use. For five years after installation of the Licensed Content or its commercial release, whichever is first, you may not disclose confidential information to third parties. You may disclose confidential information only to your employees and consultants who need to know the information. You must have written agreements with them that protect the confidential information at least as much as this agreement.

    ii. Survival. Your duty to protect confidential information survives this agreement.

    iii. Exclusions. You may disclose confidential information in response to a judicial or governmental order. You must first give written notice to Microsoft to allow it to seek a

  • protective order or otherwise protect the information. Confidential information does not include information that

    becomes publicly known through no wrongful act;

    you received from a third party who did not breach confidentiality obligations to Microsoft or its suppliers; or

    you developed independently.

    d. Term. The term of this agreement for pre-release versions is (i) the date which Microsoft informs you is the end date for using the beta version, or (ii) the commercial release of the final release version of the Licensed Content, whichever is first (beta term).

    e. Use. You will cease using all copies of the beta version upon expiration or termination of the beta term, and will destroy all copies of same in the possession or under your control and/or in the possession or under the control of any Trainers who have received copies of the pre-released version.

    f. Copies. Microsoft will inform Authorized Learning Centers if they may make copies of the beta version (in either print and/or CD version) and distribute such copies to Students and/or Trainers. If Microsoft allows such distribution, you will follow any additional terms that Microsoft provides to you for such copies and distribution.

    5. ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS.

    a. Authorized Learning Centers and Trainers:

    i. Software.

    ii. Virtual Hard Disks. The Licensed Content may contain versions of Microsoft XP, Microsoft Windows Vista, Windows Server 2003, Windows Server 2008, and Windows 2000 Advanced Server and/or other Microsoft products which are provided in Virtual Hard Disks.

    A. If the Virtual Hard Disks and the labs are launched through the Microsoft Learning Lab Launcher, then these terms apply:

    Time-Sensitive Software. If the Software is not reset, it will stop running based upon the time indicated on the install of the Virtual Machines (between 30 and 500 days after you install it). You will not receive notice before it stops running. You may not be able to access data used or information saved with the Virtual Machines when it stops running and may be forced to reset these Virtual Machines to their original state. You must remove the Software from the Devices at the end of each Authorized Training Session and reinstall and launch it prior to the beginning of the next Authorized Training Session.

    B. If the Virtual Hard Disks require a product key to launch, then these terms apply:

    Microsoft will deactivate the operating system associated with each Virtual Hard Disk. Before installing any Virtual Hard Disks on classroom Devices for use during an Authorized Training Session, you will obtain from Microsoft a product key for the operating system software for the Virtual Hard Disks and will activate such Software with Microsoft using such product key.

    C. These terms apply to all Virtual Machines and Virtual Hard Disks:

  • You may only use the Virtual Machines and Virtual Hard Disks if you comply with the terms and conditions of this agreement and the following security requirements:

    o You may not install Virtual Machines and Virtual Hard Disks on portable Devices or Devices that are accessible to other networks.

    o You must remove Virtual Machines and Virtual Hard Disks from all classroom Devices at the end of each Authorized Training Session, except those held at Microsoft Certified Partners for Learning Solutions locations.

    o You must remove the differencing drive portions of the Virtual Hard Disks from all classroom Devices at the end of each Authorized Training Session at Microsoft Certified Partners for Learning Solutions locations.

    o You will ensure that the Virtual Machines and Virtual Hard Disks are not copied or downloaded from Devices on which you installed them.

    o You will strictly comply with all Microsoft instructions relating to installation, use, activation and deactivation, and security of Virtual Machines and Virtual Hard Disks.

    o You may not modify the Virtual Machines and Virtual Hard Disks or any contents thereof.

    o You may not reproduce or redistribute the Virtual Machines or Virtual Hard Disks.

    ii. Classroom Setup Guide. You will assure any Licensed Content installed for use during an Authorized Training Session will be done in accordance with the classroom set-up guide for the Course.

    iii. Media Elements and Templates. You may allow Trainers and Students to use images, clip art, animations, sounds, music, shapes, video clips and templates provided with the Licensed Content solely in an Authorized Training Session. If Trainers have their own copy of the Licensed Content, they may use Media Elements for their personal training use.

    iv. iv Evaluation Software. Any Software that is included in the Student Content designated as Evaluation Software may be used by Students solely for their personal training outside of the Authorized Training Session.

    b. Trainers Only:

    i. Use of PowerPoint Slide Deck Templates. The Trainer Content may include Microsoft PowerPoint slide decks. Trainers may use, copy and modify the PowerPoint slide decks only for providing an Authorized Training Session. If you elect to exercise the foregoing, you will agree or ensure Trainer agrees: (a) that modification of the slide decks will not constitute creation of obscene or scandalous works, as defined by federal law at the time the work is created; and (b) to comply with all other terms and conditions of this agreement.

    ii. Use of Instructional Components in Trainer Content. For each Authorized Training Session, Trainers may customize and reproduce, in accordance with the MCT Agreement, those portions of the Licensed Content that are logically associated with instruction of the Authorized Training Session. If you elect to exercise the foregoing rights, you agree or ensure the Trainer agrees: (a) that any of these customizations or reproductions will only be used for providing an Authorized Training Session and (b) to comply with all other terms and conditions of this agreement.

  • iii. Academic Materials. If the Licensed Content contains Academic Materials, you may copy and use the Academic Materials. You may not make any modifications to the Academic Materials and you may not print any book (either electronic or print version) in its entirety. If you reproduce any Academic Materials, you agree that:

    The use of the Academic Materials will be only for your personal reference or training use

    You will not republish or post the Academic Materials on any network computer or broadcast in any media;

    You will include the Academic Materials original copyright notice, or a copyright notice to Microsofts benefit in the format provided below:

    Form of Notice:

    2008 Reprinted for personal reference use only with permission by Microsoft Corporation. All rights reserved.

    Microsoft, Windows, and Windows Server are either registered trademarks or trademarks of Microsoft Corporation in the US and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners.

    6. INTERNET-BASED SERVICES. Microsoft may provide Internet-based services with the Licensed Content. It may change or cancel them at any time. You may not use these services in any way that could harm them or impair anyone elses use of them. You may not use the services to try to gain unauthorized access to any service, data, account or network by any means.

    7. SCOPE OF LICENSE. The Licensed Content is licensed, not sold. This agreement only gives you some rights to use the Licensed Content. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you may use the Licensed Content only as expressly permitted in this agreement. In doing so, you must comply with any technical limitations in the Licensed Content that only allow you to use it in certain ways. You may not

    install more copies of the Licensed Content on classroom Devices than the number of Students and the Trainer in the Authorized Training Session;

    allow more classroom Devices to access the server than the number of Students enrolled in and the Trainer delivering the Authorized Training Session if the Licensed Content is installed on a network server;

    copy or reproduce the Licensed Content to any server or location for further reproduction or distribution;

    disclose the results of any benchmark tests of the Licensed Content to any third party without Microsofts prior written approval;

    work around any technical limitations in the Licensed Content;

    reverse engineer, decompile or disassemble the Licensed Content, except and only to the extent that applicable law expressly permits, despite this limitation;

    make more copies of the Licensed Content than specified in this agreement or allowed by applicable law, despite this limitation;

    publish the Licensed Content for others to copy;

  • transfer the Licensed Content, in whole or in part, to a third party;

    access or use any Licensed Content for which you (i) are not providing a Course and/or (ii) have not been authorized by Microsoft to access and use;

    rent, lease or lend the Licensed Content; or

    use the Licensed Content for commercial hosting services or general business purposes.

    Rights to access the server software that may be included with the Licensed Content, including the Virtual Hard Disks does not give you any right to implement Microsoft patents or other Microsoft intellectual property in software or devices that may access the server.

    8. EXPORT RESTRICTIONS. The Licensed Content is subject to United States export laws and regulations. You must comply with all domestic and international export laws and regulations that apply to the Licensed Content. These laws include restrictions on destinations, end users and end use. For additional information, see www.microsoft.com/exporting.

    9. NOT FOR RESALE SOFTWARE/LICENSED CONTENT. You may not sell software or Licensed Content marked as NFR or Not for Resale.

    10. ACADEMIC EDITION. You must be a Qualified Educational User to use Licensed Content marked as Academic Edition or AE. If you do not know whether you are a Qualified Educational User, visit www.microsoft.com/education or contact the Microsoft affiliate serving your country.

    11. TERMINATION. Without prejudice to any other rights, Microsoft may terminate this agreement if you fail to comply with the terms and conditions of these license terms. In the event your status as an Authorized Learning Center or Trainer a) expires, b) is voluntarily terminated by you, and/or c) is terminated by Microsoft, this agreement shall automatically terminate. Upon any termination of this agreement, you must destroy all copies of the Licensed Content and all of its component parts.

    12. ENTIRE AGREEMENT. This agreement, and the terms for supplements, updates, Internet-based services and support services that you use, are the entire agreement for the Licensed Content and support services.

    13. APPLICABLE LAW.

    a. United States. If you acquired the Licensed Content in the United States, Washington state law governs the interpretation of this agreement and applies to claims for breach of it, regardless of conflict of laws principles. The laws of the state where you live govern all other claims, including claims under state consumer protection laws, unfair competition laws, and in tort.

    b. Outside the United States. If you acquired the Licensed Content in any other country, the laws of that country apply.

    14. LEGAL EFFECT. This agreement describes certain legal rights. You may have other rights under the laws of your country. You may also have rights with respect to the party from whom you acquired the Licensed Content. This agreement does not change your rights under the laws of your country if the laws of your country do not permit it to do so.

    15. DISCLAIMER OF WARRANTY. The Licensed Content is licensed as-is. You bear the risk of using it. Microsoft gives no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this agreement cannot change. To the extent permitted under your local laws, Microsoft excludes the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

  • 16. LIMITATION ON AND EXCLUSION OF REMEDIES AND DAMAGES. YOU CAN RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES.

    This limitation applies to

    anything related to the Licensed Content, software, services, content (including code) on third party Internet sites, or third party programs; and

    claims for breach of contract, breach of warranty, guarantee or condition, strict liability, negligence, or other tort to the extent permitted by applicable law.

    It also applies even if Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your country may not allow the exclusion or limitation of incidental, consequential or other damages.

    Please note: As this Licensed Content is distributed in Quebec, Canada, some of the clauses in this agreement are provided below in French.

    Remarque : Ce le contenu sous licence tant distribu au Qubec, Canada, certaines des clauses dans ce contrat sont fournies ci-dessous en franais.

    EXONRATION DE GARANTIE. Le contenu sous licence vis par une licence est offert tel quel . Toute utilisation de ce contenu sous licence est votre seule risque et pril. Microsoft naccorde aucune autre garantie expresse. Vous pouvez bnficier de droits additionnels en vertu du droit local sur la protection dues consommateurs, que ce contrat ne peut modifier. La ou elles sont permises par le droit locale, les garanties implicites de qualit marchande, dadquation un usage particulier et dabsence de contrefaon sont exclues.

    LIMITATION DES DOMMAGES-INTRTS ET EXCLUSION DE RESPONSABILIT POUR LES DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une indemnisation en cas de dommages directs uniquement hauteur de 5,00 $ US. Vous ne pouvez prtendre aucune indemnisation pour les autres dommages, y compris les dommages spciaux, indirects ou accessoires et pertes de bnfices.

    Cette limitation concerne:

    tout ce qui est reli au le contenu sous licence , aux services ou au contenu (y compris le code) figurant sur des sites Internet tiers ou dans des programmes tiers ; et

    les rclamations au titre de violation de contrat ou de garantie, ou au titre de responsabilit stricte, de ngligence ou dune autre faute dans la limite autorise par la loi en vigueur.

    Elle sapplique galement, mme si Microsoft connaissait ou devrait connatre lventualit dun tel dommage. Si votre pays nautorise pas lexclusion ou la limitation de responsabilit pour les dommages indirects, accessoires ou de quelque nature que ce soit, il se peut que la limitation ou lexclusion ci-dessus ne sappliquera pas votre gard.

    EFFET JURIDIQUE. Le prsent contrat dcrit certains droits juridiques. Vous pourriez avoir dautres droits prvus par les lois de votre pays. Le prsent contrat ne modifie pas les droits que vous confrent les lois de votre pays si celles-ci ne le permettent pas.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Visual Studio 2008: Windows Communication Foundation iii

    Contents

    Module 1: Getting Started with Windows Communication Foundation Lesson 1: Designing an Application to be Part of a Service Oriented Architecture (SOA) 1-3

    Lesson 2: Overview of WCF Architecture 1-9

    Lesson 3: Using a Language-Level Interface As a Service Contract 1-16

    Lesson 4: Implementing a Simple WCF Service in Visual Studio 2008 1-22

    Lesson 5: Consuming a simple WCF service in Visual Studio 2008 1-27

    Lab: Creating a Simple Service 1-31

    Module 2: Configuring and Hosting WCF Services Lesson 1: Programmatically Configuring a Managed Application to Host a WCF Service 2-3

    Lesson 2: Programmatically Configuring a Managed Application to Call a WCF Service 2-12

    Lesson 3: Defining Client and Service Settings by Using File-Based Configuration 2-17

    Lesson 4: Selecting a Hosting Option for a WCF Service 2-21

    Lesson 5: Deploying a WCF Service 2-30

    Lab: Configure and Host a WCF Service 2-36

    Module 3: Endpoints and Behaviors Lesson 1: Exposing WCF Services over Different Endpoints 3-3

    Lesson 2: Adding Behaviors to Services and Endpoints 3-14

    Lesson 3: Interoperating with Non-WCF Web Services 3-20

    Lab: Changing Service Endpoints and Behaviors 3-27

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    iv Visual Studio 2008: Windows Communication Foundation

    Module 4: Debugging and Diagnostics Lesson 1: Logging Messages 4-3

    Lesson 2: Activity Tracing 4-12

    Lab: Message Logging and Activity Tracing 4-17

    Module 5: Designing and Defining Contracts Lesson 1: Designing a Coherent and Cohesive WCF Service Interface 5-3

    Lesson 2: Defining a Service Contract 5-10

    Lesson 3: Defining Operations on a Service 5-16

    Lesson 4: Defining a Data Contract 5-23

    Lab: Contracts for Services and Data 5-30

    Module 6: Handling Errors Lesson 1: Relating .NET Exceptions to Service-level Faults 6-3

    Lesson 2: Using Faults in a Service 6-8

    Lesson 3: Handling Faults and Exceptions on Clients 6-17

    Lab: Error Handling 6-24

    Module 7: Improving WCF Service Quality Lesson 1: Managing WCF Service Instances 7-3

    Lesson 2: Managing Concurrency Issues 7-11

    Lesson 3: Improving WCF Service Quality 7-17

    Lesson 4: Improving Data Transfer Throughput 7-23

    Lab: Improving WCF Service Quality 7-31

    Module 8: Implementing WCF Security Lesson 1: Overview of Security in WCF 8-3

    Lesson 2: Applying Overall Security Requirements to a Binding 8-14

    Lesson 3: Specifying Required Client and Service Credentials 8-25

    Lesson 4: Working with Security Information 8-34

    Lab: Protecting a Service 8-41

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Visual Studio 2008: Windows Communication Foundation v

    Module 9: Implementing Transactions Lesson 1: Overview of Transactions in a Service-Oriented Application 9-3

    Lesson 2: Creating Transactional Service Operations 9-10

    Lesson 3: Enabling the Flow of Transactions from Client to Service 9-16

    Lab: Implementing Transactions for a Service 9-22

    Course Evaluation 9-34

    Lab Answer Keys Lab Answer Key 1: Getting Started with Windows Communication Foundation L1-1 -L1-22

    Lab Answer Key 2: Configuring and Hosting WCF Services L2-23 - L2-44

    Lab Answer Key 3: Endpoints and Behaviors L3-45 - L3-64

    Lab Answer Key 4: Debugging and Diagnostics L4-65 - L4-74

    Lab Answer Key 5: Designing and Defining Contracts L5-75 - L5-104

    Lab Answer Key 6: Handling Errors L6-105- L6-120

    Lab Answer Key 7: Improving WCF Service Quality L7-121 - L7-150

    Lab Answer Key 8: Implementing WCF Security L8-151 - L8-166

    Lab Answer Key 9: Implementing Transactions L9-167 - L9-192

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-1

    Module 1: Getting Started with Windows Communication Foundation

    Lab: Creating a Simple Service Scenario You are a developer on the Contoso Clinic Management product team. You are starting development and you have been assigned to the appointments service in this initial phase.

    Logon Information: Virtual Machine: 6461A-LON-DEV-01 User Name: Student Password: Pa$$w0rd

    Estimated time: 40 minutes

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-2 Module 1: Getting Started with Windows Communication Foundation

    Exercise 1: Creating a Simple WCF Service In this exercise, you will develop the WCF service by using the WCF Service Library template in Microsoft Visual Studio 2008. You will then define a service contract, implement the service contract, and configure the service's endpoints. Finally, you will host the service in Internet Information Service (IIS).

    The main tasks for this exercise are as follows:

    1. Start the 6461-LON-DEV-01 virtual machine and log on as Student.

    2. Add a new WCF Service Library project to the existing ConnectedWCF solution.

    3. Add the existing AppointmentHelperClass to the solution.

    4. Define the service contract.

    5. Implement the service contract.

    6. Add a WCF Service Application project to the ConnectedWCF solution.

    7. Configure the endpoints for the service.

    8. Test the AppointmentService.

    f Task 1: Start the 6461-LON-DEV-01 virtual machine and log on as Student. 1. Open the Virtual Server Remote Control Client and double-click 6461-LON-

    DEV-01.

    2. Log on to 6461-LON-DEV-01 as Student using the password Pa$$w0rd.

    f Task 2: Add a new WCF Service Library project to the existing ConnectedWCF solution. 1. On the Start menu, point to All Programs, point to Microsoft Visual Studio

    2008, and then click Microsoft Visual Studio 2008.

    2. In Visual Studio 2008, on the File menu, point to Open, and then click Project/Solution.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-3

    3. In the Open Project dialog box, browse to either of the following:

    If you are using Visual Basic, browse to the E:\Labfiles\Starter\VB\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    If you are using Visual C#, browse to the E:\Labfiles\Starter\CS\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    4. On the File menu, point to Add, and then click New Project.

    5. In the Add New Project dialog box, define a project with the following properties, and then click OK:

    Project types: If you are using Visual Basic, expand Visual Basic, and then click WCF. If you are using Visual C#, expand Visual C#, and then click WCF.

    Templates: Click the WCF Service Library project template. Name: In the Name box, type AppointmentService Location: If you are using Visual Basic, in the Location box, type

    E:\Labfiles\Starter\VB\ConnectedWCF If you are using Visual C#, in the Location box, type E:\Labfiles\Starter\CS\ConnectedWCF

    6. In Solution Explorer, right-click the AppointmentService project, and then click Properties.

    7. In the Properties window, on the Application tab, in the Root namespace box (for Visual Basic) or Default namespace box for Visual C#), type com.contoso.AppointmentService

    8. On the File menu, click Save All.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-4 Module 1: Getting Started with Windows Communication Foundation

    f Task 3: Add the existing AppointmentHelperClass to the solution. 1. In Solution Explorer, right-click the AppointmentService project, click Add,

    and then click Existing Item.

    2. In the Add Existing Item - AppointmentService dialog box, browse to the following file:

    If you are using Visual Basic, browse to the E:\Labfiles\Starter\VB\ folder, and then double-click the AppointmentHelperClass.vb file.

    If you are using Visual C#, browse to the E:\Labfiles\Starter\CS\ folder, and then double-click the AppointmentHelperClass.cs file.

    3. In Solution Explorer, right-click AppointmentHelperClass, and then click View Code.

    f Task 4: Define the service contract. 1. In Solution Explorer, right-click IService1, click Rename, type

    AppointmentServiceContract.vb (for Visual Basic) or AppointmentServiceContract.cs (for Visual C#), and then press ENTER.

    2. If you are using Visual Basic, in the Microsoft Visual Studio dialog box, click Yes.

    3. In Solution Explorer, right-click AppointmentServiceContract, and then click View Code.

    4. If you are using Visual C#, change the namespace to com.contoso.AppointmentService.

    [Visual C#] ... namespace com.contoso.AppointmentService { ... }

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-5

    5. If you are using Visual C#, change the interface name to AppointmentServiceContract.

    [Visual C#] ... public interface AppointmentServiceContract { } ...

    6. In the Code Editor window for the AppointmentServiceContract class file, remove the following:

    All comments The CompositeType class definition The GetData and GetDataUsingDataContract methods in the

    AppointmentServiceContract interface definition

    7. Modify the ServiceContract attribute on the AppointmentServiceContract definition to include the namespace http://contoso.com/services/AppointmentService.

    [Visual Basic] ... _ ...

    [Visual C#] ... [ServiceContract(Namespace = "http://contoso.com/services/AppointmentService")] ...

    8. Within the AppointmentServiceContract definition, define a method named CreateAppointment that returns a string and that accepts a string parameter named patientId, a string parameter named doctorId, and a DateTime parameter named start.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-6 Module 1: Getting Started with Windows Communication Foundation

    9. Add the OperationContract attribute to the CreateAppointment method.

    [Visual Basic ... _ Function CreateAppointment(ByVal patientId As String, _ ByVal doctorId As String, ByVal start As DateTime) As String ...

    [Visual C#] ... [OperationContract] string CreateAppointment(string patientId, string doctorId, DateTime start); ...

    10. Define a second method named CancelAppointment that returns a bool value and that accepts a string parameter named appointmentId.

    11. Add the OperationContract attribute to the CancelAppointment method.

    [Visual Basic ... _ Function CancelAppointment(ByVal appointmentId As String) _ As Boolean ...

    [Visual C#] ... [OperationContract] bool CancelAppointment(string appointmentId); ...

    12. Define a third method named ListAvailableAppointmentTimes that returns a generic List of type DataTime and accepts a string parameter named doctorId and a DataTime parameter named day.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-7

    13. Add the OperationContract attribute to the ListAvailableAppointmentTimes method.

    [Visual Basic ... _ Function ListAvailableAppointmentTimes(ByVal doctorId As String, _ ByVal day As DateTime) As List(Of DateTime) ...

    [Visual C#] ... [OperationContract] List ListAvailableAppointmentTimes(string doctorId, DateTime day); ...

    Your code for the AppointmentServiceContract class should resemble the following.

    [Visual Basic] _ Public Interface AppointmentServiceContract _ Function CreateAppointment(ByVal patientId As String, _ ByVal doctorId As String, ByVal start As DateTime) As String _ Function CancelAppointment(ByVal appointmentId As String) _ As Boolean _ Function ListAvailableAppointmentTimes(ByVal doctorId As String, _ ByVal day As DateTime) As List(Of DateTime) End Interface

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-8 Module 1: Getting Started with Windows Communication Foundation

    [Visual C#] ... namespace com.contoso.AppointmentService { [ServiceContract(Namespace = "http://contoso.com/services/AppointmentService")] public interface AppointmentServiceContract { [OperationContract] string CreateAppointment(string patientId, string doctorId, DateTime start); [OperationContract] bool CancelAppointment(string appointmentId); [OperationContract] List ListAvailableAppointmentTimes(string doctorId, DateTime day); } }

    f Task 5: Implement the service contract. 1. In Solution Explorer, right-click Service1, click Rename, type

    AppointmentServiceImplementation.vb (for Visual Basic) or AppointmentServiceImplementation.cs (for Visual C#), and then press ENTER.

    2. If you are using Visual Basic, in the Microsoft Visual Studio dialog box, click Yes.

    3. In Solution Explorer, right-click AppointmentServiceImplementation, and then click View Code.

    4. If you are using Visual C#, change the namespace to com.contoso.AppointmentService.

    5 If you are using Visual C#, rename the Service1 class definition to AppointmentServiceImplementation.

    6. Remove the following from the AppointmentServiceImplementation class:

    All comments The GetData and GetDataUsingDataContract methods

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-9

    7. Implement the AppointmentServiceContract interface. If you are using Visual Basic, press ENTER after you type the interface name to generate the method stubs. If you are using Visual C#, right-click the text AppointmentServiceContract in the class definition, point to Implement Interface, and then click Implement Interface.

    8. If you are using Visual C#, remove the following code from the CreateAppointment, CancelAppointment and ListAvailableAppointmentTimes methods.

    [Visual C#] ... throw new NotImplementedException(); ...

    9. In the CreateAppointment method, add code to do the following:

    Create an Appointment object named newAppointment, and then pass the variables patientId, doctorId, and start as parameters to the constructor.

    Return the result of the static GenerateNewAppointment method in the AppointmentHelperClass class. Pass the newAppointment object as a parameter.

    [Visual Basic] ... Public Function CreateAppointment(ByVal patientId As String, _ ByVal doctorId As String, ByVal start As Date) _ As String Implements AppointmentServiceContract.CreateAppointment Dim newAppointment As New Appointment(patientId, doctorId, _ start) Return AppointmentHelperClass. _ GenerateNewAppointment(newAppointment) End Function ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-10 Module 1: Getting Started with Windows Communication Foundation

    [Visual C#] ... public string CreateAppointment(string patientId, string doctorId, DateTime start) { Appointment newAppointment = new Appointment(patientId, doctorId, start); return AppointmentHelperClass.GenerateNewAppointment( newAppointment); } ...

    10. In the CancelAppointment method, add code to return the result of the static CancelExistingAppointment method in the AppointmentHelperClass class. Pass the appointmentId variable as a parameter.

    [Visual Basic] ... Public Function CancelAppointment(ByVal appointmentId As String) _ As Boolean Implements AppointmentServiceContract.CancelAppointment Return AppointmentHelperClass.CancelExistingAppointment( _ appointmentId) End Function ...

    [Visual C#] ... public bool CancelAppointment(string appointmentId) { return AppointmentHelperClass.CancelExistingAppointment( appointmentId); } ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-11

    11. In the ListAvailableAppointmentTimes method, add code to return the result of the static GetAvailableAppointments method in the AppointmentHelperClass class. Pass the doctorId and day variables as parameters.

    [Visual Basic] ... Public Function ListAvailableAppointmentTimes(ByVal doctorId _ As String, ByVal day As Date) As System.Collections. _ Generic.List(Of Date) Implements _ AppointmentServiceContract.ListAvailableAppointmentTimes Return AppointmentHelperClass.GetAvailableAppointments(doctorId, _ day) End Function ...

    [Visual C#] ... public List ListAvailableAppointmentTimes(string doctorId, DateTime day) { return AppointmentHelperClass.GetAvailableAppointments(doctorId, day); } ...

    12. In Solution Explorer, right-click the AppointmentService project, and then click Build.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-12 Module 1: Getting Started with Windows Communication Foundation

    Your code for the AppointmentServiceImplementation class should resemble the following.

    [Visual Basic] ... Public Class AppointmentServiceImplementation Implements AppointmentServiceContract Public Function CreateAppointment(ByVal patientId As String, _ ByVal doctorId As String, ByVal start As Date) _ As String Implements _ AppointmentServiceContract.CreateAppointment Dim newAppointment As New Appointment(patientId, doctorId, _ start) Return AppointmentHelperClass. _ GenerateNewAppointment(newAppointment) End Function Public Function CancelAppointment(ByVal appointmentId As String) _ As Boolean Implements _ AppointmentServiceContract.CancelAppointment Return AppointmentHelperClass.CancelExistingAppointment( _ appointmentId) End Function Public Function ListAvailableAppointmentTimes(ByVal doctorId _ As String, ByVal day As Date) As System.Collections. _ Generic.List(Of Date) Implements _ AppointmentServiceContract.ListAvailableAppointmentTimes Return AppointmentHelperClass.GetAvailableAppointments( _ doctorId, day) End Function End Class ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-13

    [Visual C#] ... namespace com.contoso.AppointmentService { public class AppointmentServiceImplementation : AppointmentServiceContract { #region AppointmentServiceContract Members public string CreateAppointment(string patientId, string doctorId, DateTime start) { Appointment newAppointment = new Appointment(patientId, doctorId, start); return AppointmentHelperClass.GenerateNewAppointment( newAppointment); } public bool CancelAppointment(string appointmentId) { return AppointmentHelperClass.CancelExistingAppointment( appointmentId); } public List ListAvailableAppointmentTimes( string doctorId, DateTime day) { return AppointmentHelperClass.GetAvailableAppointments(doctorId, day); } #endregion } ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-14 Module 1: Getting Started with Windows Communication Foundation

    f Task 6: Add a WCF Service Application project to the ConnectedWCF solution. 1. On the File menu, point to Add, and then click New Project.

    2. In the Add New Project dialog box, define a project with the following properties, and then click OK:

    Project types: If you are using Visual Basic, expand Visual Basic, and then click Web. If you are using Visual C#, expand Visual C#, and then click Web.

    Templates: Click the WCF Service Application project template. Name: In the Name box, type AppointmentServiceIISHost Location: If you are using Visual Basic, in the Location box, type

    E:\Labfiles\Starter\VB\ConnectedWCF If you are using Visual C#, in the Location box, type E:\Labfiles\Starter\CS\ConnectedWCF

    3. In Solution Explorer, right-click the AppointmentServiceIISHost project, and then click Properties.

    4. In the Properties window, on the Web tab, in the Servers section, click Specific port, and then in the corresponding box, type 8001

    5. On the File menu, click Save All.

    6. If you are using Visual Basic, in Solution Explorer, click Show All Files.

    7. Remove the following files and folders from the AppointmentServiceIISHost project:

    The IService1 class file The Service1.svc.vb (for Visual Basic) or Service.svc.cs (for Visual C#) The App_Data folder

    8. In Solution Explorer, right-click the AppointmentServiceIISHost project, and then click Add Reference.

    9. In the Add Reference dialog box, on the Projects tab, double-click AppointmentService.

    10. In Solution Explorer, within the AppointmentServiceIISHost project, right-click the Service1.svc file, click Rename, type AppointmentService.svc and then press ENTER.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-15

    11. In Solution Explorer, right-click AppointmentService.svc, and then click View Markup.

    12. In the Code Editor window, make the following changes to the ServiceHost element in the AppointmentService.svc file:

    Change the Service attribute value to com.contoso.AppointmentService.AppointmentServiceImplementation.

    Remove the CodeBehind attribute and value. [Visual Basic]

    [Visual C#]

    13. On the File menu, click Save All.

    14. In Solution Explorer, right-click the AppointmentServiceIISHost project, and then click Build.

    f Task 7: Configure the endpoints for the AppointmentServiceIISHost. 1. In Solution Explorer, within the AppointmentServiceIISHost project, right-

    click Web.config, and then click Edit WCF Configuration.

    2. In the WCF Service Configuration Editor window, in the Configuration pane, expand Advanced, expand ServiceBehaviors, and then click AppointmentServiceIISHost.Service1Behavior.

    3. In the right pane, in the General section, in the Name box, type AppointmentServiceIISHost.ServiceBehavior

    4. In the left pane under Services, click AppointmentServiceIISHost.Service1.

    5. In the right pane, in the Name box, type com.contoso.AppointmentService.AppointmentServiceImplementation and then press ENTER.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-16 Module 1: Getting Started with Windows Communication Foundation

    6. In the left pane under Services, expand com.contoso.AppointmentService.AppointmentServiceImplementation, expand Endpoints, and then click the first {EmptyName] node.

    7 In the right-pane, in the Contract box, type com.contoso.AppointmentService.AppointmentServiceContract

    8. In the Microsoft Service Configuration Editor window, on the File menu, click Save.

    9. Close the Microsoft Service Configuration Editor window.

    f Task 8: Test the AppointmentService. 1. In Solution Explorer, right-click the AppointmentServiceIISHost project,

    point to Debug, and then click Start new instance.

    2. In the Debugging Not Enabled dialog box, click OK.

    3. In the Script Debugging Disabled dialog box, click Yes.

    4. In the Information Bar dialog box, click Close.

    5. In Internet Explorer, on the Directory Listing page, click AppointmentService.svc.

    6. If you have successfully configured and hosted the AppointmentService, Internet Explorer will display the AppointmentServiceImplementation service default page.

    7. Close Internet Explorer.

    Results: After this exercise, you should have developed a WCF service in Visual Studio 2008.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-17

    Exercise 2: Calling the Simple WCF Service In this exercise, you will add code to the existing ClinicAdminClient Windows Forms application to enable users to find all the available appointment timeslots, create a new appointment, and delete an existing appointment.

    The main tasks for this exercise are as follows:

    1. Add a reference to the AppointmentService.

    2. Add code to the ClinicAdminClient class.

    3. Build and run the solution.

    f Task 1: Add a reference to the AppointmentService. 1. In Solution Explorer, right-click the ClinicAdminClient project, and then click

    Add Service Reference.

    2. In the Add Service Reference dialog box, define a service reference with the following information, and then click OK.

    a. Address: In the Address box, type http://localhost:8001/AppointmentService.svc and then click Go.

    b. Namespace: In the Namespace box, type AppointmentServiceReference

    f Task 2: Add code to the ClinicAdminClient class. 1. In Solution Explorer, right-click ClinicAdminForm, and then click View Code.

    2. Locate the TODO 1 comment, and bring the ClinicAdminClient.AppointmentServiceReference into scope.

    [Visual Basic] ... 'TODO 1. Imports ClinicAdminClient.AppointmentServiceReference ...

    [Visual C#] ... //TODO 1. using ClinicAdminClient.AppointmentServiceReference; ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-18 Module 1: Getting Started with Windows Communication Foundation

    3. Locate the TODO 2 comment, and then add code to return a new AppointmentServiceContractClient object.

    [Visual Basic] ... Private Function GetAppointmentServiceProxy() As _ AppointmentServiceContract ' TODO 2. Return New AppointmentServiceContractClient() End Function ...

    [Visual C#] ... private AppointmentServiceContract GetAppointmentServiceProxy() { // TODO 2. return new AppointmentServiceContractClient(); } ...

    4. Locate the TODO 3 comment, and then add code to do the following:

    Create a new AppointmentServiceContract object called proxy, and then initialize it to the return value of the GetAppointmentServiceProxy method.

    Set the slots object to the return value of the ListAvailableAppointmentTimes method in the proxy class. Pass the Text property of the doctorId field and the Value property of the dateRequested field as parameters.

    [Visual Basic] ... ' TODO 3. Dim proxy As AppointmentServiceContract = _ GetAppointmentServiceProxy() slots = proxy.ListAvailableAppointmentTimes(doctorId.Text, _ dateRequested.Value) ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-19

    [Visual C#] ... // TODO 3. AppointmentServiceContract proxy = GetAppointmentServiceProxy(); slots = proxy.ListAvailableAppointmentTimes(doctorId.Text, dateRequested.Value); ...

    5. Locate the TODO 4 comment, and then add code to do the following:

    Create a new AppointmentServiceContract object named proxy, and then initialize it to the return value of the GetAppointmentServiceProxy method.

    Set the appointmentId variable to the return value of the CreateAppointment method in the proxy class. Pass the Text property of the patientId field, the Text property of the doctorId field, and the slot variable as parameters.

    [Visual Basic] ... ' TODO 4. Dim proxy As AppointmentServiceContract _ = GetAppointmentServiceProxy() appointmentId = _ proxy.CreateAppointment(patientId.Text, doctorId.Text, slot) ...

    [Visual C#] ... // TODO 4. AppointmentServiceContract proxy = GetAppointmentServiceProxy(); appointmentId = proxy.CreateAppointment(patientId.Text, doctorId.Text, slot); ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L1-20 Module 1: Getting Started with Windows Communication Foundation

    6. Locate the TODO 5 comment, and then add code to do the following:

    Create a new AppointmentServiceContract object named proxy, and then initialize it to the return value of the GetAppointmentServiceProxy method.

    Set the cancelled variable to the return value of the CancelAppointment method in the proxy class. Pass the Text property of the appointmentId field as a parameter.

    [Visual Basic] ... ' TODO 5. Dim proxy As AppointmentServiceContract _ = GetAppointmentServiceProxy() cancelled = proxy.CancelAppointment(appointmentId.Text) ...

    [Visual C#] ... // TODO 5. AppointmentServiceContract proxy = GetAppointmentServiceProxy(); cancelled = proxy.CancelAppointment(appointmentId.Text); ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Creating a Simple Service L1-21

    f Task 3: Build and run the solution. 1. On the Build menu, click Build Solution.

    2. On the Debug menu, click Start Debugging.

    3. On the Clinic Administration Client form, on the Create Appointment tab, click Find Slots.

    4. Create an appointment with the following information, and then click Create:

    Doctor: In Doctor list, click ENT_Davies. Slots: In the Slots list, click any of the available time slots. Patient: In the Patient box, type your name.

    5. In the Appointment Created dialog box, make a note of the Appointment identifier, and then click OK.

    6. On the Cancel Appointment tab, in the Appt ID box, type your Appointment identifier, and then click Delete.

    7. In the Appointment Cancellation dialog box, click OK.

    8. In Visual Studio 2008, on the Debug menu, click Stop Debugging.

    9. Close Visual Studio 2008.

    Results: After this exercise, you should have enhanced the existing ClinicAdminClient application to invoke the methods in the AppointmentService.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-23

    Module 2: Configuring and Hosting WCF Services

    Lab: Configure and Host a WCF Service Scenario You are a developer on the Contoso Clinic Management product team. Your team has developed part of the appointment service and your task now is to look at the different ways of storing the WCF configurations settings and hosting the appointments service.

    Logon Information: Virtual Machine: 6461A-LON-DEV-02 User Name: Student Password: Pa$$w0rd

    Estimated time: 80 minutes

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-24 Module 2: Configuring and Hosting WCF Services

    Exercise 1: Creating a Programmatically Configured Managed Application to Host a Service In this exercise, you will develop an EXE application to host the appointment service.

    The main tasks for this exercise are as follows:

    1. Start the 6461-LON-DEV-02 virtual machine and log on as Student.

    2. Open the existing ConnectedWCF solution.

    3. Add a new Windows Console application to the ConnectedWCF solution.

    4. Add code to host the AppointmentService.

    5. Change the endpoint address in the ClinicAdminClient.

    6. Set the ConnectedWCF solution startup projects.

    7. Build and run the solution.

    f Task 1: Start the 6461-LON-DEV-02 virtual machine and log on as Student 1. Open the Virtual Server Remote Control Client, and then double-click 6461-

    LON-DEV-02.

    2. Log on to 6461-LON-DEV-02 as Student using the password Pa$$w0rd.

    f Task 2: Open the existing ConnectedWCF solution 1. On the Start menu, point to All Programs, point to Microsoft Visual Studio

    2008, right-click Microsoft Visual Studio 2008, and then click Run as administrator

    2. In the User Account Control dialog box, click Continue.

    3. In Microsoft Visual Studio 2008 development system, on the File menu, point to Open, and then click Project/Solution.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-25

    4. In the Open Project dialog box, go to either of the following:

    If you are using Microsoft Visual Basic development system, go to the E:\Labfiles\Starter\VB\Ex1\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    If you are using Microsoft Visual C# development tool, go to the E:\Labfiles\Starter\CS\Ex1\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    f Task 3: Add a new Windows Console application to the ConnectedWCF solution 1. On the File menu, point to Add, and then click New Project.

    2. In the Add New Project dialog box, define a project with the following properties, and then click OK.

    Project types: If you are using Visual Basic, expand Visual Basic, and then click Windows. If you are using Visual C#, expand Visual C#, and then click Windows.

    Templates: Click the ConsoleApplication project template. Name: In the Name box type AppointmentServiceSelfHost. Location: If you are using Visual Basic, in the Location box, type

    E:\Labfiles\Starter\VB\Ex1\ConnectedWCF

    If you are using Visual C#, in the Location box, type E:\Labfiles\Starter\CS\Ex1\ConnectedWCF

    f Task 4: Add code to host the AppointmentService 1. In Solution Explorer, right-click the AppointmentServiceSelfHost project, and

    then click Add Reference.

    2. In the Add Reference dialog box, on the .NET tab, in the Component Name column, double-click the System.ServiceModel assembly.

    3. In Solution Explorer, right-click the AppointmentServiceSelfHost project, and then click Add Reference.

    4. In the Add Reference dialog box, on the Projects tab, in the Project Name column, double-click the AppointmentService assembly.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-26 Module 2: Configuring and Hosting WCF Services

    5. In the Code Editor window for the Module1 class (for Visual Basic) or Program class (for Visual C#), bring the System.ServiceModel namespace into scope.

    [Visual Basic] ... Imports System.ServiceModel ...

    [Visual C#] ... using System.ServiceModel; ...

    6. In the Main method, create a new Uri object named baseAddress. Pass the string http://localhost:8002/Contoso as a parameter.

    [Visual Basic] ... Dim baseAddress As New Uri("http://localhost:8002/Contoso") ...

    [Visual C#] ... Uri baseAddress = new Uri("http://localhost:8002/Contoso"); ...

    7. Create a new Type object named instanceType. Initialize the instanceType object to com.contoso.AppointmentService.AppointmentServiceImplementation.

    [Visual Basic] ... Dim instanceType As Type = _ GetType(com.contoso.AppointmentService. _ AppointmentServiceImplementation) ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-27

    [Visual C#] ... Type instanceType = typeof(com.contoso.AppointmentService. AppointmentServiceImplementation); ...

    8. Create a new ServiceHost object named host. Pass the instanceType and baseAddress objects to the ServiceHost constructor.

    [Visual Basic] ... Dim host As New ServiceHost(instanceType, baseAddress) ...

    [Visual C#] ... ServiceHost host = new ServiceHost(instanceType, baseAddress); ...

    9. Add a Using block (for Visual Basic) or using block (for Visual C#), and then pass the host object as a parameter.

    [Visual Basic] ... Using host End Using ...

    [Visual C#] ... using (host) { } ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-28 Module 2: Configuring and Hosting WCF Services

    10. In the Using block (for Visual Basic) or using block (for Visual C#), add code to do the following:

    a. Create a new instance of the Type class named contractType. Initialize the contractType object to com.contoso.AppointmentService.AppointmentServiceImplementation.

    b. Create a new string variable named relativeAddress, and then initialize it to the text AppointmentService.

    c. Add a WSHttpBinding endpoint to the host object. To do this, invoke the AddServiceEndpoint method on the host object. Pass the contractType variable, a new WsHttpBinding object, and the relativeAddress variable as parameters.

    d. Invoke the Open method on the host object.

    e. Write the following message to the console: Appointment service running. Press to quit.

    f. Invoke the ReadLine method on the Console class to stop the console from closing.

    g. Invoke the Close method on the host object.

    [Visual Basic] ... Using host Dim contractType As Type = _ GetType(com.contoso.AppointmentService. _ AppointmentServiceContract) Dim relativeAddress As String = "AppointmentService" host.AddServiceEndpoint(contractType, New WSHttpBinding(), _ relativeAddress) host.Open() Console.WriteLine("Appointment service " & _ "running. Press to quit.") Console.ReadLine() host.Close() End Using ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-29

    [Visual C#] ... using (host) { Type contractType = typeof(com.contoso.AppointmentService. AppointmentServiceContract); string relativeAddress = "AppointmentService"; host.AddServiceEndpoint(contractType, new WSHttpBinding(), relativeAddress); host.Open(); Console.WriteLine("Appointment service " + "running. Press to quit."); Console.ReadLine(); host.Close(); } ...

    f Task 5: Change the endpoint address in the ClinicAdminClient 1. In Solution Explorer, in the ClinicAdminClient project, right-click the

    app.config (for Visual Basic) or App.config (for Visual C#) file, and then click Edit WCF Configuration.

    2 In the Microsoft Service Configuration Editor, in the left pane, expand the Endpoints folder under the Client folder, and then click WSHttpBinding_AppointmentServiceContract.

    3 In the right pane, change the Address property to http://localhost:8002/Contoso/AppointmentService.

    4. On the File menu, click Save, and then close the Microsoft Service Configuration Editor.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-30 Module 2: Configuring and Hosting WCF Services

    f Task 6: Set the ConnectedWCF solution startup projects 1. In Solution Explorer, right-click the ConnectedWCF solution, and then click

    Set Startup Projects.

    2. In the Solution 'ConnectedWCF' Property Pages dialog box, click Multiple startup projects.

    3. In the Multiple startup projects list, set the Action for the AppointmentServiceSelfHost and ClinicAdminClient projects to Start. Set the Action for the remaining projects to None.

    4. In the Solution 'ConnectedWCF' Property Pages dialog box, click OK.

    f Task 7: Build and run the solution 1. On the Build menu, click Build Solution.

    2. On the Debug menu, click Start Debugging.

    3. Wait for the Console window to display the following message:

    Appointment service running. Press to quit.

    In the Clinic Administration Client form, on the Create Appointment tab, click Find Slots. You should see the list of available appointments.

    4. In Visual Studio 2008, on the Debug menu, click Stop Debugging.

    Results: After this exercise, you should have developed an EXE host for the appointment service.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-31

    Exercise 2: Calling a Service Hosted in a Managed Application by Using Programmatic Configuration In this exercise, you will programmatically define the WCF configuration for the ClinicAdminClient project.

    The main tasks for this exercise are as follows:

    1. Remove the existing endpoint configuration from the ClinicAdminClient configuration file.

    2. Programmatically add code to define the endpoint configuration.

    3. Build and run the solution.

    f Task 1: Remove the existing endpoint configuration from the ClinicAdminClient configuration file 1. In Visual Studio 2008, on the File menu, point to Open, and then click

    Project/Solution.

    2. In the Open Project dialog box, go to either of the following:

    If you are using Visual Basic, go to the E:\Labfiles\Starter\VB\Ex2\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    If you are using Visual C#, go to the E:\Labfiles\Starter\CS\Ex2\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    3. In Solution Explorer, in the ClinicAdminClient project, double-click the app.config file (for Visual Basic) or the App.config file (for Visual C#).

    4. In the Code Editor window for the configuration file, remove the element and all its sub-elements.

    5. On the File menu, click Save All.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-32 Module 2: Configuring and Hosting WCF Services

    f Task 2: Programmatically add code to define the endpoint configuration 1. In Solution Explorer, right-click the ClinicAdminForm class, and then click

    View Code.

    2. If you are using Visual Basic, bring the System.ServiceModel namespace into scope.

    [Visual Basic] ... Imports System.ServiceModel ...

    3. Locate the GetAppointmentServiceProxy method, and then remove the existing method body code.

    4. In the GetAppointmentServiceProxy method, add code to do the following:

    a. Create a new instance of the EndpointAddress class named address. Pass the text http://localhost:8002/Contoso/AppointmentService to the constructor.

    b. Create a new instance of the WSHttpBinding class named binding.

    c. Create a new variable of type AppointmentServiceContract named proxy.

    d. Instantiate the proxy object to the return value of the CreateChannel method of the form of the ChannelFactory class that is specific to the AppointmentServiceContract type. Pass the binding and address objects as parameters in the method call.

    e. Return the proxy object to the method caller.

    [Visual Basic] ... Private Function GetAppointmentServiceProxy() As _ AppointmentServiceContract Dim address As New EndpointAddress("http://localhost:8002/" & _ "Contoso/AppointmentService") Dim binding As New WSHttpBinding() Dim proxy As AppointmentServiceContract = _ ChannelFactory(Of AppointmentServiceContract). _ CreateChannel(binding, address) Return proxy End Function...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-33

    [Visual C#] ... private AppointmentServiceContract GetAppointmentServiceProxy() { EndpointAddress address = new EndpointAddress("http://localhost:8002/" + "Contoso/AppointmentService"); WSHttpBinding binding = new WSHttpBinding(); AppointmentServiceContract proxy = ChannelFactory. CreateChannel(binding, address); return proxy; } ...

    f Task 3: Build and run the solution 1. On the Build menu, click Build Solution.

    2. On the Debug menu, click Start Debugging.

    3. Wait for the Console window to display the following message:

    Appointment service running. Press to quit.

    In the Clinic Administration Client form, on the Create Appointment tab, click Find Slots. You should see the list of available appointments.

    4. In Visual Studio 2008, on the Debug menu, click Stop Debugging.

    Results: After this exercise, you should have programmatically defined the WCF configuration for the AppontmentServiceSelfHost and ClinicAdminClient projects.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-34 Module 2: Configuring and Hosting WCF Services

    Exercise 3: Defining Service Settings by Using External Configuration In this exercise, you will remove the programmatic WCF configuration from the AppointmentServiceSelfHost and ClinicAdminClient projects and then provide the configuration in external configuration files.

    The main tasks for this exercise are as follows:

    1. Add an external configuration file to the AppointmentServiceSelfHost project.

    2. Remove the programmatic endpoint configuration from the AppointmentServiceSelfHost project.

    3. Remove the programmatic endpoint configuration from the ClinicAdminClient project.

    4. Build and run the solution.

    f Task 1: Add an external configuration file to the AppointmentServiceSelfHost project 1. In Visual Studio 2008, on the File menu, point to Open, and then click

    Project/Solution.

    2. In the Open Project dialog box, go to either of the following:

    If you are using Visual Basic, go to the E:\Labfiles\Starter\VB\Ex3\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    If you are using Visual C#, go to the E:\Labfiles\Starter\CS\Ex3\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    3. In Solution Explorer, right-click the AppointmentServiceSelfHost project, point to Add, and then click New Item.

    4. In the Add New Item - AppointmentServiceSelfHost dialog box, do the following, and then click Add:

    If you are using Visual Basic, in the Categories pane, click General, and then in the Templates pane, click Application Configuration File.

    If you are using Visual C#, in the Templates pane, click Application Configuration File.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-35

    5. In Solution Explorer, in the AppointmentServiceSelfHost project, right-click the app.config file (for Visual Basic) or the App.config file (for Visual C#), and then click Edit WCF Configuration.

    6. In Microsoft Service Configuration Editor, in the left pane, right-click the Services node, and then click New Service.

    7. In the right pane, in the Name box, type com.contoso.AppointmentService.AppointmentServiceImplementation and then press ENTER.

    8. In the left pane, expand the com.contoso.AppointmentService.AppointmentServiceImplementation folder under the Services folder, right-click the Endpoints folder, and then click New Service Endpoint.

    9. In the right pane, define a new endpoint with the following information:

    Name: APService_WsHTTP Address: http://localhost:8002/Contoso/AppointmentService Binding: wsHttpBinding Contract:

    com.contoso.AppointmentService.AppointmentServiceContract

    10. On the File menu, click Save, and then close the Microsoft Service Configuration Editor.

    11. In the Microsoft Visual Studio dialog box, click Yes to All.

    f Task 2: Remove the programmatic endpoint configuration from the AppointmentServiceSelfHost project 1. In Solution Explorer, in the AppointmentServiceSelfHost project, right-click

    the Module1 class (for Visual Basic) or Program class (for Visual C#), and then click View Code.

    2. In the Main method, make the following changes to the existing code:

    a. Remove the code that defines the baseAddress object.

    b. Remove the baseAddress parameter from the ServiceHost constructor.

    c. Remove the code that defines the contractType object and relativeAddress string.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-36 Module 2: Configuring and Hosting WCF Services

    d. Remove the line of code that adds a new service endpoint to the host object.

    Your code should resemble the following.

    [Visual Basic] ... Sub Main() Dim instanceType As Type = _ GetType(com.contoso.AppointmentService. _ AppointmentServiceImplementation) Dim host As New ServiceHost(instanceType) Using host host.Open() Console.WriteLine("Appointment service " _ & "running. Press to quit.") Console.ReadLine() host.Close() End Using End Sub ...

    [Visual C#] ... static void Main(string[] args) { Type instanceType = typeof(com.contoso.AppointmentService. AppointmentServiceImplementation); ServiceHost host = new ServiceHost(instanceType); using (host) { host.Open(); Console.WriteLine("Appointment service " + "running. Press to quit."); Console.ReadLine(); host.Close(); } } ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-37

    f Task 3: Remove the programmatic endpoint configuration from the ClinicAdminClient project 1. In Solution Explorer, in the ClinicAdminClient project, right-click the

    app.config file (for Visual Basic) or App.config file (for Visual C#), and then click Edit WCF Configuration.

    2. In the Microsoft Service Configuration Editor, in the left pane, expand Client, right-click Endpoints, and then click New Client Endpoint.

    3. In the right pane, define a new client endpoint with the following information:

    Name: APService_WsHTTP Address: http://localhost:8002/Contoso/AppointmentService Binding: wsHttpBinding Contract: AppointmentServiceReference.AppointmentServiceContract

    4. On the File menu, click Save, and then close the Microsoft Service Configuration Editor.

    5. In Solution Explorer, in the ClinicAdminClient project, right-click the ClinicAdminForm class, and then click View Code.

    6. Locate the GetAppointmentServiceProxy method, and then do the following:

    a. Remove the existing method body code.

    b. Add code to return a new AppointmentServiceContractClient object.

    [Visual Basic] ... Private Function GetAppointmentServiceProxy() As _ AppointmentServiceContract Return New AppointmentServiceContractClient() End Function ...

    [Visual C#] ... private AppointmentServiceContract GetAppointmentServiceProxy() { return new AppointmentServiceContractClient(); } ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-38 Module 2: Configuring and Hosting WCF Services

    f Task 4: Build and run the solution 1. On the Build menu, click Build Solution.

    2. On the Debug menu, click Start Debugging.

    3. Wait for the Console window to display the following message:

    Appointment service running. Press to quit.

    In the Clinic Administration Client form, on the Create Appointment tab, click Find Slots. You should see the list of available appointments.

    4. In Visual Studio 2008, on the Debug menu, click Stop Debugging.

    Results: After this exercise, you should have defined the WCF configuration for the AppontmentServiceSelfHost and ClinicAdminClient projects in external configuration files.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-39

    Exercise 4: Employing Different Hosting Options for a Service In this exercise, you will host the appointment service with WAS. To use WAS, you will add additional endpoints to both the AppointmentServiceIISHost and the ClinicAdminClient projects.

    The main tasks for this exercise are as follows:

    1. Add a new Application directory to IIS.

    2. Add the net.tcp binding to the WAS configuration.

    3. Enable TCP support for the AppointmentServiceIISHost application.

    4. Configure a TCP endpoint for the AppointmentServiceIISHost application.

    5. Configure a TCP binding for the ClinicAdminClient application.

    6. Set the ConnectedWCF solution startup projects.

    7. Build and run the solution.

    f Task 1: Add a new Application directory to IIS 1. On the Start menu, click Control Panel.

    2. In the Control Panel window, click System Maintenance.

    3. In the Control Panel\System and Maintenance window, click Administrative Tools.

    4. In the Administrative Tools window, click Internet Information Services (IIS) Manager.

    5. In the User Account Control dialog box, click Continue.

    6. In the Internet Information Services (IIS) Manager window, in the left pane, expand LON-DEV (LON-DEV\Student), and then expand Web Sites.

    7. Right-click Default Web Site, and then click Add Application.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-40 Module 2: Configuring and Hosting WCF Services

    8. In the Add Application dialog box, add a new application with the following details, and then click OK.

    Alias: AppointmentServiceIISHost Physical path: If you are using Visual Basic, go to

    E:\Labfiles\Starter\VB\Ex4\ConnectedWCF\AppointmentServiceIISHost. If you are using Visual C#, go to E:\Labfiles\Starter\CS\Ex4\ConnectedWCF\AppointmentServiceIISHost.

    9. Close the Internet Information Services (IIS) Manager window.

    f Task 2: Add the net.tcp binding to the WAS configuration 1. In Windows Explorer, go to E:\Labfiles\Starter\, right-click the

    AddTcpBindingToWas.cmd file, and then click Edit.

    2. Examine the command, and then close Notepad.

    3. Right-click the AddTcpBindingToWas.cmd file, and then click Run as administrator.

    4. In the User Account Control dialog box, click Continue.

    5. In the Command Prompt window, ensure the command executed successfully, and then press ENTER.

    f Task 3: Enable TCP support for the AppointmentServiceIISHost application 1. In Windows Explorer, in the E:\Labfile\Starter\ folder, right-click the

    AppointmentServiceIISHostTcpSupport.cmd file, and then click Edit.

    2. Examine the command, and then close Notepad.

    3. Right-click the AppointmentServiceIISHostTcpSupport.cmd file, and then click Run as administrator.

    4. In the User Account Control dialog box, click Continue.

    5. In the Command Prompt window, ensure the command executed successfully, and then press ENTER.

    6. Close Windows Explorer.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-41

    f Task 4: Configure a TCP endpoint for the AppointmentServiceIISHost application 1. In Visual Studio 2008, on the File menu, point to Open, and then click

    Project/Solution.

    2. In the Open Project dialog box, go to either of the following:

    If you are using Visual Basic, go to the E:\Labfiles\Starter\VB\Ex4\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    If you are using Visual C#, go to the E:\Labfiles\Starter\CS\Ex4\ConnectedWCF folder, and then double-click the ConnectedWCF.sln file.

    3. In Solution Explorer, in the AppointmentServiceIISHost project, right-click the Web.config file, and then click Edit WCF Configuration.

    4. In the left pane, under Services, expand com.contoso.AppointmentService.AppointmentServiceImplementation, right-click Endpoints, and then click New Service Endpoint.

    5. In the right-pane, define a service endpoint with the following details:

    Name: APService_TCP Address:

    net.tcp://localhost:9090/AppointmentServiceIISHost/AppointmentServiceIISHost.svc

    Binding: netTcpBinding Contract:

    com.contoso.AppointmentService.AppointmentServiceContract

    6. On the File menu, click Save, and then close the WCF Configuration Editor.

    f Task 5: Configure a TCP binding for the ClinicAdminClient application 1. In Solution Explorer, in the ClinicAdminClient project, right-click the

    app.config file (for Visual Basic) or App.config file (for Visual C#), and then click Edit WCF Configuration.

    2. In the Microsoft Service Configuration Editor, in the left pane, under the Client folder, right-click Endpoints, and then click New Client Endpoint.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L2-42 Module 2: Configuring and Hosting WCF Services

    3. In the right pane, define a new client endpoint with the following information:

    Name: APService_TCP Address:

    net.tcp://localhost:9090/AppointmentServiceIISHost/AppointmentServiceIISHost.svc

    Binding: netTcpBinding Contract: AppointmentServiceReference.AppointmentServiceContract

    4. On the File menu, click Save, and then close the Microsoft Service Configuration Editor.

    5. In Solution Explorer, right-click the ClinicAdminForm, and then click View Code.

    6. In the Code Editor window, for the ClinicAdminForm class, locate the GetAppointmentServiceProxy method, and then pass the string APService_TCP to the AppointmentServiceContractClient constructor.

    [Visual Basic] ... Private Function GetAppointmentServiceProxy() As _ AppointmentServiceContract Return New AppointmentServiceContractClient("APService_TCP") End Function ...

    [Visual C#] ... private AppointmentServiceContract GetAppointmentServiceProxy() { return new AppointmentServiceContractClient("APService_TCP"); } ...

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Configure and Host a WCF Service L2-43

    f Task 6: Set the ConnectedWCF solution startup projects 1. In the Solution Explorer window, right-click Solution 'ConnectedWCF', and

    then click Set Startup Projects.

    2. In the Solution 'ConnectedWCF' Property Pages dialog box, click Single startup project.

    3. In the Solution 'ConnectedWCF' Property Pages dialog box, click OK.

    f Task 7: Build and run the solution 1. On the Build menu, click Build Solution.

    2. On the Debug menu, click Start Debugging.

    3. In the Clinic Administration Client form, on the Create Appointment tab, click Find Slots. You should see the list of available appointments.

    4. In Visual Studio 2008, on the Debug menu, click Stop Debugging.

    Results: After this exercise, you should have hosted the appointment service in IIS using WAS.

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    Lab: Changing Service Endpoints and Behaviors L3-45

    Module 3: Endpoints and Behaviors

    Lab: Changing Service Endpoints and Behaviors Scenario You are a developer on the Contoso, Ltd Clinic Management product team. Your manager has asked you to look at exposing the Appointment service to both Internet and intranet clients and to lock down security a little by removing the metadata endpoint. You must also experiment with exposing a metadata endpoint, and configuring the Patient Letter service to interoperate with an existing ASP.NET legacy Web service.

    Logon Information: Virtual Machine: 6461-LON-DEV-03 User Name: Student Password: Pa$$w0rd

    Estimated time: 60 minutes

  • MC

    T USE O

    NLY. STU

    DEN

    T USE PR

    OH

    IBITED

    L3-46 Module 3: Endpoints and Behaviors

    Exercise 1: Exposing Services by Using Different Bindings In this exercise, you will configure both a wsHttpBinding and a netTcpBinding endpoint for the Appointment service. You will then manually generate a service proxy class by using the Svcutil.exe tool. You will then add the necessary WCF configuration to the ClinicAdminClient and FPAdminClient client applications.

    The main tasks for this exercise are as follows:

    1. Start the 6461-LON-DEV-03 virtual machine and log on as Student.

    2. Open the existing ConnectedWCF solution.

    3. Add a netTcpBinding and a wsHttpBiniding endpoint to the Appointment service.

    4. Generate a service proxy by using Svcutil.exe.

    5