Protocol Error

Nov 27, 2012 at 1:26 PM

I don't understand why i get this error. Can someone help me please? All goes well until "HttpWebResponse response". It catch an error 500 internal server error. If i look the OdgovorGreskaStatus, i get an error "ProtocolError". I'm lost.

Thank you for you'r help.

                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;
                    if (response != null)
                    {
                        Stream responseStream = response.GetResponseStream();
                        Encoding encode = Encoding.GetEncoding("utf-8");
                        StreamReader readStream = new StreamReader(responseStream, encode);
                        string txt = readStream.ReadToEnd();

                        responseSoapMessage = new XmlDocument();
                        responseSoapMessage.PreserveWhitespace = true;
                        responseSoapMessage.LoadXml(txt);

                        SnimanjeDatoteka(NazivMapeOdgovor, responseSoapMessage);

                        if (SoapMessageSent != null)
                        {
                            EventArgs ea = new EventArgs();
                            SoapMessageSent(this, ea);
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                // prema sugestiji mladenbabic (http://fiskalizacija.codeplex.com/workitem/627)
                // prema sugestiji dkustec (http://fiskalizacija.codeplex.com/workitem/637)

                OdgovorGreskaStatus = ex.Status;
                
                WebResponse ipakPristigliErrorXmlResponse = ((WebException)ex).Response;
                if (ipakPristigliErrorXmlResponse != null)

Coordinator
Nov 27, 2012 at 1:27 PM

Did you check inner exception message?

Nov 27, 2012 at 2:12 PM

Yes but the inner exception message is null.

Coordinator
Nov 27, 2012 at 2:16 PM

OK, so, put an breakpoint on

"catch (WebException ex)" and watch declared "ex". Is any inner exception is in that object?

Nov 27, 2012 at 2:51 PM

Ok, here is a screenshot, i think it's easier :

 

Hébergeur d'image

Coordinator
Nov 27, 2012 at 2:55 PM

pls, expand row where is "ex" object.

This may be problem in certificate. You have both? - ROOT (DEMO) and FISKAL 1 ?

Nov 27, 2012 at 3:42 PM

Ho, sorry dkuster, it's the first time i work on .NET :(

Here the screenshot with the "ex" object : 

Hébergeur d'image

I installed the Verifikacijski/root (samopotpisani) certifikat in trusted root certification authorities and after the fiskal 1.

Coordinator
Nov 27, 2012 at 3:49 PM
Edited Nov 27, 2012 at 3:55 PM

OK, now it's clear enough...

So, what's location of fiskal 1 certificate?

What is application type is? aps.net or destkop app?

You have proxy.. so, did you try to define an URI object an assign it as request.Proxy = yourUriObject?

 

// Create a new request to the mentioned URL.				
			WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");

			WebProxy myProxy=new WebProxy();
			// Obtain the Proxy Prperty of the  Default browser.  
			myProxy=(WebProxy)myWebRequest.Proxy;

			// Print myProxy address to the console.
			Console.WriteLine("\nThe actual default Proxy settings are {0}",myProxy.Address);
         try
			{
				Console.WriteLine("\nPlease enter the new Proxy Address to be set ");
				Console.WriteLine("The format of the address should be http://proxyUriAddress:portaddress");
				Console.WriteLine("Example:http://proxyadress.com:8080");
				string proxyAddress;
				proxyAddress =Console.ReadLine();

				if(proxyAddress.Length==0)
				{
					myWebRequest.Proxy=myProxy;
				}
				else
				{
					Console.WriteLine("\nPlease enter the Credentials");
					Console.WriteLine("Username:");
					string username;
					username =Console.ReadLine();
					Console.WriteLine("\nPassword:");
					string password;
					password =Console.ReadLine();

					// Create a new Uri object.
					Uri newUri=new Uri(proxyAddress);

					// Associate the new Uri object to the myProxy object.
					myProxy.Address=newUri;

					// Create a NetworkCredential object and is assign to the Credentials property of the Proxy object.
					myProxy.Credentials=new NetworkCredential(username,password);
					myWebRequest.Proxy=myProxy;
				}
				Console.WriteLine("\nThe Address of the  new Proxy settings are {0}",myProxy.Address);
				WebResponse myWebResponse=myWebRequest.GetResponse();

				// Print the  HTML contents of the page to the console.
				Stream streamResponse=myWebResponse.GetResponseStream();
				StreamReader streamRead = new StreamReader( streamResponse );
				Char[] readBuff = new Char[256];
				int count = streamRead.Read( readBuff, 0, 256 );
				Console.WriteLine("\nThe contents of the Html pages are :");	
				while (count > 0) 
				{
					String outputData = new String(readBuff, 0, count);
					Console.Write(outputData);
					count = streamRead.Read(readBuff, 0, 256);
				}

				// Close the Stream object.
				streamResponse.Close();
				streamRead.Close();

				// Release the HttpWebResponse Resource.
				myWebResponse.Close();
				Console.WriteLine("\nPress any key to continue.........");
				Console.Read();				
			}
			catch(UriFormatException e)
			{
				Console.WriteLine("\nUriFormatException is thrown.Message is {0}",e.Message);
				Console.WriteLine("\nThe format of the myProxy address you entered is invalid");
				Console.WriteLine("\nPress any key to continue.........");
				Console.Read();
			}

 

http://msdn.microsoft.com/en-us/library/system.net.webrequest.proxy.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

Nov 28, 2012 at 10:22 AM

Hi! Thank you for you'r help! Fiskal 1 certificate is on c:\ and it's a desktop app. I think i found a part of problem. The problem is actually the proxy server. Normally, an https connexion is made on 443 port. In this case, cis service needs to use the 8449 and we have a security problem with our firewall. I'm trying to see with our network administrator to find a solution.

Nov 30, 2012 at 8:27 AM

Hi everyone. We have identified the problem of error 500 internal server error (exeption status: Protocol error). In our case, the problem does not come from the fact of using a proxy or a certificate problem. In fact, there was a mistake for the OIB number. This is stupid, CIS server does not seem capable of returning an error message in this case and return an http error.

For those who use a proxy server and have a 502 error bad gateway, you must using request.Proxy = null.