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

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

 Subscribe to Articles

Step by Step RESTfull service creation using WCF

Posted By:Mahesh       Posted Date: March 13, 2012    Points: 200    Category: WCF    URL: http://www.dotnetspark.com  

This article helps in Step by Step creation of RESTfull service using WCF service.

WCF most importantly includes elements for REST application are [WebGet] and [WebInvoke] attributes and the new binding webHttpBinding in connection with the webHttp endpoint behavior.

webHttpBinding endpoint enables you to choose from two different serialization formats:
•POX (Plain old XML) uses XML, without SOAP overhead.
•JSON (JavaScript Object Notation) very compact and efficient format, primarily in connection with JavaScript.

1) Create Data Contract

public class Product
    public string ProductName { get; set; }
    public int Qty { get; set; }
    public double Rate { get; set; }

2) Define Service Contract
public interface IProductService
    [WebGet(UriTemplate = "/GetProductObj")]
    Product GetProduct();
    [WebInvoke(UriTemplate = "/DeleteProduct/{ProductName}",
    Method = "DELETE")]
    void DeleteProduct(string ProductName);

3) Implement Service Contract
public class ProductService :
    public Product GetProduct()
        Product stdObj = new Product {
                    ProductName = "Foo",
                    Qty = 2,
                    Rate = 100 };
        return stdObj;

    void DeleteProduct(string ProductName)
        // delete logic

4) Use webHttpBinding (change default http port mapping to webHttpBinding) 



5) Specify webHttp End Point Behaviors




6) Test the Service

Conclusion: In this way we can create a RESTfull service using WCF service.

 Subscribe to Articles


Further Readings:


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