Sample Windows Forms Application in ASP.NET2.0.

Sample Windows Forms Application

Overview

This is a step-by-step user guide that explains how to create a simple Windows Forms Application that uses the Coherence for .NET library.

General Instructions

Developing and configuring a Windows Forms Application that uses Coherence for .NET requires five basic steps:

1.      Create a Windows Application in Visual Studio 2005.

2.      Add a reference in the Window Application .

3.      Create an App.config file.

4.      Configure the Coherence for .Net library.

5.      Create and design a Windows from.

6.      Example of the Window Application.

Creating a Windows Application Project

To create a new Windows Application, follow these steps:

1. Go to the File->New->Project... tab in Visual Studio 2005.

2. In the New Project window choose the Visual C# project type and Windows Application template. Enter the name, location (full path where you want to store your application), and solution for your project.


untitled1.bmp

  1. Click OK.

Visual Studio should have created the following files: Program.cs, Form1.cs and Form1.Designer.cs. The Solution Explorer in your project should now look like this:

untitled2.bmp

Next, rename these files if you wish. In this example they have been renamed to ContactCacheClient.cs, ContactForm.cs, and ContactForm.Designer.cs respectively.

Add a Reference.

Add the reference in the Window Application. In this Article, We are adding Add Web Reference.

  1. In your project go to Project->Add Reference... or right click on References in the Solution Explorer and choose Add Reference...

 

 untitled6.bmp

  1. In the Add Reference window and Show the Add Web Reference.
  2. File the URL in Add Web Reference and Click GO.
  3. And after that add reference click Your web services is add in your application .

 

 untitled4.bmp

  1. Click Cancel.

Creating an App.config File

To correctly configure the Coherence for .NET library, you must create an App.config XML file that contains the appropriate file names for each configuration file used by the library.

  1. Right-click the project in the Solution Explorer and choose the Add->New Item... tab.
  2. In the Add New Item window select the Application Configuration File.
    untitled7.bmp
  3. Click OK.

This is a sample of a valid App.config configuration file:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

</configuration>

In the <configSections>you must specify a class that handles access to the Coherence for .NET configuration section.

Create and Design the Application

Next, you must add controls to your Windows form. For this we're going to use buttons that will raise events when clicked, a couple of Textbox components for editing objects.

To add controls in your application follow these steps:

  1. Go to View->Toolbox.
  2. In the Toolbox window choose the controls you wish to use and drag them on the Windows form.
  3. For each control, right-click on it, choose Properties tab, and set the necessary properties.

When finished, your application should look like this:

untitled5.bmp 

 Example: -

This example used checks the valid Email Address and invalid Email Address from the database.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Net.Mail;

using System.Text.RegularExpressions;

using System.Configuration;

using System.Collections;

using System.Data.SqlClient;

 

namespace ValidEmail

{

    public partial class Form1 : Form

    {

        DataSet ds = new DataSet();

        SqlCommand cmd = new SqlCommand();

        SqlConnection con;

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection(@"Data Source=MCN-C2B848F240D\SQLSERVER2005; Initial Catalog=Data;Uid=sa; pwd=wintellect");

            ArrayList list_emails = new ArrayList();

            int i = 0;

            string email;

            con.Open();

            SqlCommand cmd = new SqlCommand("Select EmailAddress from EmailAddress", con);

            SqlDataReader read_Email = cmd.ExecuteReader();

            while (read_Email.Read())

            {

                email = read_Email.GetValue(i).ToString();

                list_emails.Add(email);

                net.webservicex.www.ValidateEmail cls = new ValidEmail.net.webservicex.www.ValidateEmail();

                bool result = cls.IsValidEmail(email);

            }

            read_Email.Close();

            con.Close();

        }

    }

}


And show the program.cs code: -

using System;

using System.Collections.Generic;

using System.Windows.Forms;

using System.Web.Services;

 

namespace ValidEmail

{

    static class Program

    {

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new Form1());

        }       

    }

}


App.config: -

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <configSections>

        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

            <section name="ValidEmail.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="true" />

        </sectionGroup>

    </configSections>

    <applicationSettings>

        <ValidEmail.Properties.Settings>

            <setting name="ValidEmail_net_webservicex_www_ValidateEmail"

                serializeAs="String">

                <value>http://www.webservicex.net/ValidateEmail.asmx</value>

            </setting>

        </ValidEmail.Properties.Settings>

    </applicationSettings>

</configuration>



Some View of Windows Forms Application:-

This sample application enables you to submit queries to, and return results from, the Live Search Web Service through an interactive Windows Forms application that exposes all the functionality available through the API. The source code, below, is well commented, and demonstrates how to configure requests and process responses from the search engine. You can modify this code to produce useful applications, or use it as a learning tool to better understand the API.

To set up the project in Microsoft Visual Studio .NET 2005

1.      Open Microsoft Visual Studio .NET 2005 and, from the File menu, choose New | Project. The New Project dialog box appears.

2.      In the Project types pane, choose Visual C# and then choose Windows.

3.      In the Templates pane, choose Windows Application.

4.      Type the name of the project, LiveSearchAPISample, in the Name text box and click OK. Visual Studio creates a new project.

5.      In the Solution Explorer, right-click References and, from the pop-up menu, select Add Web Reference.

6.      Type the following address in the URL text box:  http://www.webservicex.net/ValidateEmail.asmx.

7.      Click Go.

8.      In the Web reference name text box, type net.webreferencex.www and click Add Reference.

9.      Change the name of the form to form1.cs. Click OK to rename all references and save your work.

To add the source code to the project

1.      Replace the source code in the file form1.cs with the source code in the first Example section (Example, Part One). To do this:

    1. Click Copy Code to place the code in the Windows Clipboard.
    2. Open form1.cs from the Solution Explorer, place your cursor anywhere in the file, and press Ctrl + A.
    3. Press Ctrl + V to paste the code into the Visual Studio source file, overwriting the template-generated code.

2.      Replace the source code in the file form1.Designer.cs with the source code in the second Example section (Example, Part Two). To do this:

    1. Click Copy Code to place the code in the Windows Clipboard.
    2. Open form1.Designer.cs from the Solution Explorer, place your cursor anywhere in the file, and press Ctrl + A.
    3. Press Ctrl + V to paste the code into the Visual Studio source file, overwriting the template-generated code.

3.      Search for and replace the text YOUR_APP_ID_GOES_HERE with the AppID you generated from the Developer Provisioning System.

4.      Press F5 to run the application in Debug mode.

Requirements

  • Microsoft Visual Studio .NET 2005 or Microsoft Visual C# .NET 2005.
  • Internet connection.

Demonstrates

All functionality in the current release of the Live Search Web Service API in an interactive format.

Up Next
    Ebook Download
    View all
    Learn
    View all