none
Erreur 504 (Fiddler) - Connection reset by peer - Objet non retourné par un service WCF RRS feed

  • Question

  • Bonsoir.

    Depuis maintenant quelques jours, je rencontre un soucis sur une méthode qui ne me renvoi plus de résultats mais simplement une erreur 504 (erreur vue via Fiddler) ou une SockectException - Connection reset by peer (vue depuis le LogCat Android) lorsque je souhaite l'utiliser.

    Cette méthode fonctionnait correctement avant l'ajout d'une nouvelle propriété pour l'objet concerné, mais ne fonctionne plus maintenant (même si je reviens à la version précédente du code).

    Voici à quoi ressemble l'objet Appointment concerné :

    [DataContract (Name="Appointment")]
        public class Appointment
        {
            private int _id;
            private Customer _customer;
            private int _typeId;
            private List<Delivery> _delivery;
            private DateTime _dateBegin;
            private DateTime _dateEnd;
            private DateTime _dateCreate;
            private int _userCreate;
            private string _comment;
            private int _order;
            private Boolean _callCustomer;
            private Boolean _urgent;
            private Boolean _onsite;
            private string _attachement;
            private List<Intervention> _intervention;
            private List<User> _users;
            
            [DataMember(Name = "Id", Order = 1)]
            public int Id 
            { 
                get { return _id; }
                set { _id = value; }
            }
            [DataMember(Name = "Customer", Order = 2)]
            public Customer Customer
            {
                get { return _customer; }
                set { _customer = value; }
            }
            [DataMember(Name = "TypeId", Order = 3)]
            public int TypeId
            {
                get { return _typeId; }
                set { _typeId = value; }
            }
            [DataMember(Name = "Delivery", Order = 4)]
            public List<Delivery> Delivery
            {
                get { return _delivery; }
                set { _delivery = value; }
            }
            [DataMember(Name = "DateBegin", Order = 5)]
            public DateTime DateBegin
            {
                get { return _dateBegin; }
                set { _dateBegin = value; }
            }
            [DataMember(Name = "DateEnd", Order = 6)]
            public DateTime DateEnd
            {
                get { return _dateEnd; }
                set { _dateEnd = value; }
            }
            [DataMember(Name = "DateCreate", Order = 7)]
            public DateTime DateCreate 
            {
                get { return _dateCreate; }
                set { _dateCreate = value; }
            }
            [DataMember(Name = "UserCreate", Order = 8)]
            public int UserCreate 
            {
                get { return _userCreate; }
                set { _userCreate = value; }
            }
            [DataMember(Name = "Comment", Order = 9)]
            public string Comment
            {
                get { return _comment; }
                set { _comment = value; }
            }
            [DataMember(Name = "Order", Order = 10)]
            public int Order
            {
                get { return _order; }
                set { _order = value; }
            }
            [DataMember(Name = "CallCustomer", Order = 11)]
            public Boolean CallCustomer
            {
                get { return _callCustomer; }
                set { _callCustomer = value; }
            }
            [DataMember(Name = "Urgent", Order = 12)]
            public Boolean Urgent
            {
                get { return _urgent; }
                set { _urgent = value; }
            }
            [DataMember(Name = "Onsite", Order = 13)]
            public Boolean Onsite 
            {
                get { return _onsite; }
                set { _onsite = value; }
            }
            [DataMember(Name = "Attachment", Order = 14)]
            public string Attachment
            {
                get { return _attachement; } 
                set { _attachement = value; }
            }
            [DataMember(Name = "Intervention", Order = 15)]
            public List<Intervention> Intervention 
            {
                get { return _intervention; }
                set { _intervention = value; }
            }
            [DataMember(Name = "User", Order = 16)]
            public List<User> User
            {
                get { return _users; }
                set { _users = value; }
            }
            public Appointment()
            {
            }
            public Appointment(int id, Customer customerId, int typeId, List<Delivery> deliveryId,
                                DateTime dateBegin, DateTime dateEnd, DateTime dateCreate,
                                int userCreate, string comment, int order,
                                Boolean callCustomer, Boolean urgent, string attachment,
                                List<Intervention> intervention, List<User> user, Boolean onsite)
            {
                _id = id;
                _customer = customerId;
                _typeId = typeId;
                _delivery = deliveryId;
                _dateBegin = dateBegin;
                _dateEnd = dateEnd;
                _dateCreate = dateCreate;
                _userCreate = userCreate;
                _comment = comment;
                _order = order;
                _callCustomer = callCustomer;
                _urgent = urgent;
                _attachement = attachment;
                _intervention = intervention;
                _users = user;
                _onsite = onsite;
            }
        }

    La propriété qui a été ajoutée est "_onsite" et un booléen tout bête, comme je peux en avoir d'autres dans cet objet.

    Et la méthode qui prend en paramètre un Appointment (récupéré d'un Stream) et se charge d'insérer un Appointment en bdd, et le retourner au format JSON.

    public static Appointment InsertAppointment(Appointment deserializedAppointment)
            {
                Appointment AppToSend = null;
                int LastIdAppointment = 0;
                int IdCustomer = 0;
                string ConnectionString = ConfigurationManager.ConnectionStrings["StopTelecomBdd"].ConnectionString;             string Query = "SELECT CUSTOMER.CUS_ID FROM CUSTOMER WHERE CUSTOMER.CUS_CODE = '" + deserializedAppointment.Customer.Code + "'";
                SqlConnection ConnectionBddInsert = new SqlConnection(ConnectionString);
                ConnectionBddInsert.Open();
                SqlCommand mySqlCommand = new SqlCommand(Query, ConnectionBddInsert);
                SqlDataReader customerReader = mySqlCommand.ExecuteReader();
                if (customerReader.HasRows)
                {
                    customerReader.Read();
                    IdCustomer = Convert.ToInt32(customerReader.GetValue(customerReader.GetOrdinal("CUS_ID")));
                }
                else
                {
                    Query = "INSERT INTO CUSTOMER (CUS_NAME, CUS_CODE, CUS_ZIPCODE) "
                            + "VALUES ('" + deserializedAppointment.Customer.Name + "', '" + deserializedAppointment.Customer.Code + "', '" + deserializedAppointment.Customer.ZipCode + "')";
                    SqlConnection ConnectionBddInsertCustomer = new SqlConnection(ConnectionString);
                    ConnectionBddInsertCustomer.Open();
                    mySqlCommand = new SqlCommand(Query, ConnectionBddInsertCustomer);
                    mySqlCommand.ExecuteNonQuery();
                    Query = "SELECT @@IDENTITY as LastCustomer "
                            + "FROM CUSTOMER";
                    mySqlCommand = new SqlCommand(Query, ConnectionBddInsertCustomer);
                    SqlDataReader lastCustomer = mySqlCommand.ExecuteReader();
                    if (lastCustomer.HasRows)
                    {
                        lastCustomer.Read();
                        IdCustomer = Convert.ToInt32(lastCustomer.GetValue(lastCustomer.GetOrdinal("LastCustomer")));
                        deserializedAppointment.Customer.Id = IdCustomer;
                    }
                    lastCustomer.Close();
                    lastCustomer.Dispose();
                    if (ConnectionBddInsertCustomer.State != ConnectionState.Closed)
                    {
                        ConnectionBddInsertCustomer.Close();
                        ConnectionBddInsertCustomer.Dispose();
                    }
                }
                customerReader.Close();
                customerReader.Dispose();
                long callCustomer = 0;
                if (deserializedAppointment.CallCustomer == true)
                {
                    callCustomer = 1;
                }
                long urgent = 0;
                if (deserializedAppointment.Urgent == true)
                {
                    urgent = 1;
                }
                long onsite = 0;
                if (deserializedAppointment.Onsite == true)
                {
                    onsite = 1;
                }
                
                //Check if Appointment is in database.
                Query = "SELECT APPOINTMENT.APP_ID "
                        + "FROM APPOINTMENT INNER JOIN TEC_APP ON TEC_APP.APP_ID = APPOINTMENT.APP_ID "
                        + "WHERE TEC_APP.TEC_ID = " + deserializedAppointment.User[0].uid
                        + " AND APPOINTMENT.CUS_ID = " + IdCustomer
                        + " AND APPOINTMENT.APP_DATEBEGIN = '" + deserializedAppointment.DateBegin + "'"
                        + " AND APPOINTMENT.APP_DATEEND = '" + deserializedAppointment.DateEnd + "'";
                SqlConnection ConnectionBddSelectAppointment = new SqlConnection(ConnectionString);
                ConnectionBddSelectAppointment.Open();
                SqlCommand mySqlCommandAppointment = new SqlCommand(Query, ConnectionBddSelectAppointment);
                SqlDataReader appointmentReader = mySqlCommandAppointment.ExecuteReader();
                if (appointmentReader.HasRows)
                {
                    appointmentReader.Read();
                    AppToSend = new Appointment(appointmentReader.GetInt32(appointmentReader.GetOrdinal("APP_ID")), deserializedAppointment.Customer, deserializedAppointment.TypeId,
                                        deserializedAppointment.Delivery, deserializedAppointment.DateBegin, deserializedAppointment.DateEnd, deserializedAppointment.DateCreate,
                                        deserializedAppointment.UserCreate, deserializedAppointment.Comment, deserializedAppointment.Order, deserializedAppointment.CallCustomer,
                                        deserializedAppointment.Urgent, deserializedAppointment.Attachment, deserializedAppointment.Intervention, deserializedAppointment.User, deserializedAppointment.Onsite);
                }
                else
                {
                    deserializedAppointment.DateCreate = DateTime.Now;
                    // If it is not in database, we create it
                    Query = "INSERT INTO APPOINTMENT (CUS_ID, TYP_ID, APP_DATEBEGIN, APP_DATEEND, "
                                + "APP_DATECREATE, APP_USERCREATE, "
                                + "APP_COMMENT, APP_ORDER, APP_CALLCUSTOMER, APP_URGENT, APP_ATTACHMENT, APP_URGENTSEND, APP_ONSITE) "
                                + "VALUES (" + IdCustomer + ", " + deserializedAppointment.TypeId + ", '" + deserializedAppointment.DateBegin + "', '" + deserializedAppointment.DateEnd + "', '"
                                + deserializedAppointment.DateCreate + "', " + deserializedAppointment.User[0].uid + ", '"
                                + replaceCodeToChar(deserializedAppointment.Comment) + "', " + deserializedAppointment.Order + ", " + callCustomer + ", " + urgent + ", '" + deserializedAppointment.Attachment + "', 0, " + onsite + ")";
                    mySqlCommand = new SqlCommand(Query, ConnectionBddInsert);
                    mySqlCommand.ExecuteNonQuery();
                    Query = "SELECT @@IDENTITY as LastAppointment "
                                + "FROM APPOINTMENT";
                    mySqlCommand = new SqlCommand(Query, ConnectionBddInsert);
                    SqlDataReader lastAppointment = mySqlCommand.ExecuteReader();
                    if (lastAppointment.HasRows)
                    {
                        lastAppointment.Read();
                        LastIdAppointment = Convert.ToInt32(lastAppointment.GetValue(lastAppointment.GetOrdinal("LastAppointment")));
                        deserializedAppointment.Id = LastIdAppointment;
                    }
                    lastAppointment.Close();
                    lastAppointment.Dispose();
                    Query = "INSERT INTO TEC_APP (TEC_ID, APP_ID) "
                                + "VALUES (" + deserializedAppointment.User[0].uid + ", " + LastIdAppointment + ")";
                    mySqlCommand = new SqlCommand(Query, ConnectionBddInsert);
                    mySqlCommand.ExecuteNonQuery();
                    for (int i = 0; i < deserializedAppointment.Intervention.Count; i++)
                    {
                        Query = "INSERT INTO INT_APP (INT_ID, APP_ID) "
                                + "VALUES (" + deserializedAppointment.Intervention[i].Id + ", " + LastIdAppointment + ")";
                        mySqlCommand = new SqlCommand(Query, ConnectionBddInsert);
                        mySqlCommand.ExecuteNonQuery();
                    }
                    if (ConnectionBddInsert.State != ConnectionState.Closed)
                    {
                        ConnectionBddInsert.Close();
                        ConnectionBddInsert.Dispose();
                    }
                    AppToSend = new Appointment(deserializedAppointment.Id, deserializedAppointment.Customer, deserializedAppointment.TypeId,
                                        deserializedAppointment.Delivery, deserializedAppointment.DateBegin, deserializedAppointment.DateEnd, deserializedAppointment.DateCreate,
                                        deserializedAppointment.UserCreate, deserializedAppointment.Comment, deserializedAppointment.Order, deserializedAppointment.CallCustomer,
                                        deserializedAppointment.Urgent, deserializedAppointment.Attachment, deserializedAppointment.Intervention, deserializedAppointment.User, deserializedAppointment.Onsite);
                }
                appointmentReader.Close();
                appointmentReader.Dispose();
                if (ConnectionBddSelectAppointment.State != ConnectionState.Closed)
                {
                    ConnectionBddSelectAppointment.Close();
                    ConnectionBddSelectAppointment.Dispose();
                }
                return AppToSend;
            }

    En effectuant différents tests, j'ai pu remarqué que l'ajout dans la bdd se déroule correctement, que seule l'information qui devrait être renvoyée ne l'est pas. Ainsi que si la méthode retourne un Appointment à null, aucune erreur n'est remontée.

    Auriez-vous des pistes de recherche afin de comprendre d'où peut venir le problème sur le retour de l'objet, en sachant que l'insertion en base se déroule correctement (et donc que je devrais récupérer l'objet inséré) ?

    Pour informations, je ne pense pas que cela soit du à la taille de l'objet retourné, étant donné que j'ai une autre méthode qui fonctionne correctement et me renvoi une collection d'objets complexes bien plus longues en terme de taille.

    Restant à votre écoute pour plus de précisions.

    Cordialement.

    jeudi 12 avril 2012 16:11

Réponses

  • Bonjour..

    Après de multiples tests, j'ai pu voir d'où venait le problème finalement et donc j'ai pu le régler.

    Pour information, il s'agissait "simplement" d'un problème au niveau des propriétés de type DateTime qui étaient mal settées et donc non serialisable par mon web service.

    Cordialement.

    lundi 16 avril 2012 13:10

Toutes les réponses