Recently, I got tangled with this “The remote server returned an error: (502) Bad gateway” problem when my custom webservice, which is using SP Client object model, failed to access sharepoint list.
To troubleshoot this issue, I tried to login to the sharepoint site from the remote server using the same credentials under which my web service was running. I found that I could login to the sharepoint site. But I was getting prompted to enter my user credentials during login rather than letting me straight into the site. Usually you don’t need to enter your credentials if SP site is based on windows authentication and if you are already logged in to the machine using your windows/domain account. Then, I have been told that all the clients on this environment are connected to a proxy server. I realized that there was no default proxy server defined in the browser. After I configured IE to use default proxy server (by navigating to Tools -> Internet Options etc), I could login to sharepoint site without entering my username and pwd.
Taking it furthur, I thought of setting a default proxy for my web service as well. I explored and found that adding entry shown below to the web.config resolved my problem. Add this as a child element under <Configuration> section.
<proxy usesystemdefault=”false” bypassonlocal=”false” />
Please note that there can be different reasons for this error but for the above-mentioned scenario, this could be the solution.