Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdfxx Contents
PART VII PROFESSIONAL PROJECT – 6. . . . . . . . . . |
633 |
PROJECT 6 CREATING AN ATL SERVER APPLICATION . . . . . . . . . 635
Chapter 20 Introduction to ATL Server . . . . . . . . . . . . . . 637
|
What Is ATL Server? . |
. . . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 639 |
||
|
|
|
|
|
Y |
|
|
Request Handlers . |
. . . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 642 |
||
|
Other Features |
. . . |
. . . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 644 |
|
|
|
|
|
F |
|
|
|
Summary . . . |
. . . . |
. . . . |
. . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 646 |
|
|
|
M |
|
|
|
Chapter 21 |
Creating a Guest BookLApplication. . . . . . . . |
647 |
||||
|
|
A |
|
|
||
|
Case Study . . |
. . . . |
. . . . |
. . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 648 |
|
E |
|
|
|
||
|
Project Life Cycle . . |
. . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 648 |
||
|
T |
|
|
|
|
|
|
Creating the H ML Form-Based Interface . . . . . . . . . . . . . . |
. 651 |
||||
|
Creating the A L Server Application . . . . . . . . . . . . . . . . . . . |
. 652 |
||||
|
Understanding the GuestBook Project . . . . . . . . . . . . . . . . |
. 656 |
||||
|
Modifying the SRF . |
. . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 658 |
||
|
Form Handling |
. . . . |
. . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 659 |
|
|
Adding Methods to the Default Handler . . . . . . . . . . . . . . |
. 659 |
||||
|
Creating the Empty XML File |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 664 |
|||
|
Summary . . . |
. . . . |
. . . . |
. . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . |
. 665 |
PART VII |
PROFESSIONAL PROJECT – 7. . . . . . . . . . |
667 |
||||
PROJECT 7 |
CREATING WEB SERVICES . |
. . . . . . . . . . . . . . . . . |
669 |
|||
Chapter 22 |
Introduction to Web Services and |
|
||||
|
Related Technologies. |
. . . . . . . . . . . . . . . . . |
671 |
What Are Web Services? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672
Web Service Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
Related Technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
Web Services and XML . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
Web Services and SOAP . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
Team-Fly®
|
Contents |
xxi |
|
|
|
|
|
Web Service Description Language . . . . . . . . . . . . . . . . . . |
. 691 |
|
|
Universal Description, Discovery, and Integration (UDDI) |
. 692 |
|
|
.NET and Web Service Security . . . . . . . . . . . . . . . . . . . . . . |
. 693 |
|
|
Ensuring Web Service Security over the Internet . . . . . . . . |
. 693 |
|
|
Ensuring Web Service Security over an Intranet . . . . . . . . |
. 694 |
|
|
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. 696 |
|
|
Chapter 23 Creating a Web Service Using |
|
|
|
Managed Extensions . . . . . . . . . . . . . . . . . . |
697 |
|
Art-Shop Associates Program . . . . . . . . . . . . . . . . . . . . . . . . . . 698
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
The Product Table in the ArtShop Database . . . . . . . . . . . . 700
Creating the Basic Managed C++ Web Service . . . . . . . . . . 701
Modifying the Web Service . . . . . . . . . . . . . . . . . . . . . . . . . 704
Accessing Data Using the SQL Server.NET Data Provider . 709
Testing the Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
Building a Web Service Consumer Using Managed C++ . . . 714
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
Chapter 24 Creating a Web Service Using ATL Server. . . 725
Exchange Rate Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
Requirements Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Creating the Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Creating the Database, Table, and Stored Procedures . . . . . . 728
Creating the ATL Server Web Service . . . . . . . . . . . . . . . . . 730
Testing the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748
xxii Contents
PART IX PROFESSIONAL PROJECT – 8. . . . . . . . . . |
749 |
PROJECT 8 .NET ASSEMBLIES WITH MANAGED C++ AND .NET
INTEROPERABILITY WITH COM. . . . . . . . . . . . . . . . 751
Chapter 25 Overview of Assemblies, Manifests in .NET, |
|
and Interoperability with COM . . . . . . . . . . . |
753 |
Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
Types of Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755
Global Assembly Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
Benefits of Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758
Assembly Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
Contents of an Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . 760
Creating Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761
Assembly Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762
Public and Private Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
Assembly Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
Converting a Private Assembly into a Shared Assembly . . . . 766
Creating .NET Components . . . . . . . . . . . . . . . . . . . . . . . . . . 768
COM Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 768
COM Interop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
COM Callable Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
Runtime Callable Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771
Calling COM Objects from .NET . . . . . . . . . . . . . . . . . . . 772
Calling .NET Objects from COM . . . . . . . . . . . . . . . . . . . 775
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775
Chapter 26 Implementation of COM and .NET |
|
Interoperability . . . . . . . . . . . . . . . . . . . . . . |
777 |
Art-Shop – Creating a Login Component . . . . . . . . . . . . . . . . 778
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
Creating the Customer Table in the ArtShop Database . . . . . . . 781
Creating the Login Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . 782
Contents xxiii
Accessing Data Using the SQL Server .NET
Data Provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
Implementing the Methods . . . . . . . . . . . . . . . . . . . . . . . . . 785
Testing the Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 792
Chapter 27 Using COM+ Services from |
|
.NET Assemblies . . . . . . . . . . . . . . . . . . . . . |
793 |
Art-Shop Kiosks – Placing an Order . . . . . . . . . . . . . . . . . . . . 794 Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794
.NET and COM+ Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796 Using Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798 Creating the Database Tables . . . . . . . . . . . . . . . . . . . . . . . 798 Creating the ProcessOrder Assembly . . . . . . . . . . . . . . . . . . 799 Registering the ProcessOrder Component with
COM+ Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804 Testing the Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
PART X PROFESSIONAL PROJECT – 9. . . . . . . . . . 807
PROJECT 9 XML WITH VC++.NET . . . . . . . . . . . . . . . . . . . 809 Chapter 28 XML with VC++.NET . . . . . . . . . . . . . . . . . . . 811
New-Tech, Inc. – The Scenario . . . . . . . . . . . . . . . . . . . . . . . . |
812 |
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
813 |
Requirements Analysis and Design . . . . . . . . . . . . . . . . . . . |
813 |
Design of the Application . . . . . . . . . . . . . . . . . . . . . . . . . . |
814 |
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
815 |
XML in .NET–The .NET XML Classes . . . . . . . . . . . . . . . . . |
815 |
XmlTextReader Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
817 |
XmlValidatingReader Class . . . . . . . . . . . . . . . . . . . . . . . . |
817 |
XmlReader Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
817 |
xxiv Contents
XmlWriter Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
XmlDocument Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 820
XPathNavigator Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 822
XPathDocument Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823
Creating and Testing the Scheduler Application . . . . . . . . . . . . 823
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833
PART XI PROFESSIONAL PROJECT – 10. . . . . . . . . |
835 |
PROJECT 10 NETWORKING AND REMOTING IN VC++.NET . . . . . . . 837
Chapter 29 Implementing Networking . . . . . . . . . . . . . . 839
Introducing Network Programming . . . . . . . . . . . . . . . . . . . . . 840
Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841
IP Addresses and Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842
Developing a Network Application by Using VC++.NET . . . . . 843
The System.Net Namespace . . . . . . . . . . . . . . . . . . . . . . . . 843
The Socket Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843
The WebRequest Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
The IPAddress Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
The System.Threading Namespace . . . . . . . . . . . . . . . . . . . . . . 850
The Thread Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850
Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 852
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
Requirements Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869
Chapter 30 Introducing Remoting . . . . . . . . . . . . . . . . . 871
Introduction to .NET Remoting Architecture . . . . . . . . . . . . . . 872 Interprocess Communication . . . . . . . . . . . . . . . . . . . . . . . . 873 The .NET Remoting Framework – A Bigger Picture . . . . . . 874
Contents xxv
Remote Objects – Server Side . . . . . . . . . . . . . . . . . . . . . . . . . 874
Hosting Remote Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 875
Configuring Remote Objects . . . . . . . . . . . . . . . . . . . . . . . . 876
Passing Remote Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 877
Proxy Objects – Client Side . . . . . . . . . . . . . . . . . . . . . . . . . . . 880
Channel Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881
Working of Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882
Secured Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
Remoting Metadata and Configuration Files . . . . . . . . . . . . . . 884
Object Lifetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886
Chapter 31 Implementing Remoting . . . . . . . . . . . . . . . . 887
NJ Finances – The Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . 888
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 888
.NET Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 890
Creating the Remote Object Application . . . . . . . . . . . . . . . . . 891
Creating the Remote Server Application . . . . . . . . . . . . . . . 898
Creating the Client Application . . . . . . . . . . . . . . . . . . . . . 901
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913
PART XII APPENDIXES . . . . . . . . . . . . . . . . . . . . . |
915 |
Appendix A The .NET Vision and Goals . . . . . . . . . . . . . . 917
The Vision Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
Presentation Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 920
Business Logic/Application Layer . . . . . . . . . . . . . . . . . . . . 920
Data Access and Storage Layer . . . . . . . . . . . . . . . . . . . . . . 920
Architectural Shift in .NET . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
.NET Framework Design Goals . . . . . . . . . . . . . . . . . . . . . . . . 922
Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
Manageability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927
xxvi Contents
Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 932
Reliability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933
Scalability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935
Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936
Appendix B The .NET Server Family . . . . . . . . . . . . . . . . 939
Application Center 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . 941
BizTalk Server 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
Commerce Server 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
Content Management Server 2001 . . . . . . . . . . . . . . . . . . . 944
Exchange 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 945
Host Integration Server 2000 . . . . . . . . . . . . . . . . . . . . . . . 946
Internet Security and Acceleration Server 2000 . . . . . . . . . . 947
Mobile Information 2001 Server . . . . . . . . . . . . . . . . . . . . . 950
SharePoint Portal Server 2001 . . . . . . . . . . . . . . . . . . . . . . . 952
SQL Server 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
Appendix C Namespaces and Attributes . . . . . . . . . . . . . 957
The System Namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958
The System.Windows.Forms Namespace . . . . . . . . . . . . . . . . . 959
Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
Common Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
COM Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
IDL Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
ATL Server Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
OLE DB Consumer Attributes . . . . . . . . . . . . . . . . . . . . . . 963
Compiler Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963
|
Contents xxvii |
Appendix D Migrating Unmanaged Code to |
|
Managed Code . . . . . . . . . . . . . . . . . . . . . |
. . 965 |
Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. . . 966 |
Appendix E Basics of C# . . . . . . . . . . . . . . . . . . . . . . . |
. 975 |
Visual C# .NET – The Origin . . . . . . . . . . . . . . . . . . . . . . |
. . . 976 |
Introduction to C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. . . 977 |
Components of C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. . . 978 |
A Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. . . 990 |
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. . . 991 |
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. . . 993 |
This page intentionally left blank
Introduction
Goal of the Book
This book provides a hands-on approach to learning Visual C++ .NET. The book is aimed at readers with programming knowledge of earlier versions of Visual C++. These readers are assumed to be experienced application developers who have knowledge of developing applications using any of the earlier versions of Visual C++.
The book starts with a few overview chapters that cover the key concepts of MFC programming that remain unchanged in the new version of Visual C++ — VC++.NET. These chapters basically revisit the concepts of MFC programming with adequate sample applications.
A major part of the book revolves around professional projects. These multiple projects are based on real-life situations. These projects follow a simple to complex approach to cover specific subject areas and guide the readers in implementing their learning in practical scenarios. The projects range from simple projects, such as creating an MFC-based database-centric application and a GDI+ application using Managed C++, to complex projects, such as creating COM components, an ATL Server, class libraries, Web services, and projects illustrating the implementation of COM interoperability with .NET components, XML, networking, and remoting. These projects help readers to accomplish their goals by understanding the practical and real-life applications of Visual C++ .NET.
Apart from the overview chapters and the professional projects, this book also includes appendices. These appendices act as quick references to some of the additional concepts that will help a reader to know more about the .NET Framework and about C# (the new entrant to the .NET language family).
How to Use This Book
This book has been specifically organized to facilitate a good grasp of everything it covers. The various conventions used in the book include the following:
Analysis. The book incorporates an analysis of code, explaining what the code does and why, line-by-line.
Tips. Tips provide special advice or point out unusual shortcuts available using a particular product.