Sunday, July 13, 2008

HTTP Handlers in .Net

Introduction :
In simple words what i understand is that as the name suggests "they are meant to process the http Request by the client and generate the response. "

They are uesd by ASP.Net to handle requests for the .aspx pages.

Why and Where to use:

use of HTTP Handler(your custom) can be a alternative and better approach than .aspx page
depending on the scenario
for example :
application to application Interaction ( data posted by using XML Http from one form to other and receiving response)

Dim requestXML As New StringBuilder()
Dim oXMLHttp As New XMLHTTP

requestXML.Append("")
requestXML.Append("Rate")
requestXML.Append("Shop")

Dim Domain As String = HttpContext.Current.Request.ServerVariables("Server_Name") + ":" + HttpContext.Current.Request.ServerVariables("Server_Port")

oXMLHttp.open("POST", "http://" + Domain + "/httphandling/Default.aspx", False)
oXMLHttp.setRequestHeader("Content-Length", (requestXML.ToString.Length))
oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
oXMLHttp.send(requestXML.ToString)
Dim response As String = oXMLHttp.responseText

In the above code a xml string is sent to the "Default.aspx" where it is processed and Response is sent back.
So, what is the role of Default.aspx more specifically no visual content.

this is the case where there is Over head of Processing of the .Aspx page life cycle

So, Http Handler Can be used to overcome this Issue.


How to use:

There are Two Approaches Available to my knowledge.

The one require more effort the other bit easier.

First Approach :

Implementing The System.Web.IHttpHandler Details

I personally Found The Following Article Very Helpful Thanks to the author
Implementing HttpHandelers

Now Let us come The :

Second Approach:

Using The .ashx "web Handler" the template is available in Visual studio.Net
you donot require registring the file extension in web.Config

for details : visit

Now using This approach:

on The page sending Request:


Dim requestXML As New StringBuilder()
Dim oXMLHttp As New XMLHTTP
requestXML.Append("")
requestXML.Append("Rate")
requestXML.Append("Shop")

Dim Domain As String = HttpContext.Current.Request.ServerVariables("Server_Name") + ":" + HttpContext.Current.Request.ServerVariables("Server_Port")

oXMLHttp.open("POST", "http://" + Domain + "/httphandling/Handler.ashx", False)
oXMLHttp.setRequestHeader("Content-Length", (requestXML.ToString.Length))
oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
oXMLHttp.send(requestXML.ToString)
Dim response As String = oXMLHttp.responseText


On The Handler.ashx


<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.IO;


public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
StreamReader rd = new StreamReader(context.Request.InputStream);

string str=rd.ReadToEnd();
//processing of the request string
context.Response.Write("Yes, I received you request");

}

public bool IsReusable {
get {
return false;
}
}

}


I hope this might be helpful to the readers

Monday, June 23, 2008

XML Serialization

In simple words Serialization is the process of saving the state of a object of any Type into to a physical medium or stream.
using this process any object can be saved as :
-Binary file
-soap object
-xml file or xml stream

XML Serialization:

for the beginners who have less knowledge about the xml are advised to
visit one of the most beneficial resources xml tutorials

for details about the core concepts visit:Serialization Articles

to more elaborate the purpose of this post consider a scenario:

for example you want to create an application with facility of shipping rate calculation,
for this purpose you may use UPS online tools or USPS rate API.

for both of the ways you will have to create the Request in specified format
where information is to be represented in XML .

at this point xml serialization can help minimizing the effort required

for the practical Implementation this is a very good article
Xml serialization

Friday, June 13, 2008

Getting started with ebay developer Program

This is my first post , so please your positive comments will be encouraging for me.
ebay.com is the most known website for buying and selling, they also offer the integration
of other application for listing products to sell on the ebay .

They have also provided good resources for the developers,as startup i will recemond to visit this link:
Ebay Development starter kit
download the kit and make the sample application using the template.

please donot forget to read the Docs/eBaySellingStarterKitDocumentation
in the visual studio project.

then get your self registered at the Ebay developer program
once you get registered generate the keyset:
eBayAppID
eBayCertID
ebayAuthToken

these are required for starting developing test application
till this step there is no hurdle .

Getting The Auth Token
there are some prerequisites for that
if you donot follow you can ran into situation like this

please do register before at SandBox test user Registration
before you proceed because you need an ebay id to generate the auth token.
there you can put the it and get the auth token
and get your sample project work.

i also found a very good article which helps alot : Writing ebay Application


i hope this post will be helpful for the people want start doing their work with developing ebay application.