Search code examples
dotnet-httpclientrackspace-cloudrackspacerackspace-cloudfiles

'identity.api.rackspacecloud.com' randomly throws 'The remote name could not be resolved' exception


I am accessing Rackspace Cloud APIs.

I have one api call which authenticates me on the rackspace cloud.

The method works perfectly, however, from time to time, i get this exception, randomly :

The remote name could not be resolved: 'identity.api.rackspacecloud.com'

When i am not getting this exception, the method returns the expected result, as it should be.

Is there any specific reason why it does this?

Here is my .net code:

private async Task<XDocument> AuthenticateAsync()
{
    XNamespace ns = "http://docs.rackspace.com/identity/api/ext/RAX-KSKEY/v1.0";

    XDocument doc =
        new XDocument(
            new XDeclaration("1.0", "UTF-8", "Yes"),
            new XElement("auth",
                new XElement(ns + "apiKeyCredentials",
                    new XAttribute("username", "the userName"),
                    new XAttribute("apiKey", "the apiKey")
                )
            )
        );

    using (HttpClient client = new HttpClient())
    {
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

        StringContent content = new StringContent(doc.ToString(), Encoding.UTF8, "application/xml");

        // i randomly get "The remote name could not be resolved" exception
        HttpResponseMessage response = await client.PostAsync("https://identity.api.rackspacecloud.com/v2.0/tokens", content);
        response.EnsureSuccessStatusCode();

        string stringResponse = await response.Content.ReadAsStringAsync();
        return XDocument.Parse(stringResponse);
    }
}

Solution

  • This certainly sounds like a DNS failure. Can you configure your machine to use the Google DNS servers and try again?