Error consuming method of a web service rest

0

I created a method where my partner, besides receiving data from our base, also sends us. Well, that was working well. Then I discovered that there was a field missing. I added this field in the interface and also in the method. Well, I do not know if that was it or something, but it did not work anymore. The error is 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, as it just does write to BD

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 gives in the SaveChanges (); What I added was: _datafechamentoos Looking at the error log I know the problem is in my entity. I just do not know why you are making this mistake, because what was added, in my opinion, did nothing different from what already existed. Before everything worked, including 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 do not know how to do it.

I do not know if this is the problem, but when I put everything in the watch, and I opened each item, there in Entry > > Entity, show the attributes of my entity, okay? Well, I have an Identity field called IDOsParceiro, it should be 11, because the max value of IdOsParceiro is 10 and there it was 0. Well, I think at the moment of SaveChanges (), I think that Identity should already be triggered , right? This was the observation I made, which I found to be different.

    
asked by anonymous 04.06.2014 / 23:50

1 answer

1

With debug you do not have a bug. I discovered the problem. As I generate my entities by ERWin, I made an entity with some string fields of such size. I needed to change and did it for ERWin, for some reason it did not update the new size and the error sneezed. Resolved.

    
05.06.2014 / 00:56