Simon Bourdeau
Simon Bourdeau

Reputation: 449

Azure Cognitive Services Computer Vision fails in QA but works perfectly in dev

I have this code to run Azure Cognitive Service's Computer Vision API in a C# API. I've ran this in Dev for a couple weeks and everything is good at this point. However I moved this to our QA environment and all of a sudden I get:

InnerException {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."} System.Exception {System.IO.IOException}

This tells me the service is alive but unavailable. imageURL is a fully formed public URL (an image).

            string imageURL = _storageAccount.BlobStorageUri.PrimaryUri.AbsoluteUri + container + "/" + fullFileName;

            // Create a client
            ComputerVisionClient client = Authenticate(cvEndpoint, cvSubscriptionKey);

            // Creating a list that defines the features to be extracted from the image. 
            List<VisualFeatureTypes?> features = new List<VisualFeatureTypes?>()
            {
                VisualFeatureTypes.Categories, VisualFeatureTypes.Description,
                VisualFeatureTypes.Faces, VisualFeatureTypes.ImageType,
                VisualFeatureTypes.Tags, VisualFeatureTypes.Adult,
                VisualFeatureTypes.Color, VisualFeatureTypes.Brands,
                VisualFeatureTypes.Objects
            };

            // Analyze an image to get features and other properties.
            ImageAnalysis results = await client.AnalyzeImageAsync(imageURL, features); //fails here

This is pretty vanilla code directly from Microsoft's documentation. Anyone knows what could be happening here?

Upvotes: 1

Views: 438

Answers (1)

Simon Bourdeau
Simon Bourdeau

Reputation: 449

I fixed this issue by adding TLS 1.1 and 1.2 in my API. Not sure why 1.0 is by default but it is and the cognitive service API needs 1.2 minimum.

The fix is to add this line:

System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

Found the solution here: C# HttpClient An existing connection was forcibly closed by the remote host

Upvotes: 2

Related Questions