1
votes

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?

1
looks like a network issue"? any possibility that few ips are blocked ? also have you verified the endpoint,subscription,region config ?Satya V
Right now I've set my Azure Cognitive Service Network setup to accept requests from all networks as documented here: docs.microsoft.com/en-us/azure/cognitive-services/…. Aside from using the right key and endpoint I don't think many other settings mather. I've looked at monitoring and my QA requests (the ones that fail) are not visible in monitoring.Simon Bourdeau

1 Answers

1
votes

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