none
502 - Web server received an invalid response while acting as a gateway or proxy server

    Question

  • I have recently re-deployed my website from Amazon AWS to Azure.

    All seems to be fine except any OAuth 2 authentication with Google API's.

    I have tried a number of different APIs and each generates the following error

    502 - Web server received an invalid response while acting as a gateway or proxy server.

    There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.

    Here is a code snippet - a standard OAuth 2 authentication with a Google API.  This works on all other platforms - local, Amazon etc etc - just not my Azure website???

    X509Certificate2 certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certs//" + certificateFile, certificatePassword, X509KeyStorageFlags.Exportable);

                ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
                {
                    Scopes = new[] { Google.Apis.Calendar.v3.CalendarService.Scope.Calendar },
                    User = user
                }.FromCertificate(certificate));

                Google.Apis.Calendar.v3.CalendarService service = new Google.Apis.Calendar.v3.CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "iLink i3cloud.com",
                });

                try
                {
                    Google.Apis.Calendar.v3.Data.Event evv = service.Events.Get(user, "6ebr4dp452m453n468movuntag").Execute();
                    EventsResource.UpdateRequest ur = new EventsResource.UpdateRequest(service, evv, user, evv.Id);
                    ur.Execute();
                }

    Thanks for you help,

    Paul C


    • Edited by Pauli3k Sunday, June 01, 2014 10:33 PM typo
    Sunday, June 01, 2014 10:32 PM

Answers

  • Hi Jambor,

    There was nothing in the logs?  With trial and error I found out it was an issue with certificates in Azure.

    What it turned out to be is documented here:

    http://blog.tylerdoerksen.com/2013/08/23/pfx-certificate-files-and-windows-azure-websites/

    The issue is to do with the with the way that Azure deals with certificates.  I had to change

    X509Certificate2 certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certs//" + certificateFile, certificatePassword, X509KeyStorageFlags.Exportable);

    To be

    X509Certificate2 certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certs//" + certificateFile, certificatePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

    Monday, June 02, 2014 12:14 PM

All replies

  • Hi,

    There can be varies causes for this error, the detail error message is important to fix this issue, I suggest you have a look at below video to troubleshoot your site, and give detail information here.

    #http://channel9.msdn.com/Series/DIY-Windows-Azure-Troubleshooting/WAWSDiagPart1

    Best Regards,

    Jambor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 02, 2014 9:12 AM
    Moderator
  • Hi Jambor,

    There was nothing in the logs?  With trial and error I found out it was an issue with certificates in Azure.

    What it turned out to be is documented here:

    http://blog.tylerdoerksen.com/2013/08/23/pfx-certificate-files-and-windows-azure-websites/

    The issue is to do with the with the way that Azure deals with certificates.  I had to change

    X509Certificate2 certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certs//" + certificateFile, certificatePassword, X509KeyStorageFlags.Exportable);

    To be

    X509Certificate2 certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certs//" + certificateFile, certificatePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

    Monday, June 02, 2014 12:14 PM
  • Hi Pauli3k,

    It seems that you have fixed your issue, I will mark your post as answer, thanks for sharing.

    Regards,

    Jambor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 03, 2014 1:47 AM
    Moderator