Monday, October 19, 2009

Sending email in asp.net 3.5

Sending email is a very important in web application for remind anything to user, newsletter ,invitation or reset password etc.In .Net 1.1 we used System.Web.Mail.SmtpMail for sending emails , which is now obsolete. Now in asp.net 2.0 or higher version we can use System.Net.Mail.Smtpmail to send mail.


Code for sending email in asp.net 3.5

SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("from@site.com","Nameofsendingperson");
message.From = fromAddress; //here you can set address
message.To.Add("to@abc.com"); //here you can add multiple to
message.Subject = "Subject Goes Here"; //subject of email
message.Body =@"Body Text";
smtpClient.Send(message);
}
catch (Exception ex)
{
//throw exception here you can write code to handle exception here
}


For adding attachment with your mail you need to write following code

message.Attachments.Add(New System.Net.Mail.Attachment(Filename))

Here Filename will be the physical path along with the file name. You can attach multiple files with the mail.


If you want to sent a email with authentication then you have to write following code.

System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
//This object stores the authentication values
System.Net.NetworkCredential basicCrenntial =
new System.Net.NetworkCredential("username", "password");
mailClient.Host = "Host";
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicCrenntial;
mailClient.Send(message);

Saturday, October 17, 2009

Three major points in WCF


1) Address --- Specifies the location of the service which will be like http://Myserver/MyService.Clients will use this location to communicate with our service.

2) Contract --- Specifies the interface between client and the server. It’s a simple interface with some attribute.

3) Binding --- Specifies how the two parties will communicate in term of transport and encoding and protocols.

WCF

Windows Communication Foundation is a set of .NET technologies for building and running connected systems. It is a new breed of communications infrastructure built around the Web services architecture.



Windows Communication Foundation is Microsoft's unified programming model for building service-oriented applications with managed code. It extends the .NET Framework to enable developers to build secure and reliable transacted Web services that integrate across platforms and interoperate with existing investments. Windows Communication Foundation combines and extends the capabilities of existing Microsoft distributed systems technologies, including Enterprise Services, System.Messaging, Microsoft .NET Remoting, ASMX, and WSE to deliver a unified development experience across multiple axes, including distance (cross-process, cross-machine, cross-subnet, cross-intranet, cross-Internet), topologies (farms, fire-walled, content-routed, dynamic), hosts (ASP.NET, EXE, Windows Presentation Foundation, Windows Forms, NT Service, COM+), protocols (TCP, HTTP, cross-process, custom), and security models (SAML, Kerberos, X509, username/password, custom).

Friday, October 16, 2009

Timer on Windows Service in Visual Studio 2008


We do not use the timer System.Windows.Forms.Timer that is in the Toolbox during adding a timer to the Windows Service. This doesn’t work for Windows Services. We will have to use the System.Timers.Timer instead of System.Windows.Forms.Timer. And the event we will use Timer1_Elapsed instead of Timer1_Tick.

Monday, October 12, 2009

Developing iPhone Application From non-Mac Pc - Part-1


The popularity of iPhone is incressing so programmer’s are very much interested to write application for iPhone. To develop application for iPhone it’s must be needed to a Mac pc but Mac pc is so expensive so many programmer’s are not thinking more about it.This article is for those who are more interested to develop but havn’t Mac pc.

This article split in two section, In frist section we prepare the development environment for and in second section we develop “hello world” program.


Prepare Development Environment:

The Development environment is based on OSx86 project, therefore we use non-Apple pc. OSx86 is a collaborative "hacking" project to run the Mac OS X computer operating system on non-Apple personal computers with x86 architecture processors

There are many distribution is available Kalyway, iPc, iDeneb etc.we need any one from that. Here we use iDeneb 1.4.

1) Install iDeneb 1.4 :

iDeneb is a Mac OS X Leopard release modified by Layne and iHackintosh Team to run on non-Apple computers. This universal release can run on both Intel and AMD based machines.

2) Install iPhone Development SDK.With the SDK you get some tools like Xcode, Interface Builder, iPhone simulator, and many more

My First Architecture Development

Last month from my office, i have got a .net based project . The client requirement made me more interested on this project .The application is a Client-Server based application but the client is desktop based application. Client wanted the UI should be talk with server only through service, So he wants a extra layer on normal n-tier project that is service layer. He send the structure of architecture too.




Client recommend for service layer was web service or wcf. I have experience in earlier on web service but not wcf so i didn’t miss the chance to use wcf. Client also recommend LINQ or DTO on DB Layer.i proposed DTO .

This project was very much exciting for me for various purpose , first of all this my first architecture development in production and this is my first wcf application . From this project i have lerned many business logic as well as technical logic . I really enjoyed this project.

Friday, July 24, 2009

Unit testing

Unit testing is a software verification and validation method where the programmer gains confidence that individual units of source code are fit for use. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual program, function, procedure, etc., while in object-oriented programming, the smallest unit is a method, which may belong to a base/super class, abstract class or derived/child class.

Ideally, each test case is independent from the others: substitutes like method stubs, mock objects, fakes and test harnesses can be used to assist testing a module in isolation. Unit tests are typically written and run by software developers to ensure that code meets its requirements and behaves as intended. Its implementation can vary from being very manual (pencil and paper) to being formalized as part of build automation.

Wednesday, July 8, 2009

Comet Programming


Comet is a Web application model that enables web servers to send data to the client without having to explicitly request it. Developers can utilize Comet techniques to create event-driven Web apps. Comet is actually an umbrella term for multiple techniques for achieving client-server interaction. All methods have in common that they rely on browser-native technologies such as JavaScript, rather than on proprietary plug-ins


In theory, the Comet approach differs from the original model of the web, in which a browser requests a complete web page or chunks of data to update a web page. However in practice, Comet applications typically use Ajax with long polling to detect new information on the server. The concept predates the coining of the neologism, and is known by several other names, including Ajax Push, Reverse Ajax Two-way-web, HTTP Streaming and HTTP server push among others.

Monday, July 6, 2009

Essential Tools For WPF Development

Microsoft provides two development tools for WPF applications.

1) Visual Studio:

This is for developers and it is good in code and XAML editing

Download: Microsoft Visual Studio 2008-Express Edition


2) Expression Blend

This is for designers and its covers the graphical part stuff like gradients, template editing, animation, etc

Download: Microsoft Expression Blend 2-SP1

Introduction to WPF

The Windows Presentation Foundation is Microsoft next generation UI framework to create applications with a rich user experience.With WPF, you can create a wide range of both standalone and browser-hosted applications.It is part of the .NET framework 3.0 and higher.

The core of WPF is a resolution-independent and vector-based rendering engine that is built to take advantage of modern graphics hardware. WPF extends the core with a comprehensive set of application-development features that include Extensible Application Markup Language (XAML), controls, data binding, layout, 2-D and 3-D graphics, animation, styles, templates, documents, media, text, and typography. WPF is included in the Microsoft .NET Framework, so you can build applications that incorporate other elements of the .NET Framework class library.