Monday, February 23, 2015

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman

In this article we'll learn Step by step how to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman
We'll use Postman to test a RESTful OData Web API application, sending an HTTP POST request. We'll start with a working OData Web API built on an ODataController , which we built in a previous tutorial,   and we'll create an entry using  Postman . After we create a new record , we check it sending an HTTP GET request :



HTTP POST Request to a RESTful OData Web API Service using Postman
In order to get Postman , just go to the Tools >> Extensions on Chrome , do a search for "Postman" and install the App .

HTTP POST Request to a RESTful ODataController Web API Service using Postman



Open Postman and select "POST" from the list :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman  1

Now let's learn how to call the OData Web API : in MVC , in order to setup  the ODataController , there must be an ODataModelBuilder registered at the "Register" method called from the Global.asax file : as you see in the following snapshot , the EntitySet name MUST be the name of the Controller ( "Notes" in our case ) , so we'll look for a "NotesController" ODataController at the application :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   2
Also , there is a route prefix declared ( "ODataV4" ) , so we'll append it to the URI . 


How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   3

Found the ODataController , now we check for the "Post" action method , because we're sending an HTTP POST request :


How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman     4
Why are we checking this ? Because we want to know which kind of object is the ODataController method expecting : in our case , it expects a "Note" object , which must be included in the request's body ( "[FromBody]" ) . How to create a Note object ? Look at the declaration inside the Model :


How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   5

Now we know that a Note must include all of those properties.
You could send an OData request asking for the METADATA information to construct the Note object , but that way you won't know the constraints declared with Data Annotations at the Model :

http://localhost:21435/ODataV4/$metadata

The Port of the application can be extracted from the Web tab at the application properties:

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   6

Put all of this together , and you have the URI for the POST request : "http://localhost:21435/ODataV4/Notes" :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   7

Important : OData protocol is case sensitive : therefore , if you type "notes" instead of "Notes" , you will not reach the controller.

After setting the URI and the POST method , set the "Content-Type" header :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman  8

Next , build the JSON object to be sent inside the request's body , according to the Data Annotations :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   9

Send the request :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman  10

Postman is waiting for the response :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   11

In the meantime , the ODataController at the RESTful WebAPI have gotten the JSON object and bound it to a local variable : 

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman    12
The action method renders a response with code 201 CREATED , and Postman exposes it : 


How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   13

Finally , if you want to , send a HTTP GET request to check for the new record added to the database :

How to send an HTTP POST Request to a RESTful ODataController Web API Service using Postman   14




That's all... 
In this tutorial we've learned how to send an HTTP POST Request to a RESTful  ODataController Web API Service using Postman.
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן









Sunday, February 15, 2015

#1 - How to Install SQL Server 2012 Express

In this article we describe How to Install SQL Server 2012 Express,  viewing step by step the SQL Server Setup of the free SQL Server 2012 Express version .
The SQL Server Setup can be a bit tricky, because of the many options that we must be very careful to set :
How to Install SQL Server 2012 Express



How to Install SQL Server 2012 Express





How to Install SQL Server 2012 Express      1


Once there, click the Download button, to begin the Setup:
How to Install SQL Server 2012 Express      2


There, select the upper option - "Stand alone Installation". On the next dialog, check the "I Accept..." option:

How to Install SQL Server 2012 Express      3


The next dialog should remain untouched, and click "Next" to proceed: 


How to Install SQL Server 2012 Express    4

The next window shows all available features at the Express SQL Server version. Here you will select all options available:

How to Install SQL Server 2012 Express    5

The "Management Tools" installs the Sql Server Management Studio (SSMS) , and this is a very important feature that you will need to manipulate the data, develop queries, create user defined functions (UDFs) , Procedures, Views, Tables, columns, and so on.

The next dialog allows us to specify the SQL Server Instance name. The "Default" instance is "localhost". However, the recommended settings for the Instance are the "Named Instance" option:

How to Install SQL Server 2012 Express      6

This way, if we call the Instance "SQLExpress", this will allow another instances to run on the same machine.
The way to set the Connection String at your AppSettings or web.config file, will be "localhost//SQLExpress".
The next dialog is about the Services that SQL Server needs to run. This allows to set passwords or to change the Startup Type for the two Services. Leave the default settings as they are:

How to Install SQL Server 2012 Express       7

The next dialog is about Authentication. Usually , the authentication mode is the Windows Authentication mode. The recommended settings are, to merge the Windows Authentication  mode to SQL Server Authentication. This is made by specifying a password for the System Administrator , which in SQL Server is called "sa" (System Administrator"). Try to choose a strong password, since this User is very powerful, and can make everything at SQL:

How to Install SQL Server 2012 Express     8


Next step in the SQL Setup is the Error Reporting, in which you can opt for sending to Microsoft error reports from your machine, automatically. Select it if you wish:

How to Install SQL Server 2012 Express     9

Clicking the "Next" button will trigger the installation :

How to Install SQL Server 2012 Express     10

Finally, if everything went fine, you'll be prompted with the info about all features installed on your machine:

How to Install SQL Server 2012 Express   11



That All!!!   In this article we learned Step by Step How to Install and Setup SQL Server 2012 Express
Happy programming.....

      by Carmel Schvartzman


כתב: כרמל שוורצמן





Tuesday, February 3, 2015

How to fix the Visual Studio 2012 Error 'An incompatible DacFx version is installed'

In this article we see How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed'.

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed'



 How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed'


This error is originated in Visual Studio 2012 , when trying to open a database on the
Server Explorer , clicking the "Show table Data" :


How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 1



How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 2


The solution for the problem is installing the SSDT - Sql Server Data Tools for Visual Studio 2012 : the SSDT is a tool to make easy for programmers to edit database objects and data, to execute queries, or to perform database design from within the Visual Studio environment.



How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 3

Browse to the Microsoft Data Developer Center and download the SSDT :

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 4


After the download, run the install file as Administrator:

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 5

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 6

Restart the Visual Studio 2012 and try again to perform some edit to a database:

How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 7


This time you could open the table designers or edit the table's data:


How to fix the Visual Studio 2012 Error   'An incompatible DacFx version is installed' 8

That's all!!!!


By Carmel Shvartzman

עריכה: כרמל שוורצמן