Profilo di Ashish"Getting better never st...FotoBlogElenchiAltro Strumenti Guida

Blog


30 giugno

The SOAP vs REST

A very interseting comparision of REST vs SOAP :-
 
An analogy of SOAP and REST is an envelop vs a postcard (which one is bulky..huh..! :-) )
07 giugno

Create a RESTful service using WCF

 

Ok,so I decided to learn creating the REST services using WCF.
First I had to download the following :-

a) WCF REST Starter Kit Preview 2

image

After you have installed the starter kit,you should see a set of templates under “File > New > Project”:-

image

06 giugno

Roadmap to learn REST (Representational State Transfer)

1) What is REST?
    a)Definition
    b)Tenets of REST ful services
    c)High REST and Low REST ful service   (“ 302- Object moved”  :-) - to the last point I need a lot to learn before I get back to this)
    d)Ways to develop REST ful services.

Question :- Are you comfortable confident in in REST for what you have read till now?

  1. 2) REST ful services using WCF
        a) How to map REST verbs with HTTP verbs
        b) Reading HTTP specification for the GET,POST,PUT and DELETE

Question :- Are you comfortable confident in in REST for what you have read till now?

    c) How to create a REST ful service?
        i) Get comfortable with the different templates of the REST starter kit.
        i) Making use of GET,POST,PUT and DELETE
        ii) When to use POST,PUT and DELETE
            Get the examples.
Question :- Are you comfortable confident in in REST for what you have read till now?
    d) How to consume a REST ful service?
        Create examples which do the following:-
            i) Use Yahoo search
            ii) Use Google search
            iii) Use Twitter
    e) Caching with REST
    f) Database operations with REST
Question :- Are you comfortable confident in in REST for what you have read till now?

1) c)High REST and Low REST ful service
Reading material :-
a) http://www.mnot.net/blog/2006/03/20/hi_lo
b) http://lesscode.org/2006/03/19/high-low-rest/

I started here at 12:33 PM 6/6/2009:-

What is a Service ?
- Means to get the resources get some operations done
What is REST ?

REST is an architectural style for building resource oriented services by defining the resources that implement uniform interfaces using standard HTTP verb LIKE Get,POST,PUT and DELETE.

Tenets of REST ful service:-
1)  Use the URI to locate the resources.
2)  Use the verbs to work with resources.
Get the resource :- GET
Do something with the resource :- POST,PUT,DELETE
3) The content type of the data sent to/received from the services is the object model
XML,JSON
4) Result of a service request is nothing but the HTTP result code.
200- OK,404-Not found

kcron This is from Ron Jacobs:-
Internet is a web of pages,right? and has following characteristics:-
A) Simple and Open

Addressing scheme – URI
Application Protocol – HTTP
Representational format – XHTML
Response codes – HTTP status

B) Scales best when

Stateless
Cached

C) Hyperlinks!- and right, internet would just suck if there are no links!

If you look at how we write web services,you see that we follow SOAP which in no doubt an incredible way of interoperability between the clients and the services.
Now HOLD ON.. before I say something anything against SOAP,why not consider something which also does the same/similar thing in a simplistic way. This makes us look at the ways how we can make “web of services” work like the “web of pages”.

 

    a) How to map REST verbs with HTTP verbs
    b) Reading HTTP specification for the GET,POST,PUT and DELETE

Have a look :-
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

Look at sections 9.3 for GET,9.5 for POST ,9.6 for PUT and 9.7 for DELETE. Here is the following:-

 

9.3 GET

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.

The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.

The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in section 13.

See section 15.1.3 for security considerations when used for forms.

9.5 POST

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:

      - Annotation of existing resources;
      - Posting a message to a bulletin board, newsgroup, mailing list,
        or similar group of articles;
      - Providing a block of data, such as the result of submitting a
        form, to a data-handling process;
      - Extending a database through an append operation.

The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.

The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.

If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header (see section 14.30).

Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.

POST requests MUST obey the message transmission requirements set out in section 8.2.

See section 15.1.3 for security considerations.

 

9.6 PUT

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.

If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.

The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource. If the server desires that the request be applied to a different URI,

it MUST send a 301 (Moved Permanently) response; the user agent MAY then make its own decision regarding whether or not to redirect the request.

A single resource MAY be identified by many different URIs. For example, an article might have a URI for identifying "the current version" which is separate from the URI identifying each particular version. In this case, a PUT request on a general URI might result in several other URIs being defined by the origin server.

HTTP/1.1 does not define how a PUT method affects the state of an origin server.

PUT requests MUST obey the message transmission requirements set out in section 8.2.

Unless otherwise specified for a particular entity-header, the entity-headers in the PUT request SHOULD be applied to the resource created or modified by the PUT.

9.7 DELETE

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.

A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.

If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.

 

Although HTTP fully supports CRUD, HTML 4 only supports issuing GET and POST requests through its various elements. This limitation has held Web applications back from making full use of HTTP, and to work around it, most applications overload POST to take care of everything but resource retrieval. HTML 5, which is currently under development, plans to fix this by adding new support for PUT and DELETE.

GET, HEAD, and OPTIONS are all examples of safe methods that aren’t intended to have side effects. All safe methods are also idempotent, as are PUT and DELETE, so you should be able to repeat them multiple times without harm. The POST method is something of a special case. According to the HTTP specification, POST should be used to provide a representation that can be treated as a subordinate of the target resource. For example, you could POST a new blog entry to the URI representing the blog feed, causing a new blog entry to be added to the feed. POST can also be used to process a block of data such as the data transmitted by an HTML form. The actual function performed by the POST method is defined by the server. Therefore, POST cannot be considered safe or idempotent by clients.

HTTP also defines a suite of standard status codes that specify the result of processing the request. Status codes are organized into ranges that mean different things. For example, status codes in the 200 range mean “successful” while status codes in the 400 range mean the client issued a bad request. Figure 2 describes each status code range and provides a few examples of common status codes.

28 gennaio

Quickly open a file in VS2005/VS2008

Just in case you know the name of a file and want to open the among many without finding in the solution explorer,check out the following option in the VS.NET.
Just type "> open" followed by first few characters of the file in the "Find" in the toolbar and it would give you all the matching results(irrespective of the location or extensiton). You just hit enter on the file you want to open.

Update  :- And how to go to that Find bar in the VS 2008. Just hit Ctrl+/ and you are there! :-)Just hit Ctrl+/ and you are there! :-)

 
 
26 gennaio

ASP.NET performace tricks

Performance Issues in ADO.NET DataTable Usage - Use Enum to Access Items in DataRow http://www.knowdotnet.com/articles/adoenums.html
03 gennaio

Lyrics - "You had me from hello" - song by Kenny Chesney

If there is one reason why I started liking country music,it is because of Kenney Chesney. He is an outstanding country singer and following is lyrics of one of the songs I really like. Its "You had me from hello".
 

One word, that's all you said
Somethin' in your voice caused me to turn my head.
Your smile, just captured me
And you were in my future as far as I could see
And I don't know how it happened, but it happened still
You asked me if I love you, if I always will

Well you had me from "Hello"
I felt love start to grow
The moment that I looked into your eyes, you won me
It was over from the start
You completely stole my heart
And now you won't let go
I never even had a chance you know
You had me from "Hello"

Inside, I built a wall
So high around my heart, I thought I'd never fall
One touch, you brought it down
The bricks of my defenses scattered on the ground
And I swore to me I wasn't gonna love again
The last time was the last time I let someone in

But you had me from "Hello"
I felt love start to grow
The moment that I looked into your eyes, you won me
It was over from the start
You completely stole my heart
And now you won't let go
I never even had a chance you know
You had me from "Hello"

That's all you said
Somethin' in your voice caused me to turn my head
You had me from "Hello"
You had me from "Hello"
Girl I've loved you from "Hello"

 
Some of his many gems are-
 
 
28 dicembre

My introduction to the Assembly Language

So,I started studying Assembly Language.It is very silly to say that it is interesting language at the first glance when you look at those hexadecimal codes with some weird command like MOV on the command prompt and also when you are coming from working on all the high level languages like C++,Java and C#.However,there is no denial to the fact that you start to learn a lot about the CPU architecture especially "registers". Most important thing is Assembly language is just one level up from the machine language and hence are bound to be real fast compared to the high level (read "layered/abstract/sugar coated") languages. I would be really cool if I can get my fundamentals straight out here and then get into something real deep. I am sure it would help me in writing efficient code (or better understanding) in the language I speak,C# ! :-) Why Assembly language all of a sudden?? Ok,ok,let me confess,it is one of the papers in my MS (Computer Science) degree. :-). I realized that this subject (which I have never worked on),deserves some time to be understood and and there is an opportunity to learn a new thing. See..I am thinking! :-)

I started with real basic introduction and a good place is http://www.swansontec.com/sprogram.htm. Which basically says that the Assembly language is a mnemonic language i.e. a set of instructions mapping to the machine language. It has a pretty small but basic example of creating a assembly language program.

I read about the Assemblers and Loaders which,respectively are responsible for converting the Assembly language to the machine language and loading the machine language to the memory.

26 dicembre

"kaise Mujhe Tum Mil Gayee" - From Ghajini

 
Just in case you cant see the video above..following is the link:-
 
Of all the songs from the soundtrack of Ghajini, my favorite is Kaise Mujhe Tu Mil Gayi. A great composition by A R Rehman, the lyrics by Prasoon Joshi,as usual are are really deep and meaningful. Listen to the song at the dead of the night and you'll really like it.

Hoo hooo oooo..
Hoo hoo hooo…
Oooo..hoo…hooo..oooo
Hooo hooo…

Kaise mujhe tu mil gayi,
Kismat pe aaye naa yaakeen,
Utar aayi jheel mein jaise chand utarta hai kabhi,
Haule haule dheere se,
Gunguni dhoop ki tarah se taranum mein tum,
Choo ke mujhe guzari hu yu,
Dekhu tumhe ya mein sunu,
Tum ho sukoon, tum ho junoon,
Kyu pehle naa aayi tum?
Kaise mujhe tu mil gayi, hoo hoo..
Kismat pe aaye naa yaakeen, hoo hoo..

Mein to yeh sochta tha ki aaj kal,
Upar wale ko fursat nahi,
Phir bhi tumhe bana ke woh,
Meri nazar mein chadh gaya,
Rutbe mein woh aur badh gaya..

Aaaa..aaaaa…
Aaaa..aaaa….
Hoo..hoo…hooo..

Badle raaste jharne aur nadi,
Badli deep ki timtim,
Chedhe zindagi dhun koi nayee,
Badli barkha ki rimjhim,
Badlengi rituyein adaa,
Par mein rahungi sada,
Ussi tarah teri bahon mein baahein daalke,
Har lamha, har pal..

Aaaa..aaaaa…
Aaaa..aaaa….
Zindagi sitar ho gayi,
Rimjhim malhaar ho gayi,
Mujhe aata nahi kismat pe apni yakeen,
Kaise mujhko mili tum
29 novembre

Gazal by Jagjit Singh - Hai Lau Zindagi

 
This is one of the numerous beautiful gazals from Jagjit Singh. I first heard this in a documentary named "Hello Zindagi" on Doordarshan hosted by Nalini Singh. I loved this song and after some searching I got this.
 
 
Lyrics:-
 
hai  lau  zindagi...zindagi noor hai
magar isme jalne(?) ka dastoor hai

adhoore se rishton me jalte raho
adhoori si sasson me pal te raho...
magar jiye jaane ka dastoor he...

rawayat hai ke zindagi gahana hai
ya heera hai aur chatate rahana hai
Ke lamhon main marne kaa dastoor hai-2

If you see a spelling mistake and ,please ldo me a favor to let me know and I would correct the same..

Thanks,
Ashish


08 agosto

Nice add-ins for Reflector

Nice add-ins for Reflector:-
 
 
(if you dont have reflector,download the same from http://www.aisto.com/roeder/dotnet).
 
One of the very useful add-in is the "diff" add-in. Which would point out the differences between the two versions of the same assemblies including any added/changed/deleted members/methods.
And also the "File Diassembler" where all you have to do is provide the assembly (with the dependent assemblies) you want to disassemble and it would generate the class library out of the same with all the source code.
Others are code search,Code Metrics and many more.
 
In order to use an add-in in the Reflector :-
a) Copy the all the binaries for the add-in in the same directory as the Reflector.exe.
b) In the reflector,View > Add-In. In the Add-ins dialog,Add the dll for the Add-in.
c) You should see the added "Add-In" under Tools menu.   
 
23 luglio

Gios PDF .NET library

Very sleek open source PDF creation library built in .NET and its up for commercial use.

http://www.codeproject.com/KB/graphics/giospdfnetlibrary.aspx

Use sections in the config file and access them...

(NameValueCollection)ConfigurationManager.GetSection("applicationSettings/ConnectionStrings");

for the following XML fragment in the config file:-
 
<applicationSettings>
<ConnectionStrings>
<add key="DevConnectionstring" value="server=myserver1;database=mydatabase;uid=ashish;pwd=password"/>
<add key="QAConnectionstring" value="server=myserver2;database=mydatabase;uid=ashish;pwd=password"/>
<add key="ProdConnectionstring" value="server=myserver3;database=mydatabase;uid=ashish;pwd=password"/>
</ConnectionStrings>
</applicationSettings>
02 giugno

Visual studio 2005 Build error :- The volume for a file has been externally altered so that the opened file is no longer valid

Just clean the solution and rebuild.
 
Just dont have any idea why the above error happened this morning when I tried to add some code to a windows service and tried to build the solution.But it has a simple resolution,just clean the solution. :-)  [Solution Explorer > Right click on the Solution> Select "Clean Solution"].
 
 
 
26 maggio

Convert string to byte array and viceversa

                   byte[] elementByteContent= contentObject.Content; //  this  byte array content
                    string elementStringContent = System.Text.Encoding.UTF8.GetString(elementByteContent);
                    elementStringContent = elementStringContent.Replace(" ", "");
                    if (elementStringContent == string.Empty)
                    {
                        elementStringContent = "<P>&nbsp;</P>";
                        contentObject.Content = System.Text.Encoding.UTF8.GetBytes(elementStringContent);
                    }

Removing comments using XPathNavigator.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);

 

#region Remove XML comments
System.Xml.XPath.
XPathNavigator path = xmlDoc.SelectSingleNode("w:document",xmlNSMgr).CreateNavigator();
System.Xml.XPath.
XPathNodeIterator commentsIterator = path.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);
if (commentsIterator.Count > 0)
{
while (commentsIterator.MoveNext())
{commentsIterator.Current.DeleteSelf();}}
#endregion

 

For the following XML:-(We needed to remove "<!--  Generated by Aspose.Words for .NET 4.4.1.0   --> ")

 

  <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
- <!--  Generated by Aspose.Words for .NET 4.4.1.0
  -->
- <w:body>
- <w:p>
- <w:r>
- <w:rPr>
  <w:b />
  <w:color w:val="FF0000" />
  <w:sz w:val="24" />
  </w:rPr>
  <w:t>Evaluation Only. Created with Aspose.Words. Copyright 2003-2007 Aspose Pty Ltd.</w:t>
  </w:r>
  </w:p>
  </w:body>
  </w:document>

Process.Start() - Open the file from the application after writing on the file

There are instances where you write to a file (say XML/Text file/word) fo debugging/testing etc.In those scenarios,your program finishes writing to the file and then you open the file manually in the application(IE/Notepad/Microsoft word) to see what the program has written in that file.You can actually launch that application after you finish writing to that file from with in the program making the whole process quick.The file opens in its default application right after you finish debugging without you needing to manually open it.
 
The steps:- (2 lines):-
 
a) Include the namespace:-
using System.Diagnostics;
b) Start the process for the saved file:-
//
//Code to save the file
//
 
// Following line would open the saved file in its default application
Process.Start("SavedFullFilePath");
 
 
Example:-
// Code to save the file
XmlDocument Xdoc = new XmlDocument();
string folderPath = @"C:\Ashish\";
string upload = folderPath + "2007.docx";
string savename = folderPath + "WordPackage.xml";
ZipPackage zipPackage = null;
byte[] packageData = null;
Stream stream;
packageData = GetBytesFromFile(upload);
stream =
new MemoryStream(packageData);
if (stream != null)
zipPackage = GetZipPackageFromStream(stream);
Xdoc = RRD.DSA.SCP.OfficeAssembler.
WordToXyXmlAssembler.ConvertToXyXml(zipPackage);
Xdoc.Save(savename);

// Following line would open the saved file in its default application (Internet explorer)
Process
.Start(strSave);
 
 
05 marzo

Checking for the existence of a temporary table

IF object_id('tempdb..#MyTempTable') IS NOT NULL
BEGIN
   DROP TABLE #MyTempTable
   PRINT 'Table dropped'
END
CREATE TABLE #MyTempTable
(
   ID int IDENTITY(1,1),
   SomeValue varchar(100)
)
GO

Returning value from sp_executesql

USE Northwind
DECLARE @Count int
execute sp_executesql
          N'select @Count = COUNT(*) from Northwind.dbo.Orders',
          N'@Count int OUT', @Count OUT
SELECT @Count
27 gennaio

baawra mann dekhne chala ek sapna - Lyrics

baawra mann dekhne chala ek sapna ..
baawra mann dekhne chala ek sapna ..
baawre se man ki dekho, baawri hain baatein
baawre se man ki dekho, baawri hain baatein
baawri si dhadkanein hain, baawri hain.. saansein
baawri si karvaton se, nindiya door bhaage
baawre se nain chahe.., baawre jharokhon se.., baawre nazaaron ko takna..
baawra mann dekhne chala ek sapna ..
baawre se is jahaan mein, baawra ek saath ho
is sayaani bheed mein, bas haathon mein tera haath ho
baawri si dhun ho koi, baawra ek raag ho
baawri si dhun ho koi, baawra ek raag ho
baawre se pair chahe.., baawre taraanon ke.., baawre se bol pe thirakna ..
baawra mann dekhne chala ek sapna ..
baawra sa ho andhera, baawri khamoshiyan
baawra sa ho andhera, baawri khamoshiyan
thartharaati lau ho madham , baawri madhoshiyan
baawra ek ghunghtha chahe, haule haule bin bataaye
baawra ek ghunghtha chahe.., haule haule bin bataaye.., baawre se mukhde se sarakna ..
baawra mann dekhne chala ek sapna ...
baawra mann dekhne chala ek sapna ...
 
16 dicembre

can not drop user from database

Problem :-
 
I can not delete user from a database in sql2005 beta 3.
the message errror is :

TITLE: SQL Server Management Studio
----------------------------------------

Drop failed for User 'Amministratore'.  (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft SQL Server&ProdVer=9.00.0981.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Drop+User&LinkId=20476

----------------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

----------------------------------------

The database principal owns a schema and cannot be dropped. (Microsoft SQL Server, Error: 15138)

 

 

 

Solution:-

1) Expand Schemas(should be like a folder under <yourdatabase> -> Security) .
2) Script the the unwanted "userSchema" save it and and then Delete the schema.
3) Then, go back to the User,script the user and then delete the user.

4) Associate the schema back to the user by running the script.