For this tutorial we'll send an HTTP POST request to a REST Service (written in C#).
The signature of the method that we'll be invoking is shown below.
[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
this.myCollection.Add(instance);
return instance;
}
The function "Create" takes an instance of the class SampleItem via a POST at the URL http://localhost:1753/Service1. It can be sent as JSON or XML. If succesful, it simply echoes back the SampleItem instance. Below is the definition of the SampleItem class
public class SampleItem
{
public int Id { get; set; }
public string StringValue { get; set; }
}
To send a JSON POST request, please follow the steps below
- Run WcfStorm.Rest.exe
- In URL, type http://localhost:1753/Service1/
- Select the method "POST"
- In the request headers, add Content-Type: application/json. This step is necessary because we want to tell the REST Service that data we're sending is in the JSON format.
- In the Request Parameters panel, paste-in a JSON instance of the SampleItem Class.
- Click Send.
To send an XML POST Request:
- To send a POST request in XML format, change the Content-Type in the header to, "application/xml" or "text/xml"
- In the request body, paste in an instance of the SampleItem class in XML format.