1. Trang chủ
  2. » Khoa Học Tự Nhiên

Mcad mcsd 70 310,70 320 developing xml web services server

853 48 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 853
Dung lượng 11,02 MB

Nội dung

Copyright © 2003 by Microsoft Corporation PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2003 by Microsoft Corporation All rights reserved No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher Library of Congress Cataloging-in-Publication Data MCAD/MCSD Self-Paced Training Kit: Developing XML Web Services and Server Components with Microsoft Visual Basic NET and Microsoft C# NET / Microsoft Corporation p cm Includes index ISBN 0-7356-1586-1 1 Electronic data processing personnel Certification Microsoft software Examinations Study guides Microsoft NET Framework XML (Document markup language) 5 Microsoft Windows (Computer file) I Title: Developing XML Web services and server components with Microsoft Visual Basic NET and Microsoft C# NET II Microsoft Corporation QA76.3.M325565 2002 005.2'768 dc21 2002033714 Printed and bound in the United States of America QWT Distributed in Canada by H.B Fenn and Company Ltd A CIP catalogue record for this book is available from the British Library Microsoft Press books are available through booksellers and distributors worldwide For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329 Visit our Web site at www.microsoft.com/mspress Send comments to tkinput@microsoft.com Active Directory, ActiveX, Authenticode, BackOffice, CodeView, IntelliSense, Jscript, Microsoft, Microsoft Press, MSDN, Visual Basic, Visual C++, Visual C#, Visual J++, Visual J#, Visual Studio, Win32, Windows, and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries Other product and company names mentioned herein may be the trademarks of their respective owners The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred Acquisitions Editor: Kathy Harding Project Editor: Jean Trenary Technical Editor: Bob Willer Body Part No X08-85375 About This Book Welcome to MCAD/MCSD Training Kit��Developing XML Web Services and Server Components with Microsoft Visual Basic NET and Microsoft Visual C# NET .NET is a new Microsoft technology that offers new application frameworks such as Web services, ASP.NET, WinForms, and ADO.NET This revolutionary component technology simplifies development and deployment of components By completing the lessons and exercises in this book, you will be able to build XML Web services and server components This book also addresses the objectives of the Microsoft Certified Professional Exam 70-310 and Exam 70-320 For more information about becoming a Microsoft Certified Application Developer (MCAD) or a Microsoft Certified Solution Developer (MCSD), see "The Microsoft Certified Professional Program" section later in this introduction The "Getting Started" section of this introduction provides important setup instructions that describe the hardware and software requirements to complete the procedures in this course It also provides information about installing or accessing the material provided on the Supplemental Course Materials CDROM Read through this section thoroughly before you start the lessons Intended Audience This book was created for software developers who need to design, plan, implement, and support XML Web services and server components or who plan to take the following related Microsoft Certified Professional exams Developing XML Web Services and Server Components with Microsoft Visual Basic NET and the Microsoft NET Framework (MCP Exam 70310) Developing XML Web Services and Server Components with Microsoft Visual C# NET and the Microsoft NET Framework (MCP Exam 70320) Prerequisites This course requires that students meet the prerequisites that follow Be able to create Windows applications using Microsoft Visual Studio NET in either the Visual Basic NET or Visual C# NET programming language Have a basic understanding of the object-oriented programming concepts including classes, properties, methods, and events Be familiar with Windows-based, Web-based, and console-based application development and deployment Have a basic knowledge of COM programming Understand how Web content is stored and accessed over the Internet This includes being able to explain the roles of Web servers, Internet protocols, and Web clients (such as browsers) Be familiar with XML and related technologies such as XPath and XSD Reference Materials You might find the following reference materials useful The Visual Studio NET online Help The Microsoft Developer Network (http://msdn.microsoft.com) W3C Recommendations for XML and Web Services (http://www.w3c.org) The XML Web Services Developer Center (http://msdn.microsoft.com/webservices) About the CD-ROM The Supplemental Course Materials CD-ROM contains a variety of informational aids that can be used throughout this book eBook A complete electronic version of this training kit Completed labs Each chapter in this book concludes with a lab containing a series of exercises that reinforce the skills you learned Completed versions of these applications are included so that you can compare your results You can also use the completed applications as a reference if you need help while completing an exercise Sample exam questions To practice taking a certification exam, you can use the sample exam questions provided on the CD-ROM The sample questions help you assess your understanding of the concepts presented in this book About the DVD The DVD contains a 60-day evaluation edition of Microsoft Visual Studio NET Professional Edition The 60-day evaluation edition provided with this training kit is not the full retail product and is provided only for the purposes of training and evaluation Microsoft Technical Support does not support this evaluation edition For additional support information regarding this book and the CD-ROM and DVD (including answers to commonly asked questions about installation and use), visit the Microsoft Press Technical Support Web site at http://www.microsoft.com/mspress/support You can also e-mail tkinput@microsoft.com or send a letter to Microsoft Press, Attn: Microsoft Press Technical Support, One Microsoft Way, Redmond, WA 98052-6399 Features of This Book Each chapter contains sections that are designed to help you get the most educational value from the chapter Each chapter opens with a "Before You Begin" section, which prepares you for completing the chapter The chapters are then divided into lessons Each lesson contains the reference and procedural information used for a specific skill or skills The "Summary" section identifies the key concepts from the lesson The "Lab" section provides hands-on exercises that reinforce the skills taught in each of the chapter lessons The exercises offer step-by-step procedures that give you an opportunity to use the skills being presented or explore the part of the application being described Appendix A, "Questions and Answers," contains all of the questions asked in each chapter review and the corresponding answers Notes Several types of notes appear throughout the lessons Notes marked Tip contain explanations of possible results or alternative methods for performing tasks Notes marked Important contain information that is essential to completing a task Notes marked Note contain supplemental information Notes marked Caution contain warnings about possible loss of data Notational Conventions The following notational conventions are used throughout this book Characters or commands that you type appear in bold type Italic in syntax statements indicates placeholders for variable information Italic is also used for book titles and to indicate newly introduced terms Names of files and folders appear in initial capital letters except when you are to type them directly Unless otherwise indicated, you can use lowercase letters when you type a file name in a dialog box or at a command prompt File name extensions, when they appear without a file name, are in lowercase letters Acronyms appear in all uppercase letters Monospace type represents code samples Square brackets [ ] are used in syntax statements to enclose optional items For example, [filename] in command syntax indicates that you can choose to type a file name with the command Type only the information within the brackets, not the brackets themselves Braces { } are used in syntax statements to enclose required items Type only the information within the braces, not the braces themselves Icons represent specific sections in the book as follows: Icon Represents Supplemental course materials You will find these materials on the Supplemental Course Materials CD-ROM A hands-on practice You should perform the practice to give yourself an opportunity to use the skills being presented in the lesson Chapter review questions These questions at the end of each chapter allow you to test what you have learned in the lessons You will find the answers to the review questions in Appendix A, "Questions and Answers," at the end of the book Chapter and Appendix Overview This self-paced training kit combines notes, hands-on procedures, and review questions to teach you how to develop XML Web services and server components with Visual Studio NET It is designed to be worked through from beginning to end, but you can choose a customized track and complete only the sections that interest you (See the next section, "Finding the Best Starting Point for You," for more information.) If you choose the customized track option, see the "Before You Begin" section in each chapter Any hands-on procedures that require preliminary work from preceding chapters refer to the appropriate chapters The book is divided into the following sections and chapters This "About This Book" section contains a self-paced training overview and introduces the components of this training kit Read this section thoroughly to get the greatest educational value from this self-paced training and to plan which lessons you will complete Chapter 1, "Understanding the NET Framework," introduces the fundamentals of the Microsoft NET Framework, which is the infrastructure for developing highly distributed applications for the Internet The chapter discusses the role of the common language runtime in the NET Framework, the difference between managed and unmanaged program execution, and the use of assemblies in application deployment and configuration In addition, the chapter describes how to use the tools that the NET Framework provides for creating, deploying, and managing applications Chapter 2, "Creating and Managing Windows Services," explains the Windows service programming model and includes sections on the creation of Windows services in Microsoft Visual Studio NET and the mechanisms used to control the behavior of Windows services You learn to make entries in default event logs, create custom event logs, and record information in custom event logs You also learn to configure a service dynamically and manage a service manually and programmatically Chapter 3, "Creating and Consuming Serviced Components," describes the serviced components that enable access to COM+ services, such as automatic transaction management, object pooling, and just-in-time (JIT) activation You learn about the basics of the COM+ programming model, create and register serviced components, utilize COM+ services, and manage serviced components using the Component Services tool Chapter 4, "Creating and Consuming NET Remoting Objects," demonstrates the use of the NET Framework to establish communication between objects without having to know about the protocols or the encoding and decoding mechanisms involved in the development of a distributed application You learn to create, configure, and secure NET Remoting objects using the classes provided by the NET Framework Chapter 5, "Database Programming Using ADO.NET," shows you how to use ActiveX Data Objects (ADO) for the NET Framework In this chapter, you learn to use the NET data providers, and create and use ADO.NET DataSets In addition, you learn to manage and control data using Data�Reader and DataAdapter objects Chapter 6, "Accessing and Manipulating XML Data," explains the importance of XML as the core to data exchange between applications in the NET Framework This chapter discusses the XML Document Object Model (DOM) and shows how to access XML data in applications You learn how to read and write data from XML documents, perform queries on XML documents, and validate XML documents with the XML Schema In addition, you learn to populate a DataSet with data from an XML file and write data from a DataSet into an XML file Chapter 7, "Creating and Consuming XML Web Services," shows you how to build scalable, loosely-coupled, platform-independent applications XML Web services enable disparate applications to exchange messages using standard protocols such as HTTP, XML, XSD, SOAP, and Web Services Description Language (WSDL) Chapter 8, "Advanced XML Web Services Programming," explains how to control characteristics of Web methods using attributes In addition, you learn to create and use SOAP extensions and create asynchronous Web methods Chapter 9, "Testing and Debugging XML Web Services," shows how to debug XML Web services and serviced components You also learn how to use tracing and perform code instrumentation Chapter 10, "Deploying XML Web Services and Windows Services," explains the deployment options that the NET Framework provides You learn to create setup programs that allow you to install your NET applications In addition, you learn to implement versioning and sideby-side deployment Visual Basic NET, you use the attribute to create a Web method Which file contains configuration information, such as debug mode? The Web.config file contains configuration information, such as the debug mode and the authentication mode for a Web project It also includes information about whether to display custom errors for a Web project 10 Which file allows you to handle application-level events? The Global.asax file enables you to manage application-level events This file resides in the root directory of an ASP.NET Web application or ASP.NET Web service The Global.asax.cs or Global.asax.vb class file is a hidden, dependent file of Global.asax, which contains the code for handling application events such as the Application_OnError event Chapter 8: Advanced XML Web Services Programming Review Questions Which property of the WebMethod attribute allows you to maintain the state of objects across sessions in a Web method? The EnableSession property of the WebMethod attribute allows you to enable session state for a Web method What steps do you need to perform to enable transactions in a Web method? To enable transactions in a Web method, you need to perform the following steps: Add a reference to the System.EnterpriseServices.dll by using the �Solution Explorer Include the System.EnterpriseServices namespace in the XML Web service project Set the TransactionOption property to an appropriate value When should you use asynchronous programming? You should use asynchronous programming when your application calls a method on an object that takes significant time to execute and you do not want the program to wait for the method to return Explain how you implement asynchronous programming using callbacks A client calls the Begin method on the server object and passes a reference to the callback method When the asynchronous method finishes execution, the server object calls the callback method on the client object The callback method in turn calls the End method on the server object The End method returns a value to the client Which method do you call for the first time when you access an XML Web �service or service method with which the SOAP extension is configured to �execute? You call the GetInitializer method the first time when you access an XML Web service or service method with which the SOAP extension is configured to execute What are the different properties of the XML element? Type, Priority, and Group are the three properties of the XML element The Type property of the element represents the type of SOAP extension The Priority property represents the relative priority of the SOAP extension within a group The Group property represents the group name to which the SOAP extension belongs Which element in the Web.config file do you use to manage custom error �messages? You use the element to manage custom error messages You can set the mode attribute to On or RemoteOnly to enable custom error messages, and Off to disable the error messages How can you ensure that only authorized users access your Web service? You can use the element to specify the users and roles that can access your Web service This element enables you to implement both positive and negative authorization assertions You can use this element to allow or deny access to your Web service based on specific users or roles Chapter 9: Testing and Debugging XML Web Services Review Questions What are the different approaches to testing? There are two different approaches to testing: the waterfall approach and the evolutionary approach Explain the waterfall approach The waterfall approach is a traditional approach in which each developer in the development team works in phases These phases cover requirement analysis, design and specifications requirements, coding, final testing, and release Explain the evolutionary approach In the evolutionary approach, you develop a modular piece or unit of application, test it, fix it, and then add another small piece that adds functionality You then test the two units as an integrated component, increasing the complexity as you proceed How does the Visual Studio NET debugger work? When you debug a Visual Studio NET application, the debugger first maps the native code to MSIL, and then maps the MSIL code to source code by using a PDB file What are the main windows and dialog boxes that you use to debug a Visual Studio NET application? The main windows and dialog boxes that you use to debug a Visual Studio NET application are the Visual Studio NET debugger window, Breakpoints window, Watch window, Call Stack window, Locals window, Autos window, and Processes window What is code instrumentation? Code instrumentation is a set of tasks that you perform to monitor and analyze information about the performance of your applications It involves activities such as writing tracing code for the application, collecting trace information, analyzing the trace output, and troubleshooting the problems that occur at run time How do you implement code instrumentation? You can implement code instrumentation by using tracing, debugging, performance counters, and event logs Which tool do you need to use to convert txt files to resources files? If you have text files as resources, then you can use the ResGen.exe tool to convert txt files to resources files The syntax for using the ResGen.exe tool is ResGen strings.txt myResources.resource Which tool do you need to use to compile the resources files into satellite assemblies? Once you have created resources files, you can compile them into satellite assemblies by using Al.exe, the Assembly Linker (AL) tool The AL tool creates satellite assemblies from the resources files that you specify As you know, satellite assemblies cannot contain any executable code and can contain only resources The following command shows you how to use the Al.exe tool to generate a satellite assembly: al /t:lib /embed:myResource.resources /culture:de /out:MyRes.resources.dll Chapter 10: Deploying XML Web Services and Windows Services Review Questions What are the deployment features of the NET Framework? The NET Framework provides the following deployment features: No-impact applications Private components Controlled code sharing Side-by-side versioning Xcopy deployment On-the-fly updates Integration with Microsoft Windows Installer Enterprise deployment Downloading and caching Partially trusted code What is the format of the assembly version stored in the AssemblyInfo file? The assembly version number is a four-part number The format of the version number is ... Which attribute do you use to specify the version number of an assembly? You use the AssemblyVersion() attribute to specify the version of an assembly What are Merge Module projects? Merge Module projects enable you to install and deploy components consistently Merge Module projects ensure that the correct version of a component is installed on the target computer A Merge Module project contains a component such as a DLL along with dependent files, resources, registry entries, and setup logic You cannot install merge modules directly The modules are merged with an msi file for each application that uses the component This ensures that the component is installed consistently for all applications, eliminating problems such as version conflicts, missing registry entries, and improperly installed files A merge module contains unique version information that the Windows Installer database uses to determine which applications can use the component, preventing the premature removal of a component Therefore, a new merge module is created for every incremental version of a component You should not update a merge module after including the module in an installer The deployment tools in Visual Studio NET make it easy to create Merge Modules and include them in installers for your applications What type of Setup project do you create to deploy XML Web services? To deploy XML Web services, you create a Web Setup project Which tools does the NET Framework provide to export types defined in an assembly to a type library? The NET Framework provides the Type Library Exporter (Tlbexp.exe) to export types defined in an assembly to a type library Which tool can you use to register managed types with the Windows registry? You can use the Assembly Registration Tool (Regasm.exe) to register managed types with the Windows registry What tasks does the common language runtime perform to locate and bind an assembly? The common language runtime performs the following tasks, in the order listed, to locate and bind to assemblies: Determines the correct assembly version Checks for the previously loaded assembly Checks the global assembly cache Locates the assembly through the codebase setting or probing Appendix B COM Interoperability The applications that you develop using the Microsoft NET Framework might contain managed as well as unmanaged code Managed code executes inside the common language runtime, and the garbage collection process manages the allocation and deallocation of memory for managed objects Unmanaged code runs outside the common language runtime and does not benefit from garbage collection The NET Framework and Microsoft Visual Studio NET enable you to create applications that access managed as well as unmanaged objects The interoperability that the NET Framework provides between managed and unmanaged code enables NET components to call methods on COM components and vice versa You can enable COM components to access managed components by exporting the types from a NET assembly to a COM type library For a detailed discussion on exporting and registering managed components to make them accessible to COM objects, refer to Chapter 10, "Deploying XML Web Services and Windows Services." Accessing COM Components from Managed Code COM types are defined in type libraries Type libraries contain information, such as member names and data types of COM objects, that you need to create an �application However, the structure of type libraries is different from the structure of NET assemblies Therefore, you cannot directly use the type definitions from a type library in your NET application Before you can use COM types in your applications, you need to import the type information from a COM type library into a NET assembly The resulting assembly containing the definitions of COM types is called an interop assembly You can use the types from an interop assembly in your managed code in the same way that you use types from a NET assembly The following sections explain how to access a COM object from managed code Create a COM Type Library The following code shows the Microsoft Visual Basic 6.0 code that is compiled to create the Math.dll file Visual Basic 6.0 Public Function Add(ByVal number1 As Integer, ByVal nu As Integer Add = number1 + number2 End Function Public Function Subtract(ByVal number1 As Integer, ByV As Integer) As Integer Subtract = number1 - number2 End Function Public Function Multiply(ByVal number1 As Integer, ByV As Integer) As Integer Multiply = number1 * number2 End Function Public Function Divide(ByVal number1 As Integer, ByVal Integer) As Integer Divide = CInt(number1 / number2) End Function Create an Interop Assembly from the Type Library You can create an interop assembly by using either Visual Studio NET or the Type Library Importer (Tlbimp.exe) tool To create an interop assembly using Visual Studio NET, you would do the following: Install the COM DLL and register the type library on your computer The following command, executed from the command prompt, registers the types in the Math.dll file: Regsvr32 Math.dll In the Solution Explorer, right-click References under your project, and choose Add Reference from the shortcut menu to open the Add Reference dialog box In the Add Reference dialog box, select the COM tab Select the type library from the list of references, or click Browse to locate the tlb or dll file containing the type definitions Click OK Visual Studio NET creates an interop assembly and adds it to the list of referenced assemblies The Type Library Importer (Tlbimp.exe) is a command-line tool that converts the co-classes and interfaces in a COM type library to metadata You can use this tool to create an interop assembly and a namespace for all the types in a COM type library The following command creates an interop assembly for the types contained in Math.dll: tlbimp Math.dll The interop assembly created by the preceding command also has the name Math.dll To create an interop assembly with a different name, such as InteropMath.dll in this example, use the following command: tlbimp Math.dll /out:InteropMath.dll After creating the interop assembly, you need to add a reference to the new assembly in your project To add a reference to the interop assembly in your project in Visual Studio NET, perform the following steps: In the Solution Explorer, right-click References under your project, and choose Add Reference from the shortcut menu to open the Add Reference dialog box From the NET tab, click Browse, and select the dll file containing the interop assembly Click OK After adding a reference to the interop assembly in your project, you can use the COM types in your managed code Creating COM Objects in Managed Code After you create the interop assembly InteropMath.dll and add the reference to your project, you can create an instance of the COM type in your managed code as shown in the following code Visual Basic NET ' Namespace that contains the types imported from COM Imports InteropMath Module COMInterop Sub Main() Dim obj As New Math() Console.WriteLine("Sum of 10 and 20 is " & _ obj.Add(10, 20).ToString) Console.WriteLine("Difference between 10 and 2 obj.Subtract(10, 20).ToString) Console.WriteLine("Product of 10 and 20 is " & obj.Multiply(10, 20).ToString) Console.WriteLine("Result of 20/10 is " & obj 10).ToString) Console.Read() End Sub End Module Visual C# // Namespace that contains the types imported from COM using InteropMath; using System; class COMInteropDemo { [STAThread] static void Main(string[] args) { Math obj=new Math(); Console.WriteLine("Sum of 10 and 20 is " + obj 20).ToString()); Console.WriteLine("Difference between 10 and 2 + obj.Subtract(10, 20).ToString()); Console.WriteLine("Product of 10 and 20 is " + 20).ToString()); Console.WriteLine("Result of 20/10 is " + obj 10).ToString()); Console.Read(); } } You can then build your application and run it to view the output of the application The output of the preceding code appears as shown here About This eBook This eBook has been converted from the print version of this title Every effort has been made to ensure the accuracy of this conversion For readability and accessibility reasons, the eBook version may contain differences in formatting from the original print version The content of the eBook is not updated to reflect any content changes made for reprint releases Figures and Images The figures and screen shots throughout the book are converted to electronic format as 1:1 images The eBook uses Microsoft� Internet Explorer to shrink the images down to fit within the content pane To see the larger 1:1 image, simply click on the image The 1:1 image will open in a separate window If you click on more than one image to view the 1:1 image, each image will open in a separate window, and remain open until that window is closed Search The CHM format allows full-text searching to better locate the information you need To conduct a search, open the eBook and click the Search tab In the Search Topics text box, type the word or topic on which you wish to search Click List Topics to display the search results To view a search result, either a) double-click on the result in the Select Topic list, or b) click on the result in the Select Topic list, and click Display The topic will then display in the content pane Search results are ranked by the number of times the words searched on occur within the topic results The highest-ranked topic will include the most references to the search criteria For advanced search options, open the drop-down list next to the search input box to clarify multiple search terms with the parameters AND, OR, NEAR, or NOT Favorites To save a topic for viewing later, select the topic so that it displays in the content pane Select the Favorites tab The topic title, or heading, will appear in the Current Topic box Click Add and the topic title will appear in the Topics pane To view a topic saved in Favorites, select the title, and click Display To remove a Favorite topic at any time, select it from the topic pane, and click Remove External Links This eBook may contain links to Web sites outside of the Microsoft domain All hyperlinks within the text were valid at the time this eBook was published Due to the nature of the World Wide Web, we cannot guarantee that all links to Web sites are still valid after the release date of the eBook Accessibility This eBook utilizes Internet Explorer to display content Internet Explorer offers many accessibility features, such as keyboard shortcuts and compatibility with Assistive Technology To find out more about accessibility within Internet Explorer, go to www.microsoft.com/enable/products and select the version of Internet Explorer installed on your computer Tell Us What You Think We need to hear from you regarding your experience with our eBooks Tell us what you like, don't like; which features you use, and which features you would like to see in future versions of our eBooks Send your comments to epublish@microsoft.com Please note that technical support is not offered through this alias About Microsoft Press Microsoft Press� is a division of Microsoft Corporation and the leading source of comprehensive self-paced learning, training, evaluation, and support resources to help everyone from developers to IT professionals to end users get the most from Microsoft technology Choose from hundreds of current titles in print, multimedia, and network-ready formats—learning solutions made by Microsoft, with the most timely and accurate information available For more information, visit www.microsoft.com/mspress ... The following tables provide a list of the skills measured on certification Exam 70- 310, Developing XML Web Services and Server Components with Microsoft Visual Basic NET and the Microsoft NET Framework, or Exam 70- 320, Developing XML Web Services and Server Components with Microsoft Visual C#... Chapter 9, "Testing and Debugging XML Web Services, " shows how to debug XML Web services and serviced components You also learn how to use tracing and perform code instrumentation Chapter 10, "Deploying XML Web Services and Windows Services, "... implement, and support XML Web services and server components or who plan to take the following related Microsoft Certified Professional exams Developing XML Web Services and Server Components with Microsoft

Ngày đăng: 25/03/2019, 16:34