Ejemplo n.º 1
0
		public static async Task SendEventHubEventAsync(TemperatureData temperatureData)
		{
			HttpClient client = new HttpClient();

			client.DefaultRequestHeaders.Clear();

			var authHeader = new System.Net.Http.Headers.AuthenticationHeaderValue(
				"SharedAccessSignature", SAS);
			client.DefaultRequestHeaders.Authorization = authHeader;

			DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TemperatureData));
			string body = string.Empty;
			using (MemoryStream ms = new MemoryStream())
			using (StreamReader sr = new StreamReader(ms))
			{
				serializer.WriteObject(ms, temperatureData);
				ms.Seek(0, SeekOrigin.Begin);
				body = sr.ReadToEnd();
			}
			StringContent content = new StringContent(body, Encoding.UTF8);
			client.BaseAddress = new Uri(BaseUri);

			//await client.PostAsync(ServiceUri, content);

			client.Dispose();
		}
Ejemplo n.º 2
0
        public static async Task SendEventHubEventAsync(TemperatureData temperatureData)
        {
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Clear();

            var authHeader = new System.Net.Http.Headers.AuthenticationHeaderValue(
                "SharedAccessSignature", SAS);

            client.DefaultRequestHeaders.Authorization = authHeader;

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TemperatureData));
            string body = string.Empty;

            using (MemoryStream ms = new MemoryStream())
                using (StreamReader sr = new StreamReader(ms))
                {
                    serializer.WriteObject(ms, temperatureData);
                    ms.Seek(0, SeekOrigin.Begin);
                    body = sr.ReadToEnd();
                }
            StringContent content = new StringContent(body, Encoding.UTF8);

            client.BaseAddress = new Uri(BaseUri);

            //await client.PostAsync(ServiceUri, content);

            client.Dispose();
        }