0

I have a service that has been successfully performing inferences for 2 years, but API stopped working in December. I have created a simple App based on documentation from Microsoft to reproduce the problem. Please see code below.

Is anybody else experience this problem?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction;
using static System.Net.Mime.MediaTypeNames;

namespace TestCustomVision
{
    class Program
    {
        public static void Main()
        {
            string imageFilePath = <My Image>;

            MakePredictionRequest(imageFilePath).Wait();

            Console.WriteLine("\n\nHit ENTER to exit...");
            Console.ReadLine();
        }
        public static async Task MakePredictionRequest(string imageFilePath)
        {
            var client = new HttpClient();

            // Request headers - replace this example key with your valid Prediction-Key.
            client.DefaultRequestHeaders.Add("Prediction-Key", <My key>);

            // Prediction URL - replace this example URL with your valid Prediction URL.
            string url = <Prediction URL>;

            HttpResponseMessage response;

            // Request body. Try this sample with a locally stored image.
            byte[] byteData = GetImageAsByteArray(imageFilePath);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);
                Console.WriteLine(await response.Content.ReadAsStringAsync());
            }
        }


        private static byte[] GetImageAsByteArray(string imageFilePath)
        {
            FileStream fileStream = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read);
            BinaryReader binaryReader = new BinaryReader(fileStream);
            return binaryReader.ReadBytes((int)fileStream.Length);
        }
    }
}
silent
  • 14,494
  • 4
  • 46
  • 86
  • please add the error messages you are getting – silent Feb 04 '20 at 21:21
  • I am getting following exception: "The underlying connection was closed: An unexpected error occurred on a send" – Igor Palant Feb 05 '20 at 18:26
  • if you haven't touch this for 2 years I would not be surprised if there was an update in the custom vision service that requires you to make a change on your client. You should go to the custom visual portal and see if the URL is still the same. – silent Feb 05 '20 at 21:29
  • Why are you implementing httpClient if you are using the nuget package (`using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction;`)? – Nicolas R Feb 07 '20 at 13:01

0 Answers0