ASP.NET Web API is the framework for creating HTTP services or RESTful services in the Microsoft platform. It super-cedes the WCF framework. Browsers in desktops, tablets or mobiles can access the Web API.

Comment API

In this post, we create a Web API for Comments. Create a new MVC application. Create a controller called CommentController. It is an API controller with CRUD methods and integrates with Entity Framework.

There are methods for GET, GET(1), PUT, POST and DELETE. The URL for API is http://localhost:port/api/Comment. APIs return JSON data.

WPF Client

Next, we create a WPF application. It uses a HTTP client to access the Web API. The WPF application has the DataGrid layout, which displays all comments in a grid like fashion. The DataGrid is bound to an ObservableCollection<Comment>. Each row contains a Delete button to delete the comment.

There is also a Save button. Save enumerates through each comment and updates the comment using a PUT operation. If the update fails because the comment does not exist, we create the comment using a POST operation.

The entire project can be found here: CommentApiDemo

Using a WPF client to access MVC Web API
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *