receiving 401 Unauthorized on webservice calls that used to work.

  • 1
  • Problem
  • Updated 2 years ago
  • Solved
  • (Edited)
Built a c# application to automate the invocation of specific reports and download the results to CSV files for integration to a data warehouse.
As of April 1st, everything was working fine.
As of April 12th (I haven;t touched it in between)  we can no longer access the services, we get 401 Unauthorized back from the server.  

I validated in Replicon that my user still has the administrator role.

Here is how we have built and called  the request.

  var url = "https://na6.replicon.com/XXX/services/ReportService1.svc/GenerateReport";            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.Accept = "application/json";
            request.ContentType="application/json;charset=utf-8";
            String username = "XXX\\"+user;
            String password = passwd;
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("UTF-8").GetBytes(username + ":" + password));
            request.Headers.Add("Authorization", "Basic "+encoded);
requestObject.reportUri = "urn:replicon-tenant:xxx-gen3:report:f1e9258e-e60c-4f47-44f9-1085ed4f0ea7";
            requestObject.filterValues = filterValues;
            requestObject.outputFormatUri = "urn:replicon:report-output-format-option:csv";

[...]
       //Serialize and submit request
            var requestBody = JsonConvert.SerializeObject(requestObject);
            request.ContentLength = requestBody.Length;
            var streamWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
            streamWriter.Write(requestBody);
            streamWriter.Close();
            //get the Response
            var response = request.GetResponse();    
              
            var streamReader = new System.IO.StreamReader(response.GetResponseStream());
            var responseContent = streamReader.ReadToEnd().Trim();  
Is Basic Auth not allowed anymore?

Here is the response 
Unhandled Exception: System.Net.WebException: The remote server returned an error: (401) Unauthorized
   at System.Net.HttpWebRequest.GetResponse()
Photo of Paul Saker

Paul Saker

  • 4 Posts
  • 1 Reply Like

Posted 2 years ago

  • 1
Photo of Aashnee Kamboj

Aashnee Kamboj, Community Moderator

  • 1446 Posts
  • 103 Reply Likes
Hi Paul,

Thank you for using Replicon Community!

I will have to check this internally. There should not be a basic auth issue. I will confirm and get back to you

Thanks,
Aashnee
Photo of Paul Saker

Paul Saker

  • 4 Posts
  • 1 Reply Like
Ah, my bad.
I was not doing a lookup to capture the URL our companies service was currently deployed on.
For instance, some days we are na2, some days we are na8, na6 etc.
I will put some code in to call for the URL before building it for the rest of the process using 

https://global.replicon.com/DiscoveryService1.svc/GetUserIntegrationDetails

Thanks for looking into it anyway.