
Intel MID
Blog moved to http://weblogs.asp.net/shijuvarghese/
REST Vs SOAP - Which is the best approach?
Software Architects have been involving a never-ending debate about whether SOAP-based or REST-style web services are the right approach and recently the debate is too heating up. Yahoo's web services are using REST and google using SOAP for their web services. Some organizations have web services for both REST and SOAP. REST is Lightweight than SOAP because it does not requires lot of xml markup like SOAP.
I believe that SOAP will be the primary choice for intranet and enterprise level applications because SOAP and the WS-* specifications addresses many challenges of enterprise level applications such as reliability, distributed transactions, and other WS-* services. But I think open, Internet applications will gear towards to REST because of REST’s explicitly Web-based approach and its simplicity.
RESTful services for WCF 3.5
WCF 3.5 provides explicit support for RESTful communication using a new binding named WebHttpBinding.
The below code shows how to expose a RESTful service
[ServiceContract]
interface IStock
{
[OperationContract]
[WebGet]
int GetStock(string StockId);
}
By adding the WebGetAttribute, we can define a service as REST based service that can be accessible using HTTP GET operation.
WPF introduces the eXtensible Application Markup Language (XAML). XAML provides an XML-based way to specify declaratively a hierarchy of objects with properties and logic. We're positioning XAML as a user interface design language. XAML gets compiled into an object definition. XAML defines a set of XML elements such as Button, TextBox, Label, and many more to define exactly how a user interface looks. XAML elements typically have attributes as well, allowing various options to be set.
WPF allows specifying an interface using the XAML. Elements and attributes in XAML map directly to the classes and properties that WPF provides. For example, here’s a simple button defined in XAML:
<button background="">
Ok
</button>
This example creates a red button that contains the text “Ok”. The exact same result could also be produced with the following code:
Button btn = new Button();
btn.Background = Brushes.Red;
btn.Content = “Ok">However it’s defined, a WPF application can rely on panels for basic layout. Each panel typically contains controls, and those provided by WPF include Button, TextBox, ComboBox, Menu, and many more. How those controls are positioned depends on what type of panel is chosen. A Grid, for instance, allows positioning controls on a specified grid, while a Canvas lets the developer place controls anywhere within its boundaries. And as usual in a GUI, events generated by the user are caught and handled by the various controls and other classes in the application. It’s also possible to apply styles and templates to groups of controls, which makes it easier for applications to have a uniform look.
WPF supports much more than these basic user interface functions, including the following:
Documents: A WPF application can display XPS documents using XAML’s FixedDocument tag. An application can also display flow documents using the FlowDocument tag. A flow document can behave like a traditional on-screen document, allowing the user to scroll through its contents. By setting various attributes on this tag, however, a developer can make the document more adaptive to its surroundings. A document can display a page at a time, for example, freeing its reader from the need to scroll back and forth. The goal is to allow on-screen documents to be as readable as possible.
Graphics: WPF includes support for creating two-dimensional and three-dimensional vector graphics. For 2D work, WPF provides standard abstractions such as shapes, brushes, and pens, while 3D graphics allowing defining a model that can be assigned lighting and camera position information. Unlike earlier technologies such as Windows Forms, which relies on GDI+ for graphics, WPF graphics aren’t cabined off using a separate set of concepts that developers must understand. Instead, the XAML elements used for graphics can be combined naturally with those used for anything else in a user interface.
Images: Using XAML’s Image tag, a WPF application can display images in various formats, including JPEG, GIF, and others.
Media: A WPF application can use the MediaElement tag to display video and audio in various formats, including WMV, AVI, and MPEG.
Animation: WPF provides built-in support for animating most parts of a user interface. A circle can grow and shrink, for example, or a button can smoothly change size. Applications can also define storyboards containing timelines, allowing coordinated sequences of animations to occur.
Data Binding: Because many WPF applications display data, it’s useful to have automatic support for mapping data to user interface elements. WPF provides this kind of data binding for information contained in objects and other sources.
Windows CardSpace
Windows CardSpace provides the consistent user experience required by the identity metasystem. It is specifically hardened against tampering and spoofing to protect the end user's digital identities and maintain end-user control.
Think about how people represent themselves today on the Internet. In the majority of cases, a person’s digital identity is expressed as a simple username. Combined with a password, this identity is used to access email accounts, Internet merchants, and even on-line banks and other financial institutions. Yet despite their popularity, usernames and passwords have several drawbacks. Here are the two most important:
1)People have a hard time remembering all of the usernames and passwords they’ve chosen for different sites. Many people use the same values for different sites, easing the memory problem but increasing the security risk.
2)Usernames, passwords, and other personal information can be stolen by phishers. By sending deceptive emails, phishers entice their victim to log into a Web site that looks just like, say, the site of the victim’s bank. The site is actually controlled by the phisher, however, and so once the victim enters his username and password, the phisher can use this information to masquerade as the user at the real site.
Reducing the severity of these problems requires a new approach to managing digital identities. Windows CardSpace, originally released with the .NET Framework 3.0, is an important part of that approach. To help people keep track of their digital identities, CardSpace represents each identity as a distinct information card. If a Web site accepts CardSpace logins, a user attempting to log into that site will see a CardSpace selection screen like the one below. By choosing a card, the user also chooses a digital identity that will be used to access this site. Different cards can contain different information, allowing a user to control exactly what each site learns about her.
<script type=\"text/JavaScript\">
var xmlHttp;
//function creating new instance of XMLHttpRequest object
function createXMLHttpRequest() {
//In IE XMLHttpRequest is a ActiveX object
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");
}
//non IE browsers
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
//function call asynchronous request to server
function startRequest() {
createXMLHttpRequest();
//set callback method
xmlHttp.onreadystatechange = callBackMethod;
var url=\"MyAjaxServer.aspx\";
//instantiate request
xmlHttp.open(\"GET\",url, true);
//send request to server
xmlHttp.send(null);
}
//callback method
function callBackMethod()
{
}
</script>
<b>Search For Books</b>
<span id=\"header\"></span>
<table width=\"500\" border=\"0\">
<tbody>
<tr>
<td>Search</td>
<td><input onkeyup=\"doSearch(this.value);\" size=\"40\">
</td>
</tr>
<tr>
<td colspan=\"2\">
<table id=\"tblSearchResults\" width=\"100%\" border=\"0\">
<tbody id=\"tbSearchResults\"></tbody>
</td>
</tr>
</tbody>
</table>
td></tr></tbody></table>
JavaScript Code(search.js)
//global variable for hold XMLHttpRequest Object
var xmlHttp;
//Creating and setting the instance of appropriate XMLHTTP Request object to a "xmlHttp" variable
function CreateXmlHttp()
{
//Creating object of XMLHTTP in IE
try
{
//it will work if IE have JavaScript version 5.0
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
xmlHttp = null;
}
}
//Creating object of XMLHTTP for non-IE browsers
if(!xmlHttp && typeof XMLHttpRequest != "undefined")
{
xmlHttp = new XMLHttpRequest();
}
}
//function to search
function doSearch(searchText)
{
//create XMLHttpRequest Object
CreateXmlHttp();
//Requested url
var ajaxRequest="ProcessSearch.aspx?search="+searchText;
//set callback function
xmlHttp.onreadystatechange = callBackMethod;
//Initializes request
xmlHttp.open("GET",ajaxRequest, true);
//send request
xmlHttp.send(null);
}
function callBackMethod()
{
//if request completed sucessfully clear the previous result and show the new search results
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
clearResults();
showResults();
}
}
}
//function clear previous results
function clearResults()
{
var tableBody = document.getElementById("tbSearchResults");
while(tableBody.childNodes.length > 0) {
tableBody.removeChild(tableBody.childNodes[0]);
}
}
//function show search results in a table
//dynamically creating table rows for show the results
function showResults() {
var results = xmlHttp.responseXML;
var book = null;
var title = "";
var author= "";
var publisher = "";
var books = results.getElementsByTagName("book");
if(books.length<1)return; i =" 0;" book =" books[i];" title =" book.getElementsByTagName(" author =" book.getElementsByTagName(" publisher =" book.getElementsByTagName(" row =" document.createElement(" cell =" createCellWithText(title);" cell =" createCellWithText(author);" cell =" createCellWithText(publisher);" cell =" document.createElement(" textnode =" document.createTextNode(text);" row =" document.createElement(" cell =" createCellWithText(" cell =" createCellWithText(" cell =" createCellWithText(" search =" Request["> 0)
{
Response.Clear();
DataSet dsResults=new DataSet();
//call business layer method for search results
dsResults =Books.GetBookList(dsResults);
string resultsString= dsResults.GetXml();
Response.Clear();
Response.ContentType ="text/xml";
Response.Write(resultsString);
//end the response
Response.End();
}
else
{
//clears the response written into the buffer and end the response.
Response.Clear();
Response.End();
}
}
else
{
//clears the response written into the buffer and end the response.
Response.Clear();
Response.End();
}
}