Tuesday, March 24, 2015

Introduction to REST ful Services


REST stands for Representation State Transfer. It is stateless, client-server communication protocol. REST is an architectural style for designing distributed application. Here instead of using complex mechanism to connect between machines, simple HTTP is used to make calls between machines.

RESTful application is use HTTP request to post data for the CRUD operation. Here CRUD stands for Create, Read, Update and Delete.

REST is a lightweight alternative of SOAP based web services and Remote Procedure Calls. It is very simple, fully featured and having all capabilities the SOAP based Web Service have.

REST services are Platform Independent, Language Independent, Standard based as run on HTTP and importantly can easily be used in presence of the Firewall.

REST does not offer ant built-in security feature, encryption, session management, QoS guarantees. But we can very well built these on top of HTTP. For security Username/password tokens are passed. For encryption REST can be used on top of HTTPS.

RESTful services can be called from the url using simpler GET request, and the HTTP reply is just the raw result data. Result was not embedded in anything, data would be in XML, CSV, RSS, ATOM and JSON format.  Unlike SOAP based web services it does not require any library to create the SOAP request and send over the wire and in the client side parse the response.

e.g. if you want to see details of a book from a bookstore. Request to fetch the book's detail will be http://mybookstore.com/book/1. Here 1 is the book id and you are interested to fetch the details of the book having Id =1.

The default method types present in RESTful services will be GET, POST, PUT or DELETE. Get is used for reading data, POST is for insert, PUT is for update and DELETE is for simply deleting any resource.

In SOAP based web services we used Envelope to send data from one machine to another machine. Inside envelope there will be header, body etc. In REST it is a postcard. Postcards are easy to handle by the receiver, waste less paper (consuming less bandwidth) and have short content. Though REST request does not has any limitation in the length if we will use POST rather than GET and security wise also it is same as SOAP based web services.


Monday, November 29, 2010

Dependency Property

For further customization of new UserControl, you can add custom properties to the UserControl's code behind. You can actually add property to it, but for some special functionality like (databinding, animation) with properties, you should add DependencyProperty.
E.g : Here I am explainging how to create a DependencyProperty and use it. Follow the small application, add two textboxes in your user control, I want to change first textbox's text while changing text on second text box. You can do this in 2 ways.
First method using wizard:
1. Click on first text box.
2. Press F4 or go to Properties windows of that textbox.
3. Click on right side of Text column, not in the blank section of Text property.
4. One Context menu will be displayed, choose "Apply Data Binding".
5. Data Binder window will appear, you have to set Source, Path, Converter and Option from there.
6. Here your source will be textbox2 which is an Element.
7. Path will be Value, because you are setting value of TextBox1 to TextBox2 and vice versa.
8. If you want to convert the value in some other format, you can use this.
9. Binding will be TwoWay, if you want to make it for both control.

Second method using Code:
1. You need to create a DependencyProperty. Below is code for that :

public String MyProperty
{
get { return (String)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(String), typeof("ownerType"), new PropertyMetadata("MyProperty"));
2. Go to design view, select TextBox1. Add "{Binding MyProperty, Mode=TwoWay}" piece of code in both textbox's Text property.

Friday, October 15, 2010

What is Unity Application Block

The Unity Application block is a lightweight, extensible dependency injection container that supports constructor injection, property injection and method call injection. You can use it with Enterprise Library to create both Enterprise Library objects and your own custom business objects. However Unity Application Block is differ from other Application block included in Enterprise Library in several fundamental ways:
  • You can use Unity Application Block as a stand-alone dependency injection mechanism that does not require Enterprise Library to be installed.
  • This can be used to configure information exposed through configuration files to prepare the container, but you can also used code to dynamically register dependencies at run time.
  • This has no dependency on Enterprise Library core or Enterprise Library Configuration system. It contains its own built-in mechanism for reading configuration - although, if appropriate, this information can come from normal Enterprise Library Configuration file.

Tuesday, July 27, 2010

Update Panel

Updatepanel is one of the most widely used control of Ajax. As we know it will used for Partial Page rendering. Did you know, that when an Updatepanel control perform an asynchronous AJAX callback to the server to update its content, the request contain everything a conventional ASP.Net postback contains, including View State. Most developer assume that AJAX eliminates view state, but this is not the case.
If you are using Updatepanel control, you need to know what you are getting in to. In many cases, for a performance point of view an application is better off not using Updatepanel and instead using asynchronous call to WebMethods or PageMethods. Doing so can reduce the volume of data travelling over the wire by an order of magnitude or more.


Here I have tried to taking a closer look at how we can customize it, optimized it and even live without it.

Updatepanel works its magic by converting postback into asynchronous callbacks (XML-HTTP) requests and using Javascript on the client to refresh or repaint the part of the page encapsulated by the updatepanel control. The flashing and flickering goes away because browser does not does not repaint the page as it does during postback.

Sys.WebForms.PageRequestManager class in Microsoft Ajax library (the library of Javascript classed) is most important class managed the asynchronous callback launched by Updatepanel. It is also responsible to updating the content inside an Updatepanel while an asynchronous callback completes.
How to customize UpdatePanel :
For an example : Client wants to highlight the Updated contents inside the Updatepanel.
PageRequestManager fires events in the browser before and after an update occurs. You can hook these events in Javascript and run the code that draw user's attention to the Updated content. The key event is named pageLoaded. This events fires each time the page loads in browser (it is analogous to Page_load event of ASP.Net). It also fires each time an asynchoronous callback launches on behalf of an Updatepanel control completes and the content inside an Updatepanel updated. You can register a Javascript handler for the pageLoad event by just writing two lines of code.
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);

The first line acquires a refernece to the page's PageRequestManager object. The second register a Javascript function named as pageLoaded as a handler of pageLoaded events.
When called, a pageLoaded event handler receives an argument of type Sys.WebForm.PageLoadedEventArgs, which is another class in Microsoft Ajax Library. PageLoadedEventArgs contains a get_PanelsUpdated method that you can call to enumerate all the Updatepanels, if any, whose contents are just updated, an updatepanel is nothing more than a DIV on the client-side so you can use Javascript tp flash the DIV, highlight it or do just whatever you want to do to draw a user's attention to it.
Below code shows one way to use pageLoaded event to perform update highlighting. Each time an update occurs, this Javascript flashes the Document Object Model (DOM) elements represening updated UpdatePanels by making them appear and disapper three times in quick succession. The flashing is performed by a helper function named flashPanels, which takes a flash count as an input parameters.
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);

var _panels, _count;

var _panels, _count;

function pageLoaded(sender, args)
{
if (_panels != undefined && _panels.length > 0)
{
for (i=0; i < panels =" args.get_panelsUpdated();"> 0)
{
_panels = new Array(panels.length);

for (i=0; i <>
{
_count = (count <<>
for (i=0; i <>
window.setTimeout(toggleVisibility, 50);
}
function toggleVisibility() {
for (i=0; i < _panels[i].set_visible(!_panels[i].get_visible());
if (--_count > 0)
window.setTimeout(toggleVisibility, 50);
}


Note how an updated UpdatePanels visibility is toggeled on and off to create a flashing effect. Rather than interacting with DOM element directly, the code wraps the DOM elements represening the UpdatePanels with Sys.UI .Control's set_visible and get_visible methods to toggel the visibility.

Sys.UI.Controls is a Javascript class found in Microsoft Ajax library specially in MicrosoftAjax.js. The benifit of togglling visibility in this manner is that this is browser independent. This works equally well in every browser that supports ASP.Net Ajax. Javascript code that directly interact with the browser DOM.




Tuesday, December 29, 2009

Indexes in SQL Server

You can create maximum 249 non clustured indexes in a table and only one clustured index.

Example of Non Clustured index is : Book index in back side of each book, which contain a word and page numbers where you get those words. Basically It contain reference of each record as page number, and while user execute a sql query, it first checks while there is an index in that column or not. If there is a non clustured index so, it must contain all references of rows with matched data, and it points to those rows only. Otherwise it should search all record one by one and select only matched rows.

Example of Clustured Index : A Telephone Directory. A phone directorystill sorts entries into alphabetical order. The difference is, once we find a name in a phone book, we have immediate access to the rest of the data for the name, such as the phone number and address.

For a clustered index, the database will sort the table's records according to the column (or columns) specified by the index. A clustered index contains all of the data for a table in the index, sorted by the index key, just like a phone book is sorted by name and contains all of the information for the person inline. We can only create one clustered index on each table.

Friday, August 24, 2007

Why is manipulating the DOM hard?

Every browser has its own JavaScript rendering engine and it has its own DOM layout engine. TheW3C standardized the DOM in 1998, but browsers have been slow to provide uniform support of theW3C standards. Microsoft’s IE uses a DOM layout engine called Trident (or MSHTML), all Mozillabased browers (including Firefox and Netscape) use the open source Gecko layout engine, Safari usesApple’s WebCore, and Opera uses its own proprietary Presto layout engine. All engines support DOM1.0, but support for the later DOM 2.0 and 3.0 is still spotty.

Msxml2.XMLHTTP vs. Microsoft.XMLHTTP

If you look at different implementations of Ajax, you’ll notice that some use “Microsoft.XMLHTTP”and some use “Msxml2.XMLHTTP” when targeting IE’s ActiveX control. So what’s the difference? Asit turns out, very little when written like that. While the “Microsoft” namespace is older than the“Msxml2” namespace, written like this both statements will target MSXML 3.0 (the most widelydistributed version of MSXML). The latest version of MSXML, though, is version 6.0 (released July2006). Vista ships with version 6.0 installed and it is available for download for XP, Win2k, andWin2k3. To target the latest and most secure version of MSXML, you must use“Msxml2.XMLHTTP.6.0” to create your XMLHttpRequest. Leaving the version number off on a systemwith 3.0 installed will always target MSXML 3.0 (even if 6.0 is installed)