Está en la página 1de 21

An Introduction to

and

Visual Basic.net

Tem McGallagher April 2002

Contents
AN OVERVIEW OF THE VISUAL STUDIO.NET FRAMEWORK.........................3 .net Framework Components...........................................................................................3 Web Services...................................................................................................................4 User Interface...................................................................................................................4 Data and XML.................................................................................................................4 Base Class Library...........................................................................................................4 The Common Language Runtime....................................................................................5 System Namespace.............................................................................................................6 THE .NET IDE.........................................................................................................8 VISUAL BASIC.NET..............................................................................................9 Visual Basic.net Data Types..............................................................................................9 The System.Object Class...............................................................................................10 Garbage Collection in Visual Basic.net.........................................................................10 Object Oriented Programming in Visual Basic.net......................................................11 Visual Basic.net Classes Checking Account Sample..................................................11 Visual Basic.net A High Level Summary....................................................................13 The Framework..............................................................................................................14 Syntax............................................................................................................................14 Distribution of Applications..........................................................................................14 Data Access and XML...................................................................................................15 ACCESSING DATA WITH ADO.NET..................................................................16 XML in Visual Basic.net..................................................................................................18 ASP.NET AND WEB SERVICES.........................................................................20 A final note on ASP.net ...............................................................................................21 Web Services.....................................................................................................................21

Tem McGallagher

Page 2

11/16/2011

An overview of the Visual Studio.net Framework


Unless you have been living under a rock for the past year, you must have heard of .net (dot net) by now. What is .net? Is it a new operating environment? Is it a new language? Is it a new way of developing distributed applications? The answer is Yes: .net is all of these things and more. The .net world was created by Microsoft to allow users to have access to their information, files, or programs anywhere, anytime, and on any platform or device. When Microsoft introduced the first Windows operating system, it took application development and system design to a new level: multi-tasking. With each new version of Windows, multi-tasking has been driven more towards distributed processing and .net is the next step. Visual Studio.net has an entirely new, object-oriented framework. In this paper I will introduce you to some of features in Visual Studio.net, however, I will focus mostly on Visual Basic.net and draw some comparisons to its predecessor VB 6. The reader of this paper will not be able to start developing code in Visual Basic.net after reading, but should have a high-level view of the changes in Visual Basic.net and how they differ from previous versions. .net Framework Components
Framework, Languages and Tools
Visual Basic C++ C# ...

Common lanaguage specification

Web Services

User Interface Visual Studio .NET Data and XML

Base class library

Common language runtime

Figure 1 - An overview of the .net Framework

Tem McGallagher

Page 3

11/16/2011

As shown in Figure 1, Visual Basic sits at the top of the framework (along with the other languages in Visual Studio.net). Below that is the Common Language Specification (CLS). This specification is a set of rules that govern the minimum language features that must be supported to ensure that a language will interoperate with other CLScompliant components and tools. As long as a language conforms to the CLS, it is guaranteed to work with the CLR. In this way, when third-party compilers target the .net framework, as long as they conform to the CLS, the code is guaranteed to work. You might also notice that VB is now and equal or peer of C++, C# and any other language that is .net compliant. Visual Basic.net shares the same variable types, arrays, user-defined types, classes, graphical forms, visual controls and interfaces as these other languages. Web Services Web Services provide a Web-enabled user interface with tools that include various HTML controls and Web controls. Forms creating using Web Services are the same as forms created for a Windows application. The code behind a Web form is the same as the code behind a Windows form. The markup language that is used by Web forms is still there, but the Web form applications generate it for you. User Interface At the same level as Web Services is the User Interface. The User Interface is where Windows forms live. It also provides code for drawing to the screen, printing, rendering text and displaying images. Data and XML Both Web Services and the User Interface sit on top of the Data and XML block. As you will learn later in this paper, XML (or extensible markup language) plays just as important of a role as data. XML is used to provide a text view of data that can be shared between services on the same PC or passed through a firewall to a web server across the country using SOAP (more on SOAP a little later). Base Class Library The base class library (BCL) is underneath the Data and XML block. This area is the origin for the base class of all .net programs. Everything in Visual Basic.net is an object, and all objects originate from a class named System. The BCL also provides collections, localization, text objects, interoperability with non-.net code and ActiveX controls and a variety of other services.

Tem McGallagher

Page 4

11/16/2011

The Common Language Runtime At the base of the .net framework is the common language runtime (CLR). Much like the Java Virtual Machine, the CLR is needed to make .net code run on any machine.

Common Language Runtime


Base class library support

Thread support

COM marshaler

Type checker

Exception manager

Security engine

Debug engine

IL to native components

Code manager

Garbage Collector

Class loader

Figure 2 - Common Language Runtime services

The CLR is a set of resources that any .net program can take advantage of, from any .netsupported language. All languages will be more equal in capability than they ever have before. The CLR includes support for the BCL, where the architecture for controls and forms actually live. It is also responsible for managing threads and exceptions (replacing the Err object in VB 6). Garbage collection is also handled by the CLR. The CLR takes code generated by VB and converts it to the native language of the current platform. Through this conversion, the magic of multi platform execution is achieved. Now VB programmers can write code in VB syntax and the CLR is

Tem McGallagher

Page 5

11/16/2011

responsible for converting it to any platform that can run the CLR. The programmer is removed several layers from the hardware and doesnt really need to know what platform his/her code is running on. One additional service of the CLR is handling bad code. You have probably heard stories of rogue code that overran buffers and trashed a machine, killing all other programs along with it. By design, this cannot happen with code written in Visual Basic.net. System Namespace The System namespace includes all classes that represent the base data types used by all Visual Basic.net applications. In .net, all of the base data types are Object, Byte, Char, Array, and so on. Many of these correspond to the data type in classic VB. In addition to the base data types, the System namespace contains nearly 100 classes that provide functionality ranging from handling exceptions and forming delegates to dealing with the core run-time concepts such as application domains and the automatic memory manager. The System namespace also contains 25 second-level namespaces, listed in Table 1. Looking at these, you can see how the namespace convention logically separates functionality. Table 1 Secondary namspaces in the System Namespace Namespaces Description
System.CodeDom System.Collections System.ComponentModel System.Configuration System.Data System.Diagnostics Ssytem.DirectoryServices System.Drawing System.EnterpriseServices System.Globalization System.IO System.Management System.Messaging Contains classes that can be used to represent the elements and structure of a source code document. Contains interfaces and classes that define various collections of objects, such as lists, queues, arrays, hash tables and dictionaries. Provides classes that are used to implement and license components. Provides classes that give system run times, administrative tools, applications and other consumers of configuration information access to configuration information. Consists mostly of classes that constitute the Microsoft ADO.net architecture. Provides classes to debug applications and trace the execution of code. Provides access to Active Directory from manage code. Provides access to the GDI+ basic graphics functionality. Provides transaction-processing functionality. Provides localization information on elements such as the current culture, formatting, data, and time for specific locales. Provides types that allow synchronous and asynchronous reading from and writing to data streams and files. Provides classes for manager of system object and events. Provides classes to connect to message queues on the network, send messages to queues and receive or peek messages from queues.
Page 6 11/16/2011

Tem McGallagher

Namespaces
System.Net System.Reflection System.Resources System.Runtime System.Security System.ServiceProcess System.Text

Description
Provides a simple programming interface to many of the protocols found on the network today. Contains classes and interfaces that provide a managed view of types, methods and fields, with the ability to dynamically create and invoke types. Provides management of resources, such as a resource that contains culture-specific information. Provides infrastructure services, Provides the underlying structure of the .net framework security system, including interfaces, attributes, exceptions and base classes for permissions. Provides classes to install and run services (non-interface executables). Contains classes representing ASCII, Unicode, UTF-7 and UTF-8 character encoding; abstract base classes for converting blocks of characters to and from blocks of bytes; a helper class that manipulates and formats String objects without creating intermediate instances of String. Provides class and interfaces that enable multithreaded programming. Provides two components that raise an event on an interval or more complex schedule. Supplies classes and interfaces that enable browser-server communication. Contains classes for creating Windows-based applications and classes for many controls that can be added to forms. Contains XML classes that provide standards-based support for processing XML.

System.Threading System.Timers System.Web System.Windows.Forms System.Xml

Tem McGallagher

Page 7

11/16/2011

The .net IDE

Figure 3 - The .net IDE

One of the biggest improvements with .net, in my opinion, is the new common IDE. As you can see in Figure 3, the IDE contains a little of all the different classic Visual Studio languages. There is an output window similar to the one in C++, the properties window similar to the one in VB; but best of all are the slide-in capabilities of the different explorer windows. There is now a server explorer that slides-in from the left side of the IDE. This explorer allows the developer to have access to operating services, data connections, and best of all, SQL server. I cannot tell you how many times Ive wished that I could change a stored procedure or table design without having to load SQL Enterprise Manager to do so. With the .net IDE, all of the tools are found right in the same application. With the use of the thumb-tack, you can minimize explorers to gain more space for your code window if needed.

Tem McGallagher

Page 8

11/16/2011

Visual Basic.net
Now its time to take a look at Visual Basic.net, the main focus of this paper. I am going to assume that the reader is already at least familiar with writing applications using VB 6 or earlier. The intent of this paper is to point out what is new in Visual Basic.net and not how to develop applications using Visual Basic.net. Visual Basic.net Data Types Before we can get into the Visual Basic.net code, we need to start by exploring the changes to data types. Hopefully, you are not a programmer that insisted on using the Variant data type consistently in your codeif you did, you will have a more difficult time adjusting to the new data types in Visual Basic.net. The Variant data type no longer exists in Visual Basic.net. (Another data type that did not make the transition is the Currency type.) The primitive data types still exist (Integer, Boolean, Long, etc.), the main difference now is that these data types are all structure types in the System namespace and are referred to as Value Types. Value types are always accessed directly. In fact, you cant create a reference to a value type. And unlike reference types, setting a value type to Null is not possible. Value types always hold a value, even if one hasnt been assigned yet. When a value type variable is dimensioned, its initialized to a value representative of its type. For example, if you dimension a variable to Integer, the Visual Basic.net compiler automatically initializes the variable to 0. Consider the following VB 6 variable declaration:
Dim intValue As Integer

This code is still valid in Visual Basic.net, however, you can also do the following in Visual Basic.net:
Dim intValue As Integer = 5

Being able to dimension and set the value of a variable at the same time is a much welcome change. For you Java users out there, there are also some new features to the value types you are already familiar with: formatting and conversion. In VB 6, the Format() function and functions like CStr() or CInt() provided us with the means of converting between data types. Now, each data type has its own built in methods to handle conversion, equality checks (theres even a ToString() method in these structures.)

Tem McGallagher

Page 9

11/16/2011

A final note on data types: Visual Basic.net is a type-safe language (you can only access a variable through the type associated with that variable). We should be used to using Option Explicit in VB code to require variable declaration, but Visual Basic.net has a new directive called Option Strict. This new directive prevents you from trying to overwrite data with a different data type and should always be included at the top of your class and form code. The System.Object Class The System.Object class is much like the Object class in Java. The System.Object class is the super class of all classes the in .net frameworkits the only class in .net that does not inherit from any other object type. All objects must either explicitly or implicitly declare support for exactly one other object type. In .net it is impossible to use a class that does not inherit from System.Object. There are six methods inherited by all classes that come from the System.Object class, see Table 3 below. Table 3 Inherited Methods from System.Object Namespaces Access Description
Equals GetHashCode Public Public Takes another object as a parameter and returns a Boolean that indicates whether the two objects are equal. Returns an integer hash code that represents the objects value. This code is usually used as a key when the object is added to a collection. Two identical objects should generate the same code. The CLR calls an objects Finalize method to notify the object that the object is about to be destroyed. This method really does nothing and is overridden by the class. Creates a shallow copy of the object. Returns an instance of System.Type, which is used to get information about the object through metadata. Returns a string representation of the object.

Finalize

Protected

MemberwiseClone GetType ToString

Protected Public Public

Garbage Collection in Visual Basic.net In VB 6, when you were finished using an object, you simply set it to nothing and the object would be released. This is no longer the case with Visual Basic.net. In Visual Basic.net, when a variable loses scope, the CLR destroys the object and removes it from the stack automatically for you.

Tem McGallagher

Page 10

11/16/2011

Object Oriented Programming in Visual Basic.net Many people have asked for this for a long time and now Microsoft has delivered. As you may have guessed by now, the major difference in Visual Basic.net is that it is now truly object-oriented. Inheritance is one of the fundamental aspects of object-oriented programming. Through inheritance, you can derive classes from other classes that have already been written. Even a Windows form is now inherited, just look at the code at that begins each form: Public Class Form1 Inherits System.Windows.Forms.Form As you may know, when a class inherits from a base class, it inherits the properties and methods of that class (or its members). You can then use or add these members in your own class in whatever way you need. Visual Basic.net couldnt be truly object-oriented without polymorphism, which it of course has. Using the Windows.Forms.Form class an example: you create two Windows forms in your application, they both have a Close() method, but what the code does in each form can be different (an usually is). The point is that each form inherits from the Windows.Forms.Form class, but each has its own form (no pun intended). After all, the word polymorphism literally means many forms. One other change in Visual Basic.net that relates to OOP is method overloading. VB always had a sort of way of overloading functions or methods by using the Optional keyword in the function/method declaration. In Visual Basic.net (again, much like in Java), when you write a definition for a method/function, you can overload it with the different parameters as needed. Visual Basic.net Classes Checking Account Sample The following is a short example of a class written in Visual Basic.net. After the code, I will examine the features of the class. Code for the Checking class:
Option Strict On Imports System Namespace Accounts Public Class Checking Private m_strAcctName As String = "" Private m_strAcctNumber As String = "" Sub New() MyBase.New() End Sub

Tem McGallagher

Page 11

11/16/2011

Sub New(ByVal strAcctName As String, ByVal strAcctNumber As String) MyBase.New() m_strAcctName = strAcctName m_strAcctNumber = strAcctNumber End Sub Overridable Function Serialize() As Boolean If ((m_strAcctName <> "") And (m_strAcctNumber <> "")) _ Then Return True Else Return False End If End Function #Region "Account Properties" Property AccountName() As String Get AccountName = m_strAcctName End Get Set(ByVal Value As String) m_strAcctName = Value End Set End Property Property AccountNumber() As String Get AccountNumber = m_strAcctNumber End Get Set(ByVal Value As String) m_strAcctNumber = Value End Set End Property #End Region End Class End Namespace

Examining the Checking class and Accounts Namespace: Option Strict On To reiterate, this statement checks for possible problems in the code that would try to overwrite different data types (for example if: intI = strSomething). Imports System This imports the classes in the System Namespace.

Tem McGallagher

Page 12

11/16/2011

Namespace Accounts - Namespaces are used to group related types into a hierarchical categorization. Weve already explored the System namespace, Ive chosen to use Accounts for my namespace. Later, I may want to add a Savings account or a Money Market account class to the Accounts namespace that would have different properties. Public Class Checking Begins the definition of the class. Next, I declare private memory variables that assist me in data hiding. While these variables will hold the actual value of the Account Name and Account Number, the consumer of this class can only access these values by using the public methods. Sub New()- This is the default constructor for the class. You can see the I have overridden the New() constructor with one that will also allow the consumer to pass initial values to the class during construction. MyBase.New()- This must be the first line of code in the constructor methods. This calls the base-class constructor that the class is derived from (in this case it is System). Overridable Function Serialize() Because Visual Basic.net methods are not overridable by default you must explicity use the keyword Overridable for methods you want consumers to be able to override. Property AccountName()- The traditional Let/Set methods have been replaced in Visual Basic.net with Get/Set methods instead that are wrapped inside of the Property block. To actually implement this class in your Visual Basic.net code you would assign the class to a variable using the following code:
Dim clsChecking As New Accounts.Checking()

This calls the default constructor for the class. Then to set the properties of the class, you could do the following:
With clsChecking .AccountName = AmSouth Checking Account .AccountNumber = 53-11123221 End With

Visual Basic.net A High Level Summary As you can probably tell by now, there are a lot of things that are new with Visual Basic.net, but there are also some things that havent changed. One could easily write a

Tem McGallagher

Page 13

11/16/2011

book on this topic, but with this paper we will keep it on a high levelso lets review some of the major changes in Visual Basic.net. The Framework There are many goals of the .net framework, however, the main goal, and benefit, is that of the CLR. With the CLR, objects that are written in C++, C# and Visual Basic.net can all be used in any project that is targeted for the .net framework. If you are familiar with COM, a subject I havent touched on in this paper, its time to forget what you know COM no longer exists in .net (there is backward compatibility for ActiveX controls and DLLs, however, I would expect this to go away in future releases of .net). The Framework is meant to be the great equalizer. No longer do we, as programmers, have to worry about the underlying architecture/hardware were running on; if the PC meets the minimum requirements for the .net Framework, then your Visual Basic.net application should run without problem on that PC. Syntax Much of the syntax in Visual Basic.net has remained the same, however, as Ive already mentioned, everything in Visual Basic.net is now an object, even the data types. You can still use data types much the same as before, however, since they are now objects, the programmer has greater control and flexibility when manipulating them. Visual Basic.net is type-safe. Since the Variant data type no longer exists, you cannot simply assign the value of an Integer to a String for example; this will cause a runtime error. Using the Option Strict statement at the beginning of your code will help eliminate these types of errors because the compiler will catch them. Distribution of Applications This is a major, and very much welcome change, in Visual Basic.net. Today, when you create a VB 6 application that uses COM components, you have to remember to always package the COM components with your application. Furthermore, youd better make sure you are packaging the right version of the components or you will get trapped in DLL Hell! With Visual Basic.net, your target audience for the application must first install the .net Framework on their PC(s). Next, you simply create a folder and copy your application and any supporting files (help files, etc.) to that folder and youre finished. It really is that simple! When the user wants to uninstall your application, they simply delete the folder containing the application. There is no risk or worry of un-registering components or removing shared components that cause other applications to no longer function.

Tem McGallagher

Page 14

11/16/2011

Data Access and XML I will talk more about ADO.net in one of the following sections, but I did want to mention here that data access with Visual Basic.net and ADO.net has changed immensely. The RecordSet object no longer exists in ADO, instead we now use a DataSet object. The main idea behind the DataSet object is this: after you have defined all you need about the data source, you use a DataSetCommand object to connect to the data source and retrieve the data you want then disconnect from the data source. This frees up server resources because the server does not have to maintain as many concurrent connections. (This principle is much the same as using a disconnected recordset, but as youll see later, there are also other features in the DataSet object that disconnected recordsets cannot handle.) At the root of all data in .net is XML. I will explain later why XML is used and you will hopefully see the beauty of it. If you have ever developed distributed applications, or wanted to, .net gives you the tools to do this much easier than before. If you refer back to the table containing the System Namespace, youll see System.Xml at the end of the listi.e., one could also say that at the root of ALL things in .net is XML.

Tem McGallagher

Page 15

11/16/2011

Accessing Data with ADO.net


Data access with Visual Basic has come a long way in a relatively short period of time. After all, Microsoft released three versions of Visual Basic before database access was ever included. In VB 3, Microsoft introduced DAO (Data Access Objects), which used the Microsoft Jet Engine to connect to local databases. You could use DAO to connect to databases on a server, but the performance was poor because DAO was optimized for local access. Following DAO came RDO (Remote Data Objects) and then finally ADO (ActiveX Data Objects). These access technologies were designed with client/server in mind, but with the move away from a client/server to an n-tier approach to system design, something new was needed; enter ADO.net. As mentioned earlier, the Recordset object no longer exists in ADO.net. The successor, the DataSet object now gives us a look at all of the data. It can model data logically or abstractly, because unlike the RecordSet, the DataSet is not a container that can hold only rows of data. The DataSet can actually hold multiple tables and the relationships between them. Lets say for example you wanted to query data from two tables in a database that are joined together. In traditional ADO, you would execute a SQL query that placed the results in the RecordSet object. In ADO.net, using the DataSet object, the two tables themselves are placed in the data set and you then perform the needed query afterwards. The advantage of this method is not obvious, but what if there was some bit of detail in one of the tables your query left out? You would then, possibly, have to create another RecordSet to query the additional information you needed. Previous releases of ADO had support for XML, but it was crude at best. If you dont know what XML is by now, I suggest you start surfing or buy a good book on XML: its here to stay. For several years now, many businesses have been using XML to exchange data. The problem has been that both entities had to agree in advance on the format of the XML document, because there were not any languages that would give you an easy way to access XML data. Microsoft introduced the use of XML in ADO in version 2.1. The programmer could either save a recordset to XML and vice-versa; the trouble was that Microsoft defined the format of the XML and no other platforms had native support for it. Thanks to W3C, there is now a standard XML schema for recordsets and Microsoft uses this standard in ADO.net. I am not sure if other companies have yet adopted the standard, but you can be assured they will soon if they havent already. Figure 4 depicts data flow from a data source to a data consumer using ADO.net. First we connect to and retrieve tables from a relational database. The tables are each placed in an in-memory DataSet object using DataSetCommand objects. These DataSetCommand objects specify the tables (or a subset thereof) that we are interested in.

Tem McGallagher

Page 16

11/16/2011

After the DataSet is filled, the connection to the database is immediately closed. We can then build the relationship between the individual tables within the DataSet itself and send the data, via XML, to any client application.
Presentation Tier Windows Forms
MyApp.exe DataSet DataSet

Web Forms

Internet/Intranet

XML

Business Tier Data Object (Class)


DataSet

DataSetCommand

DataSetCommand

Data Tier

Database

Figure 4 - ADO.net data flow

Tem McGallagher

Page 17

11/16/2011

Table 4 below lists some of the differences between ADO and ADO.net. Table 4 A Comparison of ADO and ADO.net Features Feature ADO ADO.net
Memory-resident data Relationships between multiple tables Accessing data Use the Recordset object, which Uses the DataSet object, which can looks like a single table. contain one or more tables represented by DataTable objects. Requires the JOIN query to Supports the DataRelation object to assemble data from multiple associate row in one DataTable database tables in a single result object to rows in another DataTable table. object. Scans Recordset rows Permits non-sequential access to sequentially. rows in a table. Follows relationships to navigate from rows in one table to corresponding rows in another table. Provided by the Recordset Communicates to a database with object, but generally supports standardized calls to a connected access represented DataSetCommand object. by the Connection object. Communicates with a database with call to an OLE DB provider. Uses the connection object to Uses the strictly typed programming transit commands. characteristic of XML. Data is selfdescribing. Underlying data constructs such as tables and rows do not appear in the XML, making code easier to read and to write. Uses COM marshaling to Transmits a DataSet with an XML transmit a disconnected file. The XML format places no recordset. Supports only those restrictions on data types and data types defined by the COM requires no type conversion. standard. Problematic because firewalls are typically configured to prevent system-level requests such as COM marshaling of binary objects. Database locks and active database connections for long durations contend for limited resources. No problem because the ADO.net DataSet object uses text-based XML, which can pass through firewalls. Disconnected access to database data limits contention for limited database resources.

Disconnected access

Programmability

Sharing disconnected data between tiers or compon ents Transmitting data through firewalls Scalability

XML in Visual Basic.net You cannot do anything in Visual Basic.net without XML being involved somewhere. It may not be on the surface, but it is there in the underlying data. Chances are that if you
Tem McGallagher Page 18 11/16/2011

are only developing Windows applications for use on a single PC, you will not use XML very often; but if you want to query or update data from a remote data source (on the Internet or Intranet), you will need to understand what XML is and what it can do. And you will, of course, use ADO.net as the mechanism to do this.

Tem McGallagher

Page 19

11/16/2011

ASP.net and Web Services


Web Forms (the controls and classes .net provides for building Web pages) and Web Services (programmable application logic accessible by standard Internet protocols) are part of the framework for Internet functionality included in Visual Basic.net and are known under the umbrella of ASP.net. If you have worked with ASP (Active Server Pages) before, you will be surprised at how much different and more efficient ASP.net is. ASP.net encompasses a completely new programming object model. It replaces the VB 6 WebClasses and DHTML pages. Not only that, but the ASP.net programming model is also more consistent and easier to use. Some of the key features of ASP.net are: Language Independence. ASP.net allows you to use compiled languages, providing better performance and cross-language compatibility. Simplified development. ASP.net makes even the richest pages straightforward and easy to write. Separation of code and content. Each Web Form has a code module with the same name but with the extension .vb. This so-called code behind the page contains the program logic code, while the Web Form contains the visual components. Improved scalability. New session-state features make it easy to create Web Forms that work on Web server farms. Support for multiple clients. ASP.net controls can automatically detect the client and optimize themselves for a consistent look and feel. You no longer have to write separate code for different browsers. New Web Forms controls. The new controls can output HTML 3.2 for down-level browsers while taking advantage of the runtime libraries for enhanced interactivity on richer clients. Our programs can now output to a whole new range of platforms such as PDAs. Server-side processing. ASP.net changes each page into a server-side object. More properties, methods, and events can be used with your code to create content dynamically. The runat-server attribute converts the HTML element into a server-side control that is visible and therefore programmable within ASP.net on the server. Events raised by Web Form controls are detected and the appropriate code is executed on the server in response to these events.

Tem McGallagher

Page 20

11/16/2011

A final note on ASP.net ASP.net is written entirely in the new C# language. All ASP.net pages have the .aspx file extension, which allows both .asp and .aspx files to be run on the same machine under the existing ASP runtime. Web Services In very general terms, ASP.net pages are for human interaction with a Web server, and Web services are for programmatic interaction with a Web server. Web services are a general model for building applications that can be implemented for any operation that supports or requires communication over the Internet. DCOM (which stands for Distributed COM) has been around for a long time and is widely used today by many developers. DCOM allows us to distribute tiers or single components in an enterprise solution; problem is DCOM uses protocols that can only be shared between computers running Microsoft operating systems. Web services uses a new technology called SOAP (Simple Object Access Protocol), which doesnt rely on operating systems or network protocols but uses XML and HTTP to perform remote requests; thereby making it usable on non-Microsoft platforms as well. SOAP is basically a message exchange protocol that uses HTTP and XML. HTTP is used as the transport because it uses port 80 and practically any computer with Internet access is allowed in and out of a firewall using port 80. XML is used for formatting the messages. The key advantage of Web services is that is allows software companies to create services that can be marketed to other companies. Lets say, for example, weve been asked to develop a web site for our company, which does business in different parts of the world. Obviously there will be money conversions involved in this application. In order to keep up with the daily exchange rates, we would have to develop our own system that updates the exchange rates daily. But what if we instead used a Web Service provided by a bank? Each time we need an exchange rate, we simply make a request to the banks Web Service. The benefits of the scenario are obvious, but in addition to the obvious, is the fact that we have a guarantee from the bank that the rates are valid. There are already a number of businesses offering Web Services on the Internet. There is even an Internet based registry that can be searched for a usable Web Service. You can imagine that some of these services will be charged, while other may not (where its in the best interest of the business offering the service to provide it free of charge). Some authors are predicting that Web Services may very well become the new standard for B2B integration over the Internet.

Tem McGallagher

Page 21

11/16/2011

También podría gustarte