Web Api Asp.net mvc has any data limit reported on Route?

Asked

Viewed 60 times

0

I have a web api, I’m trying to do an insertion in a user register, but I noticed that the number of parameters has a limit. If I try to add one more parameter it generates an error:

      [HttpPost]
        [Route("consulta/InseriUsuario/{apiKey}/{userKey}/{idpais}/{idioma}/{idperfil}/{nomecompleto}/{sobrenome}/{titulocareira}/{ladoequipe}/{patrocinador}/{email}/{celular}/{cidade}/{endereco}/{cep}/{uf}/{numero}/{complemento}/{senha}/{login}/{nomeequipe}/{ddi_fone}/{ddd_fone}/{telefone}/{ddi_whtas}/{ddd_whats}/{whatsapp}/{skype}/{twitter}")]

        public  HttpResponseMessage InseriUsuario(string apiKey, string userKey, int IDPAIS, int IDIDIOMA, int IDPERFIL, string NOMECOMPLETO, string SOBRENOME,
                                 string TITULOCARREIRA, string LADOEQUIPE, string PATROCINADOR, string EMAIL,
                                 string CELULAR, string CIDADE, string ENDERECO, string CEP,
                                 string UF, string NUMERO, string COMPLEMENTO, string SENHA,
                                 string LOGIN, string NOMEEQUIPE, string DDI_FONE, string DDD_FONE,
                                 string TELEFONE, string DDI_WHATS, string DDD_WHATS, string WHATSAPP,
                                 string SKYPE, string TWITTER, string FACEBOOK, string URLCADASTRO,
                                 string URLCONFERENCIA, string HORACONFERENCIA, string URLCONFERENCIAGRAVADA, string URLLOJAVIRTUAL,
                                 string TITULODEPOIMENTO, string DESCRICAODEPOIMENTO, string IMAGEMPERFIL)
        {

            try
            {
                var tTabela = new UsuarioAplicacao();
                tTabela.InseriUsuario(apiKey, userKey, IDPAIS, IDIDIOMA, IDPERFIL, NOMECOMPLETO, SOBRENOME, TITULOCARREIRA, LADOEQUIPE,
                                        PATROCINADOR, EMAIL, CELULAR, CIDADE, ENDERECO, CEP, UF, NUMERO, COMPLEMENTO, SENHA, LOGIN, NOMEEQUIPE,
                                        DDI_FONE, DDD_FONE, TELEFONE, DDD_WHATS, DDD_WHATS, WHATSAPP, SKYPE, TWITTER, FACEBOOK, URLCADASTRO,
                                        URLCONFERENCIA, HORACONFERENCIA, URLCONFERENCIAGRAVADA, URLLOJAVIRTUAL, TITULODEPOIMENTO,
                                        DESCRICAODEPOIMENTO, IMAGEMPERFIL);

                return Request.CreateResponse(HttpStatusCode.OK, tTabela);
            }
            catch (Exception ex)
            {

                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }
        }

inserir a descrição da imagem aqui

  • you can turn all these parameters into one object

  • 1

    @Eduardosampaio, has to post a more detailed example, thank you

1 answer

0

object

public class ClientViewModelRegister
{      
    public string Name { get; set; }
    public string Email { get; set; }
}



        [HttpPost]
        [Route("register")]
        public HttpResponseMessage Register(ClientViewModelRegister model)
        {

            try
            {
                if (ModelState.IsValid)
                {
                    Client client = new Client()
                    {
                        Name = model.Name,
                        Email = model.Email,
                        DateRegister = DateTime.Today                                                  
                    };

                    _AppClient.Insert(client);

                    return Request.CreateResponse(HttpStatusCode.OK, "Register Successfully");

                }
                else
                {
                    return ErrorModel();
                }
            }
            catch (Exception e)
            {

                return Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }

        }

first we have object according to the controller you have to do this way where they are property, you put everything in object you want to receive as parameter so it becomes simpler,I will leave link of a project below for you to have as example. https://github.com/EduardoSampaio/Gerenciamento.api/blob/master/Gerenciamento.Api/Controllers/ClientController.cs

Obs: every call you name when you send must be equal to the property if you will not receive null value.

ex: if I send a name object must have property public string name {get;set;}

Browser other questions tagged

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