in my service i have the following request:
[Route(@"/api/adddevice", Verbs = "POST")]
public class AddDeviceRequest : IReturn<AddDeviceResponse>
{
public DTOTargetDevice TargetDevice { get; set; }
}
It uses the following DTO:
public class DTOTargetDevice
{
private string _guid = string.Empty;
public string GUID
{
get { return _guid; }
set { _guid = DTOUtils.GetGUID(value); }
}
public string Type { get; set; }
public string DeviceName { get; set; }
public string[] PropertiesName { get; set; }
public string[] PropertiesValue { get; set; }
}
From a C# client, everything works fine, but when i try to call it, TargetDevice is always null. This is the javascript code i'm using:
var parms = {};
parms.targetDevice = {};
parms.targetDevice.guid=guid();
parms.targetDevice.deviceName = guid();
parms.targetDevice.type = sDeviceType;
parms.targetDevice.propertiesName = (propsName);
parms.targetDevice.propertiesValue = (propsValue);
var config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
var promise = $http.post("http://" + sIP + ":20001/api/adddevice", parms, config).then(function (response) {
var result = response.data.result;
console.log("Added Device: " + result);
return result;
});
This is the json, taken from Chrom Developer window:
{"targetDevice":{"guid":"e7461703-1b4b-7cd3-6263-3ac0935fb6f7","deviceName":"11e08b8f-d030-8f69-a469-4a1300aa49bf","type":"HTTPDevice","propertiesName":["Name","Acronym"],"propertiesValue":["Device","Device"]}}:
I've tried several options, but i'm always receiveng a null exception on TargetDevice within the request.
I've already read in other threads that simple objects is preferred, but in other services i have even more complex DTO. Do you have any suggestion about that?
Thanks Leo