Web Service in ASP.Net (SOAP)

What is Web Service in ASP.net (SOAP)

  • SOAP is an XML-based messaging framework specifically designed for exchanging formatted data across the Internet, for example using request and reply messages or sending entire documents.
  • completely neutral with respect to operating system, programming language, or distributed computing platform
  • A better way was needed to describe the messages and how they are exchanged. The Web Services Description Language (WSDL) is a particular form of an XML Schema, developed by Microsoft and IBM for the purpose of defining the XML message, operation, and protocol mapping of a web service accessed using SOAP or other XML protocol.
  • The WSDL syntax allows both the messages and the operations on the messages to be defined abstractly, so they can be mapped to multiple physical implementations.
  • WSDL creates web service definitions by mapping a group of endpoints into a logical sequence of operations on XML messages. The same XML message can be mapped to multiple operations (or services) and bound to one or more communications protocols (using “ports”).
  • The Universal Description, Discovery, and Integration (UDDI) framework defines a data model (in XML) and SOAP APIs for registration and searches on business information, including the web services a business exposes to the Internet.
  • UDDI is an independent consortium of vendors, founded by Microsoft, IBM, and Ariba, for the purpose of developing an Internet standard for web service description registration and discovery.
  • The information in UDDI is categorized according to industry type and geographical location, allowing UDDI consumers to search through lists of potentially matching businesses to find the specific one they want to contact.
  • When you create a Web reference, Visual Studio creates an XML Web service proxy class automatically and adds it to your project. This proxy class exposes the methods of the XML Web service and handles the marshalling of appropriate arguments back and forth between the XML Web service and your application. Visual Studio uses the Web Services Description Language (WSDL) to create the proxy.

Static Classes in .Net

  • Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class.
  • To separate data and behavior that is independent of any object identity
  • Static classes can be used when there is no data or behavior in the class which depends on object identity.
  • Can be use for storing single-ton instances, global data.
  • A static constructor is used to initialize any static data. This is called only once
  • A static constructor is used to perform a specific action that needs performed once only.
  • A static constructor is called automatically before the first instance is created or any static members are referenced.
  • Static Classes are Sealed and only contains Static Members
  • Static Classes Cannot be instantiated
  • Static Classes can be use for Helper Methods.
static class MyStaticClass
    public static string GetName() { return "Name"; }
    public static string GetAddress() { return "Address"; }


SQL Server Database Triggers

  • A trigger is an object contained within an SQL Server database that is used to execute a batch of SQL code whenever a specific event occurs.
  • A trigger is “fired” whenever an INSERT, UPDATE, or DELETE SQL command is executed against a specific table.
  • A Trigger is associated with Database Table

There are three types of Database Triggers –



  • Body of trigger can have any block which a Stored Procedure can have
  • Body can call SP using Exec
  • When SQL server processes this “INSERT” command, it creates a new virtual table, which contains all nine of the fields in the “INSERT” command. This table is named “Inserted”, and is passed to the trig_addAuthor trigger.
  • At any one time, each trigger only deals with one row.
  • So for INSERT Trigger only hold reference of Inserted virtual Table

CREATE TRIGGER trig_addAuthor
ON authors
— Get the first and last name of new author
SELECT @newName = (SELECT au_fName + ‘ ‘ + au_lName FROM
— Print the name of the new author
PRINT ‘New author “‘ + @newName + ‘” added.’


  • The “UPDATE” function is used to check whether or not the “au_fName” and “au_lName” fields have been updated by the “UPDATE” Query
  • “UPDATE” triggers have access to two virtual tables: Deleted (which contains all of the fields and values for the records before they were updated), and Inserted (which contains all of the fields and values for the records after they have been updated)
  • Update triggers can also be used to check field constraints and relationships

CREATE TRIGGER trig_updateAuthor
ON authors
SELECT @oldName = (SELECT au_fName + ‘ ‘ + au_lName FROM Deleted)
SELECT @newName = (SELECT au_fName + ‘ ‘ + au_lName FROM Inserted)
PRINT ‘Name changed from “‘ + @oldName + ‘” to “‘ + @newName + ‘”‘


  • It has only access to the virtual table “Deleted”
  • Same as INSERT, UPDATE


  1. When triggers are used correctly, they can save a lot of development work. One of the main benefits of using triggers is that they are stored in a central repository (the database), meaning that they are accessible from all client applications / web pages that can connect to the database.
  2. Before triggers came along, if we had a table that needed to be updated and we wanted to perform some actions after that update, then we would have to “hard code” the extra SQL into our application. This meant that if we wanted to change the code later down the track, then each client would need the updated version of our application. This is both annoying and time consuming.

Happy Coding 🙂

ActionScript for Designers Part 1- Basics of ActionScript

Hi Guys,

Generally Flash comes with two meanings – 1) Flash for Designer & 2) Flash for Developers (ActionScript). Designer always threaten about ActionScripting. It is not that complicated at basic level where Designer can levarage the benefits of ActionScripting to their Creative Work without having Programming knowledge.

If you already know the Flash, using tools and creating animations, you may want to add some interactivity to your skills.

Actionscript is written as a series of statements within a Flash movie, and is placed either in a frame or in an external class file. In the Flash intro class, we also put actionscript on buttons and movieclips, but that was done for the sake of easier learning.

ActionScript, an object oriented programming (OOP) language built for Flash/Flex developement. There are versions of actionscript like Flash (7/8/ cs2 etc..), these are ActionScript 1.0, 1.1, 2.0, 3.0.  Based on the Flash version, adobe provides default scripting version which is located at Publish Settings in Flash IDE (Integrated Development Environment).


Trace function allows you to print information to your output window in Flash. This is not visible to those who view the SWF on the web. Trace is especially useful for debugging, if something goes wrong and you want to figure out why. You can trace simple text or the contents of variables.

trace(”Text or variables can go here”);


Functions are basically reusable chunks of code that you don’t want to rewrite over and over again.  It saves your coding time and add scalability layer to your code.

function myFuncationName(inputValue)


Flash Timeline refers to the sequence of frames and keyframes in either a movieclip or on the Stage or main movie. The stage’s timeline can be treated in actionscript as an instance of a movieclip. It is represented either as _root (from any timeline in the movie which is deeply nested to N-level), or as _parent from a movieclip placed on main timeline frames. It is often referred to as the main timeline.



Using simple playhead control, you can take control of your timeline. A lot of animations you can place on timeline which can be easily played using playhead functions. These include:

gotoAndPlay (frameVariable);


Assigning attributes allows you to dynamically store or update items in your variables(Container) using Actionscript. This includes visibily, scale, alpha, position etc… Some examples:

myMovieClip_mc. _alpha=35;


if statements are used to take decisions inside code. It is straightforward.
if (myVariable==myOtherVariable)
for e.g.
   trace(“Alpha is 50”);
   //do something
 //do alternative


Loops are used to perform specific tasks to certain number of times or until a condition satifies. There are two kind of loops – FOR loop, & WHILE loop.
for (var startCounter=0; startCounter<5; startCounter++)

var startCounter=0;
while (startCounter != 10)
trace(“Count “+ startCounter);


Buttons can be used to control movies. To accomplish this, you need to attach action to the button or movie clip with the on() function. You could write actions in the Timeline using event handler functions with instance names of button or movie clips or you can write actions on button or movie clips, for this you need to select button or movie clip and Press F9 to open Action window.


Hope you like this tutorials. I am working on it to proceed further with more detailed one.

Happy Coding 🙂

Generate Page URL Name for CMS, Blogs Application

Hi All,

To give the Name to the Page can be handeled by many ways like

Using GUID (Issue- Cant identify exactly while browsing through pages)
Using Session (Issue-Same as above)
Using Page Title provided in Text Field (We will see this)
We are going to implement the scenario 3. We will first see what are our constraints for page url name.

It should be only Alphanumeric enabled like – About-Us.aspx
No other character should include in the page name like – %,@,$ etc
Its just about Regular Expression to identify the alphanumeric characters. The reqular expression is in System.Text.RegularExpressions namespace.

Regex.Replace(strInput, “[^\\w]”, “”);

If you give the page Title to – About % US #$ output will be AboutUs.aspx

Happy Coding 🙂

Optimizing SQL Server Database Design Tips & Tricks – Part 1

Database design is most crucial part in application development. Database can be anything SQL Server, MySQL, Oracle, etc. I will consider SQL SERVER as a part of discussion.

Tunning the database depends upon various factors like whether one datatype is better depends on the context of it’s usage. Following are most common datatypes used in database.

Numbers Datatype (For storing Primary Keys, Foreign Keys, Status etc) 

An int requires 4 times the storage of a tinyint. More storage means more data and

index pages to read / write, more I/O and thus potentially more seek time. It also means more memory consumption.

For eg. Desigining User Role and Users Table. Generally application will not have more than 5-10 user roles like Admin, Manager, Employee, etc. Most of developers design the table like - 

Table – UserRole

RoleId – Integer (whole number) data from –2^31 (–2,147,483,648) through 2^31–1 (2,147,483,647). It takes 4 Bytes to store.

RoleName – Varchar (50)

Which is not suiting to our requirements. Instead of int we can use tinyint – Integer data from 0 to 255. Storage size is 1 byte. 


DateTime Datatype (For storing dates)

Most of the times database tables required date to be stored to maintain record creation date. 

DateTime data type are stored internally two 4-byte integers. The first 4 bytes store the number of days before or after the base date: January 1, 1900. The base date is the system reference date. The other 4 bytes store the time of day represented as the number of milliseconds after midnight.

The smalldatetime data type stores dates and times of day with less precision than datetime. The Database Engine stores smalldatetime values as two 2-byte integers. The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes since midnight.

So, instead of using datetime as datatype smalldatetime is more efficient in general development.


STRING DATATYPE (Storing text data)

All string data stored inside varchar, text, ntext, nvarchar, etc. 

For eg. FirstName data field developers used varchar or nvarchar with default size i.e. 50. We should know the scope of the filed in terms of maximum characters. Generally first name, last name etc.. won’t take more than 20 – 25 characters. So instead of 50 if we use 20 characters we can save half the storage, index size which will increase performance of queries. 

 These are the basics which needs to keep in mind while developing applications. 

Happy Coding … 🙂

GridView in ASP.Net

GridView plays very important component in ASP.Net Application. It covers most of the basic reports for which you do not need any reporting component like Crystal Report, Report Viewer etc.

Major concern with any data entry form is Add, Edit, Delete and View.


We are using SQL Server Express editions as Database.

Table Name- Employees

Fields- EmpId, EmpName, Designation

Take GridView control on page and set the ID property to dgEmployees.

Go to property builder by right click on GridView -> Show Smart Tag -> Edit Columns. Uncheck Auto-Generate Field from the Property window.

Add three TemplateField Column for Employee Name, Designation, & Delete Button. Add Edit button from CommandField Group from Property Window.

TemplateField Colums have ItemTemplate, Alternating Item Template, Edit Template, Header Template, Footer Template.

Each template columns Item Template field contains Label Control & Edit Template contains TextBox control for Editing item. Set the Binding Field name to the Text Property of both controls for each template field to the respective Database Column Name i.e Eval(“EmpName”).

Set the DataKeyNames property of GridView to Primary Key Column of DataBase i.e. EmpId. This property binds the database column field value to each row of gridview as a Unique Identifier.

Set the data bindings for Delete Button for CommandArgument Eval(“EmpId”); for saving the ID column value from database for fetching the ID field value while Deleting the Record. Set the CommandName property to Delete Button to CMDDelete. The CommandName property can contain any string name which can be used to recognize the type of command invoked from gridview. Because when any of the event generated in GridVeiw it fires RowCommand Event. In this event we have to handle the Delete Button Code. Instead if you are using default Delete Button of GridView then register for RowDeleting event of GridView and for accessing Unique ID columnvalue from database you need to fetch the id from DataKeys collection of GridView. For e.g.

int EmpId = Convert.ToInt32(dgEmployees.DataKeys[e.RowIndex].Value);

Place the Textbox control in the grids Footer template for Adding new record. Set the CommandName to CMDAdd for Add button.

Register events for Edit, Update, Cancel button of gridview ??” RowEditing, RowUpdating, RowCancelEditing.

View in GridView

To view data in gridview is very simple. Just create a DataSet using SqlDataAdapter??Ts Fill method and set the GridViews DataSource Property to DataSet.

Create a Method to Bind the GridView to DataSource named BindGrid. This method fetches data from the GetEmployees method which returns DataSet from Employees table.

Call the BindGrid on Page_Load in !IsPostBack block to fill the grid by default.

private void BindGrid()


dgEmployees.DataSource = GetEmployees();



private DataSet GetEmployees()


DataSet ds = new DataSet();

SqlConnection conn = new SqlConnection();

conn.ConnectionString =ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;

SqlDataAdapter da = new SqlDataAdapter("Select * From Employees", conn);




return ds;


catch { }






return null;


Edit in GridView

For Editing Register RowEditing event of GridView. To switch the normal mode to Edit mode of gridview EditIndex property plays important role. EditIndex specifies which row is in edit mode by setting RowIndex to it. By default EditIndex of gridview is -1 (Normal mode). If you want to edit 3rd Row then set the EditIndex to 2 (Row index starts from 0,1,2..).

After setting editindex refresh the grid by calling BinGrid. GridViewEditEventArgs object knows the current row index so getting row index of the selected row in gridveiw is not big deal; just e.NewEditIndex (e object of GridViewEditEventArgs).

protected void dgEmployees_RowEditing(object sender, GridViewEditEventArgs e)


dgEmployees.EditIndex = e.NewEditIndex;



Cancel in GridView

For Cancel just reset the GridView editindex to default i.e. -1 and refresh the grid.

protected void dgEmployees_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)


dgEmployees.EditIndex = -1;



Update in GridView

For Update register RowUpdating event of the gridview. Find the Unique id for updating the row from DataKeys collection of gridview.

int EmpId = Convert.ToInt32(dgEmployees.DataKeys[e.RowIndex].Value);

Find the controls in the selected row by using FindControl method of gridviews rows collection and collect data from the text boxes.

TextBox txtname = dgEmployees.Rows[e.RowIndex].FindControl(“txtEmpName”) as TextBox;

TextBox txtdesign = dgEmployees.Rows[e.RowIndex].FindControl(“txtDesignation”) as TextBox;

Finally update the row and refresh the grid.

if(txtname!=null && txtdesign!=null)

UpdateEmployee(empId, txtname.Text.Trim(), txtdesign.Text.Trim());

dgEmployees.EditIndex = -1;


Complete code-

protected void dgEmployees_RowUpdating(object sender, GridViewUpdateEventArgs e)


int empId = Convert.ToInt32(dgEmployees.DataKeys[e.RowIndex].Value);

//Find Text boxex

TextBox txtname = dgEmployees.Rows[e.RowIndex].FindControl("txtEmpName") as TextBox;

TextBoxtxtdesign=dgEmployees.Rows[e.RowIndex].FindControl("txtDesignation") as TextBox;

if(txtname!=null && txtdesign!=null)

UpdateEmployee(empId, txtname.Text.Trim(), txtdesign.Text.Trim());

dgEmployees.EditIndex = -1;



Custom Delete in GridView

For Delete register RowCommand event of the gridview. Find the Unique id for deleting the row from DataKeys collection of gridview. Check for CommanName and invoke delete method for the selected row.

protected void dgEmployees_RowCommand(object sender, GridViewCommandEventArgs e)


if (e.CommandName.Equals("CMDDelete"))


int EmpId = Convert.ToInt32(e.CommandArgument);


//Refresh Grid




Add in GridView

Adding from GridView is just some trick with Footer Template. I added textboxes and a add button in the footer row of the gridview. When u are in Normal mode it is visible else it is invisible to synchronize between edit and add.

Like Updating find the Textbox and pass the values to Addemployee method like

else if (e.CommandName.Equals("CMDAdd"))


TextBox txtname = dgEmployees.FooterRow.FindControl("txtEmpName") asTextBox;

TextBox txtdesign = dgEmployees.FooterRow.FindControl("txtDesignation") as TextBox;

if (txtname != null && txtdesign != null)


AddEmployee(txtname.Text.Trim(), txtdesign.Text.Trim());




The Complete code for EditEmployee, AddEmployee, UpdateEmployee, DeleteEmployee is in Source File.

The code should be in RowCommand event only. Due to this we use CommandName for different button control to differentiate between the type of code to be handled by gridview.

ASP.Net Server Variables

Below is the detailed table for showing the ServerVariables Collection information.

Variable Name Description
ALL_HTTP HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:sv HTTP_HOST:localhost:1229 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)
ALL_RAW Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: sv Host: localhost:1229 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)
APPL_PHYSICAL_PATH D:\code\web\demos\membership\
PATH_INFO /membership/servervariables.aspx
PATH_TRANSLATED D:\code\web\demos\membership\servervariables.aspx
SCRIPT_NAME /membership/servervariables.aspx
SERVER_NAME localhost
URL /membership/servervariables.aspx
HTTP_HOST localhost:1229
HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)

Storing Objects into Permanant DataStore in ASP.Net

Hi All,

I was facing a problem towards sharing a data between Flash and .Net. The easiest way i found is XML Seralization because Remoting is much heavy and it requires remoting implementation. Even now I can store the Calss objects permanantely. This can be used in concept of Hibernate (Some what at very basic level).

I found XML Seralization because there must be some common bridge between two different technoloiges for communication. XML will act as common bridge between .Net and Flash.

XML Seralization can be done by System.Xml.Serialization.XmlSerializer class from System.Xml.Serialization namespace.

Assume our class defination looks like below –

namespace EShopping
public class Category
private int _CategoryId;
public string CatName;
public int CategoryId
get{return _CategoryId;}

Our object has below contents-

EShopping.Category c = new EShopping.Category();
c.CategoryId = 1;
c.CatName = “Hello”;

Now we want to seralize this object to the XML by XML Seralization.

System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(EShopping.Category));

XmlSerializer Class has a method called Seralize and Deserialize.
Seralize method requires parameter Textwriter and class object to seralize.

System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(EShopping.Category));

System.IO.TextWriter tw = new System.IO.StreamWriter(Server.MapPath(“SeralizeClass.xml”));

ser.Serialize(tw, c);


That’s it. Now you can see the SeralizeClass.xml file in your Web root directory. You can access this into any of the technologies which has xml support.

Accessing Seralize Object into .Net-

This is pretty straight forward and just access the object by Deserialize methotd of XmlSerializer Class.

System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(EShopping.Category));

System.IO.TextReader tr = new System.IO.StreamReader(Server.MapPath(“SeralizeClass.xml”));

EShopping.Category c = (EShopping.Category)ser.Deserialize(tr);


Happy Coding 🙂