Forum Discussion

AndrewBauer's avatar
6 years ago

Unable to connect to Online via CompanyFileService

My application that has been running for over a year has all of a sudden stopped working. When I debug it, it seems that the CompanyFileService either isn't creating a WebRequestFactory correctly, isn't able to connect via it or is prematurely closing the connection. Below is a screenshot of the error I am receiving:

 

 

The code I am using is from an example I found in MYOB community:

try
{
    ShowSpinner();

    if (UseCloud)
    {
        _configuration = new ApiConfiguration(DeveloperKey, DeveloperSecret, "http://desktop");
        _oAuthKeyService = new OAuthKeyService();

        //Get tokens if not stored
        if (_oAuthKeyService.OAuthResponse == null)
        {
            var oauthService = new OAuthService(_configuration);
            _oAuthKeyService.OAuthResponse =
                oauthService.GetTokens(OAuthLogin.GetAuthorizationCode(_configuration));
        }

        // Load all files from cloud and local simultaneously
        var cfsCloud = new CompanyFileService(_configuration, null, _oAuthKeyService);
        cfsCloud.GetRange(OnComplete, OnError);
    }
    else
    {
        _configuration = new ApiConfiguration(LocalApiUrl);
        var cfsLocal = new CompanyFileService(_configuration);
        cfsLocal.GetRange(OnComplete, OnError);
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

The error occurs on:

cfsCloud.GetRange(OnComplete, OnError);