I am sending event to IoT hub using azure sdk and rest client.
I have to use IoT hub routing features so I am adding addition property to main payload before sending to IotHub
Case 1: Sending Data using Azure SDK
Event Model
RealTimeMachineData realTimeData = new RealTimeMachineData();
realTimeData.Date = DateTime.UtcNow;
realTimeData.MachineCode = "M1";
SDK code to send data to IoT Hub
When I see this message in Service bus explorer i look like this
{
"MachineCode": "M1",
"Date": "2017-08-27T10:05:22.7063498Z",
}
Case 2: When I do the same thing by calling through Rest API
HttpClient client = new HttpClient();
string deviceId = "DemoDevice";
string baseUrl = "https://******.azure-devices.net/devices/" + deviceId + "/messages/events?api-version=2016-02-03";
client.BaseAddress = new Uri(baseUrl);
var sas = @"SharedAccessSignature sr=********";
client.DefaultRequestHeaders.Add("Authorization", sas);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var message1 = new Microsoft.Azure.Devices.Client.Message(Encoding.ASCII.GetBytes(realTimeData.ToString()));
message1.Properties.Add("Source", "AiR");
HttpResponseMessage response = client.PostAsJsonAsync(baseUrl, message1).Result;
After sending event this way when i check the message to service bus explorer it look like
I have to use this approach in stream analytics and since the payload is getting different when sending through rest client so facing lot of problems.
Am I doing something wrong or is there something different I have to do while sending via Rest client?