I've the following ASP.NET WebAPI binding:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new {id = RouteParameter.Optional}
);
And my Controller looks like this:
public class ReferenceDataController : BaseController
{
[RequireUserToken(ApprovedDeviceToken = true, ValidUserToken = true)]
[HttpPost]
public IEnumerable<SynchronizeItem<IReferenceDataItem>> Sync([FromBody]IEnumerable<SynchronizeItem<IReferenceDataItem>> clientSyncItems, [FromUri]int referenceDataType)
{
// my code
}
On the client site I use the following code to send a request:
var client = new RestClient (baseUrl);
var request = new RestRequest (resource, method);
request.XmlSerializer = new JsonSerializer ();
request.RequestFormat = DataFormat.Json;
request.AddHeader ("X-Abc-DeviceToken", deviceToken);
if (!string.IsNullOrWhiteSpace (userToken))
request.AddHeader ("X-Abc-UserToken", userToken);
if (payload != null)
request.AddBody (payload);
if (parameters != null)
{
foreach (var parameter in parameters)
{
request.AddUrlSegment(parameter.Key, parameter.Value);
}
}
var response = client.Execute<T> (request);
My expectation is, sending a POST request to http://myhost/api/referencedata/sync?referencedatatype=countries
with a body which contains an IEnumerable. If I remove the UrlSegment parameters on client site and the second argument on the webservice site, than it works.
How can I combine a body with payload and additional URL parameters?