Introduction
Download Database SQL Scripts & Data
Download VS2013 Web API Project (minus packages)
Download SoapUI Project (update your windows credentials)
For years I have used SoapUI to test my SOAP oriented services, creating SoapUI projects and integrating them into a TFS build, or simply having a SoapUI project open to quickly test the response (structure or data) from a service call - quick and simple...
Background
During an AngularJS Web API project, I needed to test the Web API methods in isolation, without the calls from the client, to track down a defect. To determine if the issue was in the WEB API or in the request from the client. So it was a simple matter of testing the Rest service method in isolation first. To do this I knew I would use SoapUI, but I hadn't used it with a Rest API project before - thus this tutorial!
Using the attached code
Firstly, download a set of SQL scripts and execute within your SQL Server to create the "Scratch" database objects.
Secondly, I have attached a simple Microsoft WEB API project (Visual Studio 2013), which you can download, compile (change connection string) and deploy to your IIS.
Then download the SoapUI project (Freeware version 5.2.0). I will step through in detail below, on how to create and test your SoapUI project requests.
Compile & Deploy WEB API Project to IIS
Open the solution in Visual Studio 2013, compile and add the missing packages through Nuget. Once you’re missing packages have been included into the project, it's time to publish the API project to your IIS.
Deploy to a site called "WebApi-SoapUI"
All going well your IIS should look something like this;
Now, you can see the Controller that we wish to test against.
Execute SQL Scripts
Unzip the SQL package, and double click the "Scratch Database.sql" file to open in SQL Server. Execute this script to create a Scratch database with two tables and a stored procedure.
Import the data from the two .txt files into the respective tables. Now, we have data that we can black box test against.
Create Soap UI Rest Project
Open Soap UI and click on the new Rest project toolbar button.
This will render a dialog for you to enter in the Rest URL for the particular controller we wish to test against:
http://localhost/SoapUIWebAPI/api/People
We are presented with a SoapUI Rest Project with a default Request - give your request a more meaningful name, like "All People".
Because we have security enabled within the web site (Windows Authentication) - we will have to replicate it in the Rest request also (mimic the client request). We do this by clicking on the Authorize (NTLM) button (bottom of the page).
Enter valid credentials for the web site (NB: make sure your App Pool account also has the correct credentials to access the controller API's).
Create Soap UI Rest Requests
Now we are ready to make a Rest request to our controller. Notice how the request URL is split up into server and controller and the method dropdown is "Get" by default (which is correct in this case). Click on the green arrow to initiate the request and you should see a JSON response.
Json Data Response:
To make a request for a particular record, we simple build the request up like we would in our browser address bar.
Add a new request for the People API like this:
For eg., to retrieve the record with an ID of 5, we simply create a request like this - make sure to set the authorization (for each request)
Create Soap UI Rest Post
To post like a form submit (like a client would), ensure to click the "Post QueryString" checkbox. Add your parameters and ensure that the action method is "Post", before submitting the request.
Validate your post in SQL server, you can also use your Get method to retrieve the newly entered record (NB: ID is not an identity field, you might want to get the next valid ID value from SQL Server).
If you add more action methods to the project, you should have a SoapUI project something like this (always remember to set the authorization settings for each request):
Create Soap UI Rest Put
Create Soap UI Rest Delete