Web Services with ASP.NET 2.0 in C#

I was trying to develop a web service that would serves request for converting document to PDF format. This development involves the following task:

1. Ability to receive request in the form of binary data.
2. Ability to send out email.

I don't have any exposure to web services apart from Maxis ECPA development based on SOAP. As usual, the first thing that I would do is to buy a book that could teach me the basic of web service development. Of this, I bought Beginning ASP.NET 2.0 with C#, published by Wrox. This book only cover a little bit of web service, but it's just enough for me to learn the fundamental of the web service building block.

As I learned how to create the web service using Visual Studio 2005, together with some example from MSDN website, I was managed to create the web service. There wasn't much coding need to be done, as the ASP.NET 2.0 framework has made it easier to develop web appplication. Note about the development that I made:

1. Sending binary data over to the web service
The binary data was data from documents such as word, excel, power-point, images, etc. The binary data must be extracted into the form of an array, byte[]. byte is a type of variable in C# that deals with binary data.

2. Sending email
ASP.NET 2.0 was capable to store information of the SMTP mail server (Simple Mail Transportation Protocol) in the web.config XML file, thus it reduces the hassle of initiating the SmtpClient instance. Things to remember was that sending an email using MailMessage.Send may experience failure for file with few megabytes. It was better to send using MailMessage.SendAsync. This was really good as compare to old days where sending file through asynchronous connection was a pain in C++. 1 thing to remember was the Message object could only be destroyed after it has been sent; otherwise error will be thrown. So, while sending with SendAsync, create the Event Handler for SendCompleteEvent, set the message object as parameter for UserState in SendAsync, then do the Dispose inside the Event Handler function.

3. Include Web Service in application
While adding reference to a web service, the behavior will have to be set to dynamic. When deploying the application, change the URL inside all the configuration files that end with .config to point to the web application's URL if it's not on the same machine.

Conclusion:
It is really easy to develop application with the web service for it made things easier to maintain.

Comments

Popular posts from this blog

Yahoo! Messenger voice call & video call disabled, why?

Sport's Injuries - Treatment for bruises

Web Development: Disable, Validate, & Enable Buttons