Monday, March 22, 2010

Web Service - Understanding WSDL and UDDI

Web Services Description Language (WSDL) is one of the prime specifications in web services, the other two being SOAP and UDDI. WSDL is the description language for web services that describes a set of SOAP messages and how these messages are exchanged across network. WSDL will be in XML format; therefore it can be easily understood and edited by humans and machines.


Another advantage of WSDL being in XML format is that it is programming language independent and also platform independent. In addition, WSDL defines where the web service is available from and what communications protocol has been used to talk to the web service. As a result the WSDL file describes everything that is required to write a program for an XML Web service. There are tools available in Microsoft Visual Studio .NET to read a WSDL file and generate the code required to communicate with an XML Web service.
Universal Discovery Description Language (UDDI) is a directory where you can expose your web services for other users to easily access it. You can also consume the web service that is already posted in UDDI. However, you can also post a web service without registering it in UDDI. DISCO is another directory where you can post your web service. But if you want to reach to maximum of customers, you can place it in UDDI. The UDDI directory offers three parts for you to register:
• White Pages
• Yellow Pages
• Green Pages

The white pages consist of the description such as name and address of the company offering the service. The yellow pages consist of industrial categories based on standard taxonomies such as North American Industry Classification System and Standard Industrial Classification. The green pages describe the interface to the web service in detail so that anyone can write an application after using the web service. Web services are described in UDDI directory through a document called Type Model or tmodel. Normally, this tModel contains a WSDL file that describes a SOAP interface to an XML Web service, but the tModel is flexible enough to describe almost any kind of web service.
Apart from using the web services from UDDI, you can also search a particular web service in UDDI. In addition, you can search for companies’ information that posted web services. In certain times, you might know the names of the companies that offer web services but you may not be aware of the web services that they offer. The WS Inspection is a specification in UDDI that allows you to search for a collection of web services that are located in a particular company name. You can evaluate these web services according to your requirements.

Saturday, March 20, 2010

What is Global.asax ? How to use it in .Net web projects ?

The Global.asx file is an optional file that contains code for responding to application level events raised by ASP.NET. This file is also called as ASP.NET application file. This file resides in the root directory of an application. If we are not defining this file in application, the ASP.NET page framework assumes that you have not defined any applicationa/Session events in the application.

Followign are the list of events handled in the global.asax file.

Event: Application_Start 

When an application starts. This event occurs only one time in an application’s life cycle. It occurs again when you restart the application. It’s the best place to count number of visitors.

Event: Application_End

This event occurs when application ends.

Event: Session_Start

This event occurs whenever a new session starts. This is the best place to count user sessions for an application

Practical Usage: Setting user specific values, caching items based upon user context.

Event: Session_End

This event Opposite of the previous event.

Event: Application_Error

This event occurs when an unhandled error or exception occurs in an application.

Event: Application_BeginRequest

This event occurs every time when server makes a request. This event may occur multiple times in an applications life cycle.

Event: Application_End

This event occurs when an application closes

Monday, March 1, 2010

Tracking Emails - Know Whether the Recipient Opens it

It is very easy to track whether the user has read the email. The concept is very simple. You insert a link to a small transparent image in the mail sent, the mail being sent in HTML format, and when the user opens the email the image is loaded sending you a querystring to the web page that tracks the email. The web page requests the querystring or the parameter that is passed. This ensures that the email is read by the user.



When the page that is tracking is requested by the email sent you can get the value of the date and time when the request comes and you can store them in a database or send you an alert indicating the time and date at which the email was read by the user. This is the simple way that is used to track whether the emails sent are read or not.
To send emails you may be importing the namespace System.Web.Mail. You would be creating a MailMessage object as given below.
Imports System.Web.Mail
string sBody;
MailMessage mailMsg = new MailMessage();
mailMsg.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = “your Server name”;
mailMsg.From = "your email address";
mailMsg.To = “to email address”;
mailMsg.Subject = “subject line of the mesg”;
mailMsg.Body = sBody;
SmtpMail.Send(mailMsg);

The above code sends an email to an email address as given in the mailMsg.To property. For tracking an email, all you have to do is to add an image tag to the body of the message i.e. sBody. This can be done by
sBody = sBody + "";
In the above line sParam is the parameter that is passed to the url and sYourDomain is your domain name where you create this page to track the email. If you send an email with the body of the message as given above, when the user reads the email, the image tag will try to load the url given in the tag. This will send the parameter “sentto” that is given by you to the page requested. In the trackemail.aspx page you can write code to retrieve the value of the parameter “sentto”. Once you receive the parameter you can do anything on that page to indicate that the user has read the email.
The code given below can be used in the trackemail.aspx page to retrieve the parameter.
private void Page_Load(object sender, System.EventArgs e)
{
if ( Page.IsPostBack == false )
{
if ( Request.Params["sentto"] != null )

//here you can send a mail to yourself
...
mailMsg.Body = Request.Params["sentto"].ToString()
+ “ has read your email”;
...

}
Response.Redirect("transparent.gif");
}

Once you have retrieved the parameter that is passed to the page you can redirect the request to a transparent image so that this transparent image, “transparent.gif” loads in the email message of the user who is reading the mail. Make this “transparent.gif” as small as possible, usually of 1 pixel by 1 pixel height and width, so that it does not take time to load. Since it is transparent the user who reads your mail may not know that an image has been loaded in the email message and the email that he reads is being tracked.
This way of tracking the email is so easy. Once you get the parameter in your trackemail.aspx page you can add a time stamp to the body of the email message that is sent to you in the Page_Load event of that page. This enables you to know the time and date at which the email was read by the user.