.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!



Home >> Articles >> WCF >> Post New Resource Bookmark and Share

 Subscribe to Articles

Three way to form URI for REST Services

Posted By :Dhananjay Kumar      Posted Date :29/07/2010   Points :25   Category: WCF    URL: http://www.dhananjaykumar.net

In this article, I will show how we could construct URI in three ways.
 


Objective 


In this article, I will show how we could construct URI in three ways. 


Method # 1: Creating URI from string 


I am passing string in constructor of URI class, to create new URI. 


1.gif

Codeview of the above image

#region Creating URI from string 
string url = "http://dhananjaykumar.net/feed/";
Uri uri = new Uri(url);
Console.WriteLine(uri.AbsoluteUri);      
Console.Read();
#endregion 


Output


2.gif 


Method #2: New URI from Component Instance 


I am here taking host and path individually and then combining them in constructor of Uri class. 


3.gif

Codeview of the above image
#region Creating URI from Component Instance 
    string host = "http://dhananjaykumar.net";
    string path = "/feed";
    Uri uri1 = new Uri(host);
    uri1 = new Uri(uri1, path);
    Console.WriteLine(uri1.AbsoluteUri);
    Console.Read();
#endregion 


Output


4.gif 


Method #3: Creating URI using Try Pattern validation 


In this , I am showing you how could we use Try Pattern method of URI class to construct an URI. 


5.gif

Codeview of the above image

#region Create New URI Try Pattern Validation 
    string url = "http://dhananjaykumar.net/feed/";
    Uri uri2; 
            
    if(Uri.TryCreate(url,UriKind.Absolute , out uri2))
    {
        Console.WriteLine(uri2);

    }
    Console.Read();
#endregion 

Output

6.gif

You can also download the code from below link



Featured Articles


Design Pattern Interview Questions Part (3)
Software Architecture Interview Questions Part 3 State Pattern, Stratergy pattern,Visitor pattern, Adapter and fly weight ... Read More
Software Architecture Interview Questions Part 4- Design Patterns
(A) Can you explain bridge pattern? (A) Can you explain composite pattern? (I) Can you explain decorator pattern ? (A) Can you explain Façade pattern? (A) Can you explain chain of responsibility ( COR)? (I) Can you explain proxy pattern? (B) Can you explain template pattern? ... Read More
UML Interview Question Part 1
(B) Define UML? (I) Can you explain use case diagrams? (I) Can you explain primary and secondary actors? (I) How does a simple use case look like? (I) Can you explain 'Extend' and 'Include' in use cases? (I) Can you explain class diagrams? (B) How do we represent private, public and protected in class diagrams? (I) what does associations in a class diagram mean? (I) Can you explain aggregation and composition in class diagrams? (A) What are composite structure diagram and reflexive association in class diagrams? ... Read More
Responses

No response found. Be the first to respond this post

Post Comment
You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend