Saturday, May 01, 2010

REST vs SOAP

 

REST

SOAP

Simple HTTP next DCOM
not transport neutral transport neutral
  message based security
only CRUD operations CRUD + more
can scale ?
broader reach and interoperability ?
std format using GET,PUT,POST,DELETE format is SOAP envelope,header,body
no need for WSDL  
data format can be JSON or XML  
easy to version and evolve ?
bookmarking and caching can be done cannot be done
Cloud computing people are using REST ?

SOAP is typically used in enterprise scenarios as middleware and most of the operations are pretty much CRUD operations.

Why REST :

  • if you only do HTTP
  • if you don’t need WS* and web Security(SSL) is good enough
  • Simpler than SOAP , uniform, comparable

Why SOAP :

  • if you need message based security – banks
  • your services are middle ware rather than public web services(web facing)
  • your services are local to enterprise

My post here tells you what REST is, however that is the most common understanding of REST, the definition goes beyond it, ex.

  • that resources be self-describing
  • complete object should be provided to POST/PUT instead of key value pairs of updates
  • collection of resources should be resource that represents a collection of other resources

World wide web is a RESTful system. Does your browser (the client) know whether it’s displaying a banking website or a casual game? Nope, it just utilizes standard media types (HTML, CSS, Javascript) to compose and represent the data. You don’t have to know the specific URL you’re looking for on a website so long as you know the “starting place” (usually the domain name) and can navigate there.

So REST is an ingenious and flexible way to allow for the consumption and traversal of network-available information. What it’s not, however, is a very good roadmap toward building APIs for web applications.

webHttpBinding - REST in WCF (Part 3)


Now we know that using [WebGet] we can get a resource based on URI. This is just the GET verb of HTTP, we also have other Verbs – PUT,POST,DELETE. To use these verbs WCF has the [WebInvoke] attribute.

However we cannot allow anyone to PUT,POST,DELETE our resources, so we will typically have some authentication process before we can allow this. This is achieved by reading and writing to the HTTP context. It can also be used to control caching, set content type, etc.

Taking the .svc Out of REST
WCF Services hosted in IIS use the .svc extension. This does not follow common REST URI naming practices. For example, the service in Part 1 and 2 is accessed using the following URI:
http://localhost/TimeService.svc/Now?GMT=1
You can remove the .svc extension by using an ASP.NET HttpModule (with IIS 7.0 only) to call HttpContext.RewritePath to modify the URI. This would allow the URI to take the following form: http://localhost/TimeService/Now?GMT=1


Technorati Tags: ,

webHttpBinding – REST in WCF (Part 2)


In Part 1, the service was exposed as /Now?GMT=5, now the solution is updated to handle request such as /GMT/5

Download the complete solution using an SVN client from here

[OperationContract]
[WebGet(UriTemplate = "/GMT/{GMT}")]
string GMT(string GMT);

Sunday, April 18, 2010

webHttpBinding – REST in WCF (Part 1)


REST stands for Representational State Transfer

It basically means exposing services

  • based on URI
  • encode message without the overhead of SOAP
  • pass parameter using HTTP
  • format data using JSON or POX

Service Contract

Get the complete code solution from this SVN url : http://subversion.assembla.com/svn/TechnologyAndMe/RestTimeService

using System.ServiceModel;
using System.ServiceModel.Web;

[ServiceContract]
public interface ITimeService
{
[OperationContract]
[WebGet]
string Now(string GMT);
}


Web.Config





behaviorConfiguration="webBehavior">

















Now to access the service hit the service with this url

http://localhost:3048/TimeService.svc/Now?GMT=1


The output is as follows


GMT 14/18/2010 23:23:58

Friday, April 09, 2010

Whitespace – Cleanest programming language


http://compsoc.dur.ac.uk/whitespace/

From their homepage -
“Most modern programming languages do not consider white space characters (spaces, tabs and newlines) syntax, ignoring them, as if they weren't there. We consider this to be a gross injustice to these perfectly friendly members of the character set. Should they be ignored, just because they are invisible? Whitespace is a language that seeks to redress the balance. Any non whitespace characters are ignored; only spaces, tabs and newlines are considered syntax.”

WTF. Now talk about dirty code.

User story formats

 

Now, usually the user stories that we write are of the format :
As A Bank Teller, I Want a name search field, So That I can quickly look up customers.

But like someone pointed out, it makes much more sense to construct the story as follows:
So That I can quickly look up customers, As A Bank Teller, I Want a name search field.

Further more, now we can relate the So That to actual business values and we also got rid of explicit implementation details from I Want, as follows:
So That I can serve customers faster, As A Bank Teller, I Want an efficient way to look up customers.

Sunday, April 04, 2010

WPF window phases

 

1. Constructor is called.
2. Window.Initialized event is raised.
3. Window.Activated event is raised.
4. Window.Loaded event is raised.
5. Window.ContentRendered event is raised.
6. User interacts with the window.
7. Window.Closing event is raised.
8. Window.Unloaded event is raised.
9. Window.Closed event is raised.