Sie sind auf Seite 1von 7

Winter 2012

Master of Computer Application (MCA) Semester 5 MC0081 . (DOT) Net Technologies


Describe the steps involved in creating classes and objects with the help of a program in C#. Answer : Defining a Class A class is the most powerful data type in C#. Like structures, a class defines the data and behavior of the data type. Programmers can then create objects that are instances of this class. Unlike structures, classes support inheritance, which is a fundamental part of object-oriented programming. Declaring class Public class customer { // fields ,properties and methods go here } example public class Person { // Field public string name; // Constructor that takes no arguments. public Person() { name = "unknown";} // Constructor that takes one argument. public Person(string nm) { name = nm;} // Method public void SetName(string newName) {name = newName;} } class TestPerson { static void Main() { // Call the constructor that has no parameters. Person person1 = new Person(); Console.WriteLine(person1.name); person1.SetName("John Smith");

Console.WriteLine(person1.name); // Call the constructor that has one parameter. Person person2 = new Person("Sarah Jones"); Console.WriteLine(person2.name); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey();}} // Output: // unknown // John Smith // Sarah Jones 2. Describe the following with respect to creating Web Forms in .Net environment: a. Web Form Life Cycle b. Creating a Web Form Write programs with corresponding output screens to demonstrate the above concepts. Answer :a. Web Form Life Cycle Every request for a page made from a web server causes a chain of events at the server. Theseevents, from beginning to end, constitute the life cycle of the page and all its components. The life cycle begins with a request for the page, which causes the server to load it. When therequest is complete, the page is unloaded. From one end of the life cycle to the other, the goal is to render appropriate HTML output back tothe requesting browser. The life cycle of a page is marked by the following events, each of which you can handle yourself or leave to default handling by the ASP.NET server: Initialize Load ViewState Process Postback Data Load Send Postback Change Modifications Handle Postback Events PreRender Save State Render Dispose

b. Creating a Web Form To create the simple Web Form that will be used in the next example, start up Visual Studio .NETand open a New Project named Programming CSharpWeb . Select the Visual C# Projects folder (becauseC# is your language of choice), select ASP.NET Web Application as the project type, and type in its name, Programming CSharp Web. Visual Studio .NET will display http://localhost/ as the default location.

When you create a new Web Form application, Visual Studio .NET will generate a bitof boilerplate code to get you started
Q3. Design a simple Window based form application to perform basic arithmetic operations.

Answer : 3. Design a simple Window based form application to perform basic arithmetic operations We have to write the following code in the .cs file using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Formnamespace Calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string i, j; static char c; private void btnthree_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(3); } private void btnone_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(1); } private void btntwo_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(2); } private void btnfour_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(4); } private void btnfive_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(5); } private void btnsix_Click(object sender, EventArgs e)

{ textBox1.Text += Convert.ToString(6); } private void btnseven_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(7); } private void btneight_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(8); } private void btnnine_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(9); } private void btnzero_Click(object sender, EventArgs e) { textBox1.Text += Convert.ToString(0); } private void btnplus_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '+'; } private void btnminuse_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '-'; } private void btnmultiply_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '*'; } private void btndivide_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '/'; }

private void btnmodulo_Click(object sender, EventArgs e) { i = textBox1.Text; textBox1.Text = ""; c = '%'; } private void btnequal_Click(object sender, EventArgs e) { j = textBox1.Text; calclocalhost.CalcWebService obj = new calclocalhost.CalcWebService(); textBox1.Text = obj.calculate(i, j, c); } } } Run the application. Output:

Q4) Describe the following with respect to State Management in ASP.Net: a. Cookies in ASP.NET b. Session State c. Application State Answer : a. Cookies in ASP.NET Cookies provide a means in Web applications to store user-specific information. For example, when auser visits your site, you can use cookies to store user preferences or other information. When the uservisits your Web site another time, the application can retrieve the information it stored earlier.A cookie is a small bit of text that accompanies requests and pages as they go between the Web serverand browser. The cookie contains information the Web application can read whenever the user visits the site . You can add cookies to the Cookies collection in a number of ways. b. Session State

.ASP.NET session state is enabled by default for all ASP.NET applications. ASP.NET sessionstatevariables are easily set and retrieved using the Session property, which stores session variable values as acollection indexed by name. For example, the following code example creates the session variablesFirstName and LastName to represent the first name and last name of a user, and sets them to valuesretrieved from TextBox controls. C# Code Session["FirstName"] = FirstNameTextBox.Text; Session["LastName"] = LastNameTextBox.Text; c. Application State Application state is a data repository available to all classes in an ASP.NET application.Application state is stored in memory on the server and is faster than storing and retrieving information ina database. Unlike session state, which is specific to a single user session, application state applies to allusers and all sessions. Therefore, application state is a useful place to store small amounts of often-useddata that does not change from one user to another. The following example shows an object declaration foran application state value:<object runat="server" scope="application" ID="MyInfo"PROGID="MSWC.MYINFO"></object>.
Q5. Describe the following with respect to Web Services in .Net: a. Writing and Testing a Web Service b. Implementing a Web Service Client ans : a. Writing a Web Service

The ASMX file shown in Figure 8.5 is a complete Web service. It implements two Web methods: Add and Subtract. Both take two integers as input and return an integer as well. Deploying the Web service is as simple as copying it to a directory on your Web server that is URL-addressable. If you put Calc.asmx in wwwroot, the Web services local URL is http://localhost/calc.asmx. Calc.asmx demonstrates several important principles of Web service programming using the .NET Framework: Web services are implemented in ASMX files. ASMX is a special file name extension registered to ASP.NET (specifically, to an ASP.NET HTTP handler) in Machine.config. ASMX files begin with @ WebService directives. At a minimum, the directive must contain a Class attribute identifying the class that makes up the Web service. Web service classes can be attributed with optional WebService attributes. The one in this example assigns the Web service a name and a description that show up in the HTML page generated when a user calls up Calc.asmx in his or her browser. The WebService attribute also supports a Namespace parameter that can be used to change the name of the XML namespace that scopes the Web services members.
b. Implementing a Web Service Client Here are the steps: 1. Use Wsdl.exe to create a proxy class for Calc.asmx. If you installed Calc.asmx in wwwroot, the proper command is

wsdl http://localhost/calc.asmx Wsdl.exe responds by creating a file named Calculator Web Service.cs. 2. Create a new text file named CalcClient.cs and enter the code . 3. Compile the CS files into a console application with the following command: csc CalcClient.cs "Calculator Web Service.cs" 4. Run CalcClient.exe. Q6. Describe the following with respect to Web site deployment in ASP.Net: a. Creating Application Pools (IIS 6.0)

b. Deploying ASP.NET Applications


Answer : a. Creating Application Pools (IIS 6.0) With IIS 6.0 running in worker process isolation mode, you can group Web applications into application pools. Application pools allow specific configuration settings to be applied to groups of applications, and the worker processes servicing those applications. Any Web directory or virtual directory can be assigned to an application pool. By creating new application pools and assigning Web sites and applications to them, you can make your server more efficient and reliable, and your other applications always available, even when the applications in the new application pool terminate. Guidelines for Creating Application Pools computer, create an individual application pool for each Web site. Use an account with the least user rights possible, such as Network Service in the IIS_WPG group. the same server with the production version of the application, separate the two versions into different application pools. This isolates the test version of the application. h its own unique set of properties, create a unique application pool for that application. Note: You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName

b. Deploying ASP.NET Applications Deploying ASP.NET Applications in IIS 6.0 (IIS 6.0) Microsoft Windows Server 2003 includes support for ASP.NET applications and the Microsoft .NET Framework version 1.1 with the operating system installation. This chapter describes how to deploy ASP.NET applications on a newly installed server running Internet Information Services (IIS) 6.0. Version 1.1 of the .NET Framework is installed with Windows Server 2003. Most ASP.NET applications run without modification on version 1.1 of the .NET Framework

Das könnte Ihnen auch gefallen