Search code examples
angularjsasp.net-web-apiangular-resource

Can't get from web api with complex parameter


I have this function in my web api backend

[HttpGet]
public WmsWebStatus<OrdemRecebimento> CriaOrdemRecebimento(OrdemRecebimento ordemRecebimentoContrato)
{
  try
  {
    WmsWebStatus<OrdemRecebimento> retorno = WmsWebStatus<OrdemRecebimento>.Autenticacao.WMS1001;
    retorno.Retorno = Resolve<IOrdemRecebimentoServico>().CriaOrdemRecebimento(ordemRecebimentoContrato);
    return retorno;
  }
  catch (Exception ex)
  {
    WriteLog.Exception(ex);
    return WebserviceUtil.ObterStatus<OrdemRecebimento>(ex);
  }
}

and I have this on my angular factory

app.factory('recebimentoServico', function ($q, $resource, $http) {  servico.teste = function (parametros) {
return $q(function (resolve, reject) {
  $resource(urlWebService + '/Recebimento/', null)
    .get({teste: "produto"}, function (dados) {
      resolve(dados);
    }, function (erro) {
      reject(erro);
    });
}); }  return servico;});

where I have {teste: "produto"}, I want to pass a JSON object that matches the OrdemRecebimento object

but it seems that whenever I try to pass a JSON object, it always come as null in the backend.

How can I pass an JSON object to my Web API backend?


Solution

  • Does this method create an order (based on my google translate of the name)? If so do not use Get ([HttpGet]), use Post ([HttpPost]) instead as you are modifying data and that is what Post is for.

    Once you fix that then use $http.post to send the data to your web api.