Error while consuming a web service Rest method

Asked

Viewed 368 times

0

I created a method where my partner, besides receiving data from our base, also sends us. Well, this was working well. Then I discovered that a field was missing. I added this field to the interface and also to the method. Well, I don’t know if it was that or something else, but it didn’t work anymore. The error is that extracted from the server log:

System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. at System.Data.Entity.Internal.InternalContext.SaveChanges() at SuporteTecnicoWS.SuporteTecnicoServiceWS.recebeDadosParceiro(String _idparceiro, String _numos, String _datavisita, String _dataagendamento, String _dataaberturaos, String _datafechamentotarefa, String _datafechamentoos, String _statusos, String _statuspdv, String _tecnico, String _tarefa_fechada) at SyncInvokerecebeDadosParceiro(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) 
  SerializedException <Exception><ExceptionType>System.Data.Entity.Validation.DbEntityValidationException, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.</Message><StackTrace> at System.Data.Entity.Internal.InternalContext.SaveChanges() at SuporteTecnicoWS.SuporteTecnicoServiceWS.recebeDadosParceiro(String _idparceiro, String _numos, String _datavisita, String _dataagendamento, String _dataaberturaos, String _datafechamentotarefa, String _datafechamentoos, String _statusos, String _statuspdv, String _tecnico, String _tarefa_fechada) at SyncInvokerecebeDadosParceiro(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><ExceptionString>System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. at System.Data.Entity.Internal.InternalContext.SaveChanges() at SuporteTecnicoWS.SuporteTecnicoServiceWS.recebeDadosParceiro(String _idparceiro, String _numos, String _datavisita, String _dataagendamento, String _dataaberturaos, String _datafechamentotarefa, String _datafechamentoos, String _statusos, String _statuspdv, String _tecnico, String _tarefa_fechada) at SyncInvokerecebeDadosParceiro(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</ExceptionString></Exception> 
  AppDomain /LM/W3SVC/2/ROOT/WebServiceSuporteTecnico 

This is my interface

[OperationContract]
        [WebInvoke(
            Method = "GET", // Tipo de request
            BodyStyle = WebMessageBodyStyle.Bare, // Identação do retorno
            UriTemplate = "pegastatusparceiro/{_idparceiro}/{_numos}/{_datavisita}/{_dataagendamento}/{_dataaberturaos}/{_datafechamentotarefa}/{_datafechamentoos}/{_statusos}/{_statuspdv}/{_tecnico}/{_tarefa_fechada}" // Url do serviço, onde cada {} = parametro
            )]//Filter para tratar REST
        T_OsParceiro recebeDadosParceiro(string _idparceiro, string _numos, string _datavisita, string _dataagendamento, string _dataaberturaos,
                                                string _datafechamentotarefa, string _datafechamentoos, string _statusos, string _statuspdv,
                                                string _tecnico, string _tarefa_fechada);

And that’s my method, because he only makes it in the comic

public T_OsParceiro recebeDadosParceiro(string _idparceiro, string _numos, string _datavisita, string _dataagendamento, string _dataaberturaos,
                                                string _datafechamentotarefa, string _datafechamentoos, string _statusos, string _statuspdv,
                                                string _tecnico, string _tarefa_fechada)
        {
            using (WEBEntities db = new WEBEntities())
            {
                T_OsParceiro parceiro = new T_OsParceiro();

                parceiro.IDTarefaParceiro = Convert.ToInt32(_idparceiro);
                parceiro.NumOs = Convert.ToInt32(_numos);
                parceiro.DataVisita = Convert.ToDateTime(_datavisita);
                parceiro.DataAgendamento = Convert.ToDateTime(_dataagendamento);
                parceiro.DataAbertura = Convert.ToDateTime(_dataaberturaos);
                parceiro.DataFechamentoTarefa = Convert.ToDateTime(_datafechamentotarefa);
                parceiro.DataFechamento = Convert.ToDateTime(_datafechamentoos);
                parceiro.StatusOS = _statusos;
                parceiro.StatusPDV = _statuspdv;
                parceiro.Tecnico = _tecnico;
                parceiro.Is_Tarefa_Fechada = Convert.ToBoolean(_tarefa_fechada);

                db.T_OsParceiro.Add(parceiro);
                db.SaveChanges();

                return parceiro;
            }
        }

The error is in Savechanges(); What I added was: _datafechamentoos Looking at the error log I know the problem is in my entity. I just don’t know why you are making that mistake, because what was added, in my opinion, did nothing other than what already existed. Before everything worked, even the test was done by the Web Service with the partner consuming the WS or API(REST). The log asks me to see this: 'EntityValidationErrors' , but I don’t know how to.

I don’t know if this is the problem, but when I put everything on the watch, and I opened each item, there in the Entry >> Entity, it shows the attributes of my entity, okay? Well, I have an Identity field called Elderly Partner, he should be with 11, because I max value Elderly Partner is 10 and there was 0. Well, I think at the time of Savechanges(), I think Identity should already be fired, right? That was the remark I made that I thought was different.

  • First of all, modify your db.SaveChanges following the script for that answer to see the errors: http://answall.com/questions/17644/como-correctr-o-entityvalidationerrors/17648#17648

  • I could not make it work as you sent me, Gypsy. The base.Savechanges() gives error

  • The idea is to fall inside the Exception so you can see the errors, using breakpoints and Watch windows.

1 answer

1

With debug there is no bug,. I discovered the problem. As I Gero my entities by Erwin, I made an entity with some string fields of such size. I had to change it and I did it for Erwin, for some reason he didn’t update the new size and the bug sneezed. Solved.

  • But look at the following. I had found the error and this is it. I went to the bank and changed the size of the field from 18 to 255. Well, I removed edmx and created another one. I made an Insert by BD and ok. However by the application(WS) continues the error The field Statuses must be a string or array type with a Maximum length of '18'. It is no longer varchar(18), but varchar(255) and continues with the 18. I already gave a build and nothing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.