Wednesday, June 1, 2011

Again chines hacker hacked google account !!

On Tuesday, Google revealed on its blog that it had been the target of a phishing campaign seemingly originating in Jinan, China, and aimed at gaining access to the accounts of senior officials in the U.S., Korea and other governments, as well as those of Chinese activists.

This kind of hacking is not new for google. Last year january also it happened where all webmail services–was vulnerable to this sort of spoof attack. That time google was seriously planing to close there operation in china. 

See how this time hacker phishing the account. 

Wednesday, May 25, 2011

CREATE WCF POST Restful service


In my last article to explain about WCF Restful service using HTTP Get method.  This works well as long as you are sending small data as information to the service. But if want to deliver huge data, HTTP GET Method is not a good choice.  

When i write any WCF service, i always use POST. Reason is the advantage of POST over GET. Using HTTP POST method, you can almost achieve everything which you can achieve from GET. Despite of this you will get some additional feature if use POST. We might say that "GET" is basically for just getting (retrieving) data whereas "POST" may involve anything, like storing or updating data, or ordering a product, or sending E-mail etc. 
1) Easy Character Encoding using application/x-www-form-urlencoded
2) No Proxy by default so always actual data from web server. 
3) Data length can be restricted by webserver, not by browser.

1) Character encoding will reduce the amount of data that can be used because of url encoding entities (i.e. three Japanese characters are converted to this: %26%2312454%3B%26%2312455%3B%26%2312502%3B)
2) Running a http request with GET can be cached on your web browser or a configured proxy server.
3) Maximum URL length is 2,083 characters in Internet Explorer (see MaxClientRequestBuffer: Use POST instead of GET to Send Large Amounts of Data in Request)
and lot more  
Extremely long URLs are usually a mistake. URLs over 2,000 characters will not work in the most popular web browser. Sending long information via URL is not a good way of implementation and also there has many restrictions i.e. max length of URL, Information format bla bla bla. For example Internet Explorer has a limitation implemented at 2083 characters. URIs is meant to be readable not to send information. 
So if you are writing any REST service and your information is long enough, better to choose POST instead of GET method.
In this article, i am going to create WCF Restful service using POST method and access it using HTTP Request. So we will have client and server both in this example code. I am creating one service which accepts HTTP Post XML request and response request data in XML format.  

Launch Visual Studio 2010. Click FILE->NEW->PROJECT. Create new "WCF Service Application". .


Once you create the project, you can see in solution that By Default WCF service and interface file are already created. Delete By default created file as we will create our own interface and WCF service file.

Now right click on solution and create one new WCF service file. I have given name to the service file as “RestServiceImpl.svc”.

We will create two DataContract classes for request and response purpose.

RequestData will receive the request from the client and ResponseData response. One very important thing is that POST XML format to the service should be same as RequestData. So the post xml request format can be like below:  

We must have to use namespace for the data contract in POST RESTFul service, which have multiple use i.e. reflects the current version of your code. The Same namespace should use in XML to Post data. Here i have given as namespace which can be changed.

Now we will write the OperationContract in IRestServiceImpl which is an interface.  Below is the code for that. 

As we can see in above code that here, Request and Response format is XML. We can change it to JSON also by changing the WebMessageFormat  from WebMessageFormat.Xml to WebMessageFormat.Json 

Implementation of Auth OperationContract in RestServiceImpl.svc.cs here.

Now let’s move to configuration part which is the last one. There will be two basic parts of the configurations file which we must have to understand.


And that’s it. Our Restful WCF POST RESTful service is ready to test. SERVICE IS READY I have created one Test WebClient in C# which makes Http request with some XML data. My application is hosted on localhost and URL is http://localhost:35798/RestServiceImpl.svc/auth . I launched and invoked service using WebClient. Below is my XML response which is correct one.

This service can be used by any language application (.NET, PHP, JAVA etc) and that is the major reason to use REST service in the application. 

Hope the article is useful for the community. Comments, suggestions and criticisms are all welcome.

You can download the source code from here .   

Thanks a Lot


Thursday, April 14, 2011

Using VS 2010 for developmement? Use Code Map extension. Great one.

Hello All

During development of enterprise application, we always have challenge to visualise the type nesting, implemented interface, member and scope, collection of all the valuable comment etc.
Recently i found one extension file which integrate with Visual Studio Solution and solve all my above mentioned issue.

There has few good tools in the market which solve this issue partially i.e. resharper etc. But they are paid one and expensive also.

VS10x Code Map is a Visual Studio 2010 extension that displays a graphical nested representation of the current code editor window (C# and VB.NET). This extension is free and can be downloaded from here. It’s very light weight (unlike resharper. It sucks :( ) and does not make any impact on your code performance.

So it’s time to evaluate this tool.

Code Visualization
If you see below screen, you can find that the left side there has a Code Visualise Window which is Code Map tool. Once you install Code Map, this tool will appear in every .cs and .vb file of your VS editor. You can see that it display all the method and interface details. Also you can easily navigate to the interface which is used in the method. On the click of each method in left windows, you will be focused on that method implementation.

Global Solution History
This widow will allow you to display all the history of the page including method name which you browsed in current session. It displays in proper format and if you click on the details, it will focus on that method in the VS editor. Please see below:

Bookmark Listing
In large code files, a code elements-based code map might not be enough. If you find yourself looking over and over for certain positions in code, then named bookmarks are for you. Simply start a comment with the BMK token and then type in a meaningful name (this will end up with something like //BMK Some name here in C# or 'BMK Some name here in VB) and VS10x Code Map will pick that up and add the name at the top of the containing element, so that you can find it instantly.

There has lot more in this tool which makes your development process ease and fast. I recommend this software to everyone who is using VS 2010 for development.

Hope this article is useful for you. Comments, suggestions and criticisms are all welcome.


Saturday, September 18, 2010

Internet Explorer 9.0 . Feature of Chrome + Mozila

Hi Folks
Few days back Microsoft has launched their new Internet Explorer Version 9.0 (BETA). As per Microsoft “Internet Explorer 9 has a streamlined design, fewer dialog boxes to click through, more intuitive navigation, and many new features that speed up your web browsing experience. Features like Pinned Sites let you pin your favourite website directly to the taskbar for one-click access. Other features, like hardware acceleration, deliver an all-around faster browsing experience. With Internet Explorer 9, websites perform and feel more like the programs you use every day on your PC.”
I also decided to install it on my machine.

After installation, need to restart the machine..

Installed and ready to use...

I feel really nice with this. I can see collective feature of Chrome and Mozilla. Below is the new feature listing of Internet Explorer 9.0 (BETA):
1. Streamlined design
2. Pinned Sites
3. Download Manager (Same as Chrome and Mozilla)
4. Enhanced tabs
5. New Tab page
6. Search in the address bar
7. Notification Bar

And the best part which i really like is "Add-on Performance Advisor" and "Hardware acceleration" mechanism. I recommend this software to install it and test it. You will also feel good.

So finally i can say that Internet Explorer 9.0 is rocking...

Monday, August 30, 2010

Create RESTful WCF Service API : Step By Step Guide

Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for your services, enabling you to expose CLR types as services, and to consume other services as CLR types. In this article I am going to explain you how to implement restful service API using WCF 4.0 . The Created API returns XML and JSON data using WCF attributes.

What is REST?
Based on Roy Fielding theory "Representational State Transfer (REST), attempts to codify the architectural style and design constraints that make the Web what it is. REST emphasizes things like separation of concerns and layers, statelessness, and caching, which are common in many distributed architectures because of the benefits they provide. These benefits include interoperability, independent evolution, interception, improved scalability, efficiency, and overall performance."
Actually only the difference is how clients access our service. Normally, a WCF service will use SOAP, but if you build a REST service clients will be accessing your service with a different architectural style (calls, serialization like JSON, etc).
REST uses some common HTTP methods to insert/delete/update/retrive infromation which is below:
a) GET - Requests a specific representation of a resource
b) PUT - Create or update a resource with the supplied representation
c) DELETE - Deletes the specified resource
d) POST - Submits data to be processed by the identified resource

Why and where to use REST?
Few days back i was writing a service which was suppose to access by heterogeneous language/platform/system. It can be used by iPhone, Android, Windows Mobile, .NET web application, JAVA or PHP. Using web service it was bit complex for me to expose it to everyone using uniform system. Then we decided to use REST, which was easily espoused over cloud. This was a great example which shows the capability of SIMPLE RESTful SERVICE :) . Below is some point which will help you to understand why to use the RESTful services.
1) Less overhead (no SOAP envelope to wrap every call in)
2) Less duplication (HTTP already represents operations like DELETE, PUT, GET, etc. that have to otherwise be represented in a SOAP envelope).
3) More standardized - HTTP operations are well understood and operate consistently. Some SOAP implementations can get finicky.
4) More human readable and testable (harder to test SOAP with just a browser).
5) Don't need to use XML (well you kind of don't have to for SOAP either but it hardly makes sense since you're already doing parsing of the envelope).
6) Libraries have made SOAP (kind of) easy. But you are abstracting away a lot of redundancy underneath as I have noted. Yes in theory SOAP can go over other transports so as to avoid riding atop a layer doing similar things, but in reality just about all SOAP work you'll ever do is over HTTP.

Step by step guide
Generally developer scared to use WCF because lot of confusing configuration. I will try to use minimum configuration so that it will be easier to understand for us. We will develop Restful WCS API in 6 steps. So let’s start now.

STEP:1) First of all launch Visual Studio 2010. Click FILE->NEW->PROJECT. Create new "WCF Service Application" .

STEP-2) Once you create project, you can see in solution that By Default WCF service and interface file is already created. Delete By default created file as we will create our own interface and WCF service file.

STEP-3) now Right click on solution and create one new WCF service file. I have given name to the service file as “RestServiceImpl.svc”.

STEP-4) As i explained in starting of the article that we will be writing an API which can return data in XML and JSON format, here is the interface for that. In IRestServiceImpl , add following code.

In above code, you can see two different method of IRestService which is XMLData and JSONData. XMLData Returns result in XML whereas JSONData in JSON.

STEP-5) Open the file RestServiceImpl.svc.cs and write following code over there..

STEP-6) Now let’s move to configuration part which is the last one. There will be two basic part of the configuration file which we must have to understand...

This part contains information about the End Point. below is the code detail..

This part contains details about service and endpoint behavior.

And that’s it. Our Restful WCF service is ready for test purpose.

Service Ready to Test Now
Now i launch the application in browser to see the result. I launch this service in IE and my URL is now http://localhost:35798/RestServiceImpl.svc . Now if i use http://localhost:35798/RestServiceImpl.svc/xml/123 URL, i get following response on the browser which an XML format and that was my task to achieve.

Now if i use http://localhost:35798/RestServiceImpl.svc/json/123 URL, i get following response on the browser which an XML format and that was also my task to achieve.

Hope the article is useful for community. You can download this code from here. Comments, suggestions and criticisms are all welcome.