User:Foxall/23

Ka Wiktionary

Hour 23. Introduction to Web Development[wax ka badal]

Visual Studio .NET, more than any previous Microsoft technology, offers incredible Web development tools and functionality. In fact, .NET is very much about programming for the Web. Creating Web applications requires a thorough understanding of all the skills you've acquired in this book�and more. In addition to the complexities of programming that you've dealt with, such as creating forms, writing code, and so on, additional concerns exist, such as Web protocols, firewalls, Web servers, and scalability. Teaching you how to create Web applications is beyond the scope of this book. However, it's important that you're at least a little familiar with the concepts and technologies involved with Microsoft's .NET Internet programming strategy. This hour gives you an overview of the .NET Web programming technologies.

The highlights of this hour include the following:

  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch23lev1sec1.htm#ch23lev1sec1 XML]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch23lev1sec2.htm#ch23lev1sec2 SOAP (Simple Object Access Protocol)]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch23lev1sec3.htm#ch23lev1sec3 ASP.NET]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch23lev1sec4.htm#ch23lev1sec4 Web Forms]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch23lev1sec5.htm#ch23lev1sec5 XML Web services]

XML[wax ka badal]

XML (eXtensible Markup Language) is a universal format for transferring data across the Internet. On the surface, XML files are simply text files. However, this is oversimplifying things. The beauty in XML is that XML files themselves contain not only data, but self-describing information (metadata) about the data. The fact that XML files are text files makes it relatively easy to move them across boundaries (such as firewalls) and platforms.

graphics/newterm.gif Semantic tags are used to describe data in an XML file, and a starting and ending tag are used to define an element. The data between a starting and ending tag is the value of the element. Tags are similar to HTML tags and have the following format:
<tagname>data</tagname>

For example, you could store a color in an element titled BackColor, like this:

<BackColor>Blue</BackColor>

It's important to note that XML tags are case sensitive; therefore, BackColor is not the same as backcolor, and both elements could exist in the same XML file.

Elements can be nested as long as the starting and ending tags of elements don't overlap. For example, two customers could be stored in an XML file like this:

<Customer>
 <Name>John Smith</Name>
 <OrderItemID>Elder Scrolls: Morrowind</OrderItemID>
 <Price>$20.00</Price>
</Customer>
<Customer>
 <Name>Jane Aroogala</Name>
 <OrderItemID>Ultima VII: The Black Gate</OrderItemID>
 <Price>$62.00</Price>
</Customer>

XML files can be much more complex, but this simple example should suffice to show you that XML documents are text documents that can store just about any type of data you can think of. In fact, Microsoft is using XML in just about everything, from ADO.NET to XML Web services.

>

SOAP

To pass structured data across the Web (such as passing objects or calling methods on objects), the sender and receiver must agree on how the data will be transmitted. SOAP (Simple Object Access Protocol) is Microsoft's new protocol used to exchange structured data over the Web using an XML format. SOAP is lightweight (doesn't consume a lot of resources or bandwidth) and makes use of the widely accepted HTTP protocol. SOAP is fundamental to Microsoft's .NET strategy because it allows different applications on multiple platforms to share structured data and interoperate across the Web.

>

ASP.NET

ASP.NET is the next evolution of ASP (Active Server Pages). ASP.NET is a framework for creating applications that reside on a Web server and that are run from within a client browser. ASP.NET enables you to program Web-based client-server applications using tools and methodologies much like those used to create traditional applications.

ASP.NET solutions execute on a Web server running Microsoft Internet Information Server (IIS). Therefore, to create ASP.NET solutions, you'll need to have some knowledge of IIS.

In a nutshell, ASP.NET is used to dynamically generate Web pages by serving up Web Forms (discussed shortly). For example, you may create an e-commerce site where a user may choose to view all products by category. Using ASP.NET, you could dynamically build and display a Web page containing the appropriate list of products. The server would execute the code to build the new Web page and then send the page to the user's browser as an HTML document.

Web Forms 

Web Forms are similar to Windows Forms applications (which you've been creating and programming throughout this book). However, Web Forms are designed specifically to run in a browser over the Web. Although Web Forms are designed to run within any browser by default, you can target deployment to a specific browser to take advantage of a particular browser's features.

To create a Web Forms application, you choose ASP.NET Web Application on the New Project dialog box (see [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/23.htm#ch23fig01 Figure 23.1]). Be aware that to create and test a Web Forms application, you will have to have a Web server installed. If you don't have a Web server installed and configured, you'll receive a message similar to that shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/23.htm#ch23fig02 Figure 23.2], and you'll be prevented from creating the project.

Figure 23.1. A Web Forms project is different from a Windows Forms project.

graphics/23fig01.jpg

Figure 23.2. To create a Web Forms application, you will need to install and configure a Web server.

graphics/23fig02.gof

 Comparing Windows Forms to Web Forms 

Creating a Web Form application may offer many advantages. For example, to deploy a Web Form application, you have to deploy only to a Web server (not to all client machines). After it is set up on the server, users can run the program simply by pointing their browsers to the proper URL. Contrast this with the need to deploy a Windows Application to hundreds or thousands of users' computers. Another benefit of Web Forms is that applications are essentially platform independent because the code runs on the server and the browser is the only thing running on the client side. When deciding whether to make an application Windows-Forms based or Web-Forms based, consider the following.

 Deployment 

As mentioned previously, Windows applications built on Windows Forms are installed and executed on the user's machine. Web Forms, however, run within a browser and therefore do not require deployment to a client machine. Rather than having to install updates on every client as you do with a Windows Forms application, with a Web Forms application you need to update only the server (which must be running the .NET Framework).

 Graphics 

Windows Forms include the capability to interact with the Windows graphics device interface (refer to [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch10.htm#ch10 Hour 10], "Drawing and Printing," for information on the GDI) to create intricate graphics with excellent performance. Web Forms can access the GDI on a Web server. However, round-trips are required for screen updates, which can negatively affect the performance of drawing graphics.

 Responsiveness 

When an application requires a high degree of interactivity with the user (such as screen updates, lots of event code, and data validation), Windows Forms provide the best performance because they run on the client machine. Most interactive processes with Web Forms require round-trips to the server, which again can negatively affect the responsiveness of an application.

 Text Formatting and Control Positioning 

Windows Forms provide exceptional capability of placing controls (for example, Windows Forms support snapping to grids). Displaying text on a Windows Form, however, requires using controls such as a label or a text box. Making text flow on a Windows Form (such as flowing around other controls when adjusting to the sizing of a form) can be very difficult to accomplish. In addition, formatting text can be problematic because most controls support only one font at a time.

Web Forms, on the other hand, are served to clients as HTTP Web pages, which excel at formatting and flowing text. Web Forms aren't as precise as Windows Forms when it comes to placing controls, however.

 .NET Platform Installation 

To run a Windows Forms application, users must have the .NET Framework installed on their computer. Web Forms, however, are installed on the server; therefore, the .NET Framework must be installed on the server but isn't needed on the client. The client needs only a Web browser. It is important to note that future service packs of Windows will likely include the latest .NET Framework�but don't depend on this.

 Security and System Resources 

Windows Forms applications can have complete control over system resources such as the Registry and also may be restricted using the operating system's security features. Web Forms are restricted by the user's browser security settings and thus have very limited access to system resources.

>

XML Web Services

Perhaps the technology that Microsoft is most excited about in .NET is XML Web services. Microsoft describes an XML Web service as "a unit of application logic providing data and services to other applications." It's easiest to think of XML Web services as applications that reside on a server without a user interface, providing objects to clients. The following are a few practical examples of what can be done with XML Web services:

  • A company could create stock quote XML Web services that clients could use to get real-time stock quotes.
  • A doctor's office could expose scheduling functions so that clients could use their mobile devices to schedule appointments.
  • A government office could expose tax-related objects, which businesses could use to get accurate tax rates.
  • A company could expose data that is paid for by subscription. When clients access the data via the Web service's objects, a billing system could track the number of accesses.
  • An auction company such as eBay could expose its bidding system as authenticated XML Web services, and third-party vendors could create their own front ends to placing bids on the auction site.

Obviously, this list just scratches the surface. Microsoft ambitiously envisions everyone exposing application logic as XML Web services. Although this may not become a reality in the near future (indeed, XML Web services may never take off like Microsoft hopes), many companies are generating a lot of excitement about this technology.

As a programmer, a lot of the details of XML Web services are handled for you by .NET. For example, SOAP and XML are used to marshal objects and method calls across the Web so that you don't have to worry about the details of the plumbing. Because a standard protocol is used to marshal this information, you don't have to worry about the language or the platform used to implement the XML Web services�almost any type of client can consume XML Web services (C#, Visual Basic, Java, and so on). Clients don't even have to be Windows based or even be PCs; Web-enabled phones and other wireless devices can consume XML Web services.

Writing code to consume XML Web services is actually similar to writing code to access an Automation server. First, you create a Web reference, which is much like creating a reference to an Automation library such as Excel or ADO. After you've got a reference to the XML Web services, the objects become available in code, and you can browse them as you would "traditional" objects.

To create XML Web services, you have to have a sound understanding of creating objects by programming classes, and you have to learn ASP.NET�the underlying technology of XML Web services. The .NET Framework handles the details of using SOAP to allow clients to interact with your XML Web services, so you focus most of your attention on creating useful objects rather than on details of the underlying plumbing.

Programming for the Web is an exciting proposition, and one that can't be entered into lightly. To create robust Web applications requires an understanding of a lot of technologies, including Web servers, protocols, firewalls, security, object-oriented programming concepts, and much more. By completing this book, you're gaining a solid understanding of application development with C#, and you're building a set of skills that you can use to move into Web programming. If you're interested in Web development, you should consider purchasing a book dedicated to the subject, such as Sams Teach Yourself C# Web Programming in 21 Days.

Q&A[wax ka badal]

[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/23.htm#qad1e68577 Q1:] Can I use XML files within my applications?
A1: Yes, you can design your own XML files and use them any way you see fit. For example, you could save a configuration file in an XML file with a scheme you've designed. For more information, look at the documentation on System.Xml in the online Help.
>

Workshop

The Workshop is designed to help you anticipate possible questions, review what you've learned, and get you thinking about how to put your knowledge into practice. The answers to the quiz are in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01.htm#app01 Appendix A], "Answers to Quizzes/Exercises."

 Quiz
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans01 1:] What does XML stand for?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans02 2:] An element is designated in an XML document using the what?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans03 3:] True or False: XML tag names are case sensitive.
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans04 4:] What is the name of the protocol used by .NET to marshal object requests across the Web?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans05 5:] What forms engine is used to create forms that run over the Internet?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans06 6:] Which forms engine provides for faster response to user interaction?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans07 7:] Where is the .NET Framework installed for Windows Forms applications? Web Forms applications?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec23.htm#ch23ans08 8:] What is the name of the ASP.NET technology used to expose application logic as objects over the Web?