The remote server returned an error: (502) Bad Gateway.

Nov 26, 2012 at 9:25 AM

Hello everyone. 

On "using (Stream requestStream = request.GetRequestStream())" in CentralniInformacijskiSustav.cs, i have an error 502 bad gateway. 

Does anyone have un idea? Thank's a lot!

Coordinator
Nov 26, 2012 at 9:36 AM

Did you tried to look up on the Internet? Is seems to me that this can be related to web services communication per se...

Nov 26, 2012 at 1:08 PM

Ok thank's. After much internet research, i found how to solve the error 502. In my compagny, we use a proxy server to access the internet.

So after the request method POST, we must add the line : "request.Proxy = null". And finally it work. But now, i have another problem, the write request stream is ok but after at the HttpWebResponse, i have this error message : "The remote server returned an error: (500) Internal Server Error."

 

                HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
                if (request != null)
                {
                    //ServicePointManager.Expect100Continue = true; //http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.NET.SERVICEPOINTMANAGER.EXPECT100CONTINUE)&rd=true

                    if (TimeOut > 0)
                        request.Timeout = TimeOut;

                    request.ContentType = "text/xml";
                    request.Method = "POST";

                    request.Proxy = null;


                    //request.Headers = new WebHeaderCollection();
                    //request.Headers.Add("SOAPAction", webMethod);


                    byte[] by = UTF8Encoding.UTF8.GetBytes(soapMessage.InnerXml);
                    request.ProtocolVersion = HttpVersion.Version11;
                    request.ContentLength = by.Length;


                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(by, 0, by.Length);
                    }

                    HttpWebResponse response = request.GetResponse() as HttpWebResponse; //error 500 at this step 
                    if (response != null)
                    {

Coordinator
Nov 26, 2012 at 1:12 PM

Thank you for this Proxy tip :)

Internal server error 500 is quite common error in this "fiskalizacija" project :)

Please check out OdgovorGreska and OdgovorGreskaStatus for more details on actual error returned from the CIS.

Nov 26, 2012 at 5:12 PM
Edited Nov 27, 2012 at 8:26 AM

Yep. Ok, so, OdgovorGreskaStatus is "Protocol Error". I don't know where this error is coming.