Protocol Error

Apr 2, 2013 at 2:54 PM
Edited Apr 2, 2013 at 2:58 PM
My problem goes like this:
  1. If I send correct xml, I get proper response (jir).
  2. If I send incorrect xml (incorrect oib or something),
    I get ProtocolError ("The remote server returned an error: (500) Internal Server Error.")
(because of 1. i eliminated proxy, certificate problems...)

I then tried (for test) with web-service as object:
   Porezna_service.RacunZahtjev racun_zahtjev = deserialize_xml(string_xml);              

   Porezna_service.FiskalizacijaService soapService;
   soapService = new Porezna_service.FiskalizacijaService();
   soapService.Url = "https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest";
   Porezna_service.RacunOdgovor odgovor = soapService.racuni(racun_zahtjev);
here I get back response (odgovor.Greske)....
But the problem is, that deserialization messes up with xml signature
(I allways get: S004: 'Neispravan digitalni potpis.')

I found and read this threads:
http://fiskalizacija.codeplex.com/discussions/404729
http://fiskalizacija.codeplex.com/discussions/401865

Thank you for your help.
Apr 3, 2013 at 8:15 AM
Do you use one of the final components of this project or use net source code for your project?
What do you mean by eliminating proxy certificate issue?
I ask because I long ago had many problems with the same error 500.
Apr 3, 2013 at 8:56 AM
Thank you for your reply.

In the threads listed at the end of my first post, people had problems with proxy and problems with certificate.
Because I get proper response if I post proper xml, I asume I can eliminate those two problems...

I am using net source code.
This part in particular (from CentralniInformacijskiSustav.cs):
            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)
                {
                    using (Stream noviResponseStream = ipakPristigliErrorXmlResponse.GetResponseStream())
                    {
                        StreamReader responseReader = new StreamReader(noviResponseStream);
                        OdgovorGreska = new XmlDocument();
                        OdgovorGreska.Load(responseReader);

                        Trace.TraceError("Greška kod slanja SOAP poruke. Primljen odgovor od CIS-a, detalji greške u CentralniInformacijskiSustav.OdgovorGreska.");
                        throw;
                    }
                }
                else
                {
                    Trace.TraceError(String.Format("Greška kod slanja SOAP poruke. Status greške (prema http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus.aspx): {0}. Poruka greške: {1}", ex.Status, ex.Message));
                    throw;
                }
Apr 3, 2013 at 12:53 PM
It seems that the Error 500 occurs with untreated exceptions, applications expected something that they never received, so we have to do it yourself. I looked at these articles and honestly I do not know all the connotations proxy settings, we did not do that, maybe we missed something.
Mainly, for almost half a year, we regularly get the expected CIS error message, OS message (in case of non availability of CIS) and message Time Out (depends on configuration).
This site and this project was designed by Nino and would give him an advantage in responding because I believe that they will be more competent for that.
Apr 11, 2013 at 7:52 AM
Thank you for reply!

So.. how did you handle exceptions?

It is strange to me that for everyone else the above code is manageing the exceptions ok,
but I dont get CIS error messages.... I don't know how is that possible...
I am compiling with .net 2 framework...
Any idea would be most welcome!
Coordinator
Apr 11, 2013 at 7:55 AM
This is source code from Sample.exe, I believe that this is good starting point.

private void ObradaGreske(string oib)
    {
        //Greška je u datumu i vremenu slanja, "21.10.201210:10:28" umjesto "21.10.2012T10:10:28"
        string xml = @"<?xml version=""1.0"" encoding=""utf-8""?><tns:RacunZahtjev xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" Id=""signXmlId"" xmlns:tns=""http://www.apis-it.hr/fin/2012/types/f73""><tns:Zaglavlje><tns:IdPoruke>cff93023-850b-403c-ac8b-277619e81dc9</tns:IdPoruke><tns:DatumVrijeme>21.10.201210:10:28</tns:DatumVrijeme></tns:Zaglavlje><tns:Racun><tns:Oib>44718633471</tns:Oib><tns:USustPdv>true</tns:USustPdv><tns:DatVrijeme>21.10.2012T10:10:22</tns:DatVrijeme><tns:OznSlijed>P</tns:OznSlijed><tns:BrRac><tns:BrOznRac>1</tns:BrOznRac><tns:OznPosPr>123</tns:OznPosPr><tns:OznNapUr>1</tns:OznNapUr></tns:BrRac><tns:Pdv><tns:Porez><tns:Stopa>25.00</tns:Stopa><tns:Osnovica>10.00</tns:Osnovica><tns:Iznos>2.50</tns:Iznos></tns:Porez></tns:Pdv><tns:IznosUkupno>12.50</tns:IznosUkupno><tns:NacinPlac>G</tns:NacinPlac><tns:OibOper>12345678900</tns:OibOper><tns:ZastKod>e4d909c290d0fb1ca068ffaddf22cbd0</tns:ZastKod><tns:NakDost>false</tns:NakDost></tns:Racun></tns:RacunZahtjev>";

        XmlDocument dokument = new XmlDocument();
        dokument.LoadXml(xml);

        Raverus.FiskalizacijaDEV.CentralniInformacijskiSustav cis = new CentralniInformacijskiSustav();

        X509Certificate2 certifikat = Raverus.FiskalizacijaDEV.PopratneFunkcije.Potpisivanje.DohvatiCertifikat("FISKAL 1");
        PopratneFunkcije.Potpisivanje.PotpisiXmlDokument(dokument, certifikat);

        PopratneFunkcije.XmlDokumenti.DodajSoapEnvelope(ref dokument);

        try
        {
            XmlDocument odgovor = cis.PosaljiSoapPoruku(dokument);
            if (odgovor != null)
            {
                string jir = Raverus.FiskalizacijaDEV.PopratneFunkcije.XmlDokumenti.DohvatiJir(odgovor);
                MessageBox.Show(jir);
            }
        }
        catch (Exception ex)
        {
            if (cis.OdgovorGreska != null)
            {
                MessageBox.Show(cis.OdgovorGreska.InnerXml);
                MessageBox.Show(Raverus.FiskalizacijaDEV.PopratneFunkcije.XmlDokumenti.DohvatiSifruGreske(cis.OdgovorGreska, PopratneFunkcije.TipDokumentaEnum.RacunOdgovor));
                MessageBox.Show(Raverus.FiskalizacijaDEV.PopratneFunkcije.XmlDokumenti.DohvatiPorukuGreske(cis.OdgovorGreska, PopratneFunkcije.TipDokumentaEnum.RacunOdgovor));
                MessageBox.Show(Raverus.FiskalizacijaDEV.PopratneFunkcije.XmlDokumenti.DohvatiGreskuRezultataZahtjeva(cis.OdgovorGreska));

            }
            else
                MessageBox.Show(String.Format("Greška: {0}", ex.Message));
        }

    }
Apr 11, 2013 at 11:49 AM
Just tried again and it's working...

I am guessing: there was something wrong with response from test server...

Thank you for all the help!