I have a Web Api that shows some datas. Now, i have to Show a image, that is stored on a Oracle DB... in Oracle DB is everything ok and the Stored Procedure brings me a "Long Raw". Actualy the result of FOTO on the controller is empty [{"ISUSPID":0,"FOTO":""}], even when on DB brings me the image... The question is what i am doind wrong, thats the FOTO is empty on Json ???
This is my class [FotoEnvolvido]:
using System;
using System.ComponentModel.DataAnnotations;
namespace WebApiApp.Models
{
public class FotoEnvolvido
{
[Key]
public Int32 ISUSPID { get; set; }
public byte[] FOTO { get; set; }
}
}
This is my Controller:
[HttpGet]
[Route("Foto")]
public IEnumerable<FotoEnvolvido> GetFoto(Int32 isuspid)
{
DataSet lretorno = new DataSet();
string connectionString = GetConnectionString();
using (OracleConnection connection = new OracleConnection())
{
connection.ConnectionString = connectionString;
OracleDataReader reader = null;
OracleCommand cmd = new OracleCommand();
cmd.Connection = connection;
cmd = new OracleCommand("MOBILE.XAPIMANDADOMOBILE.BUSCAFOTO", connection);
cmd.CommandType = CommandType.StoredProcedure;
//variáveis entrada
cmd.Parameters.Add(new OracleParameter("isuspid", isuspid));
//variáveis de saida
cmd.Parameters.Add(new OracleParameter("oretorno", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
connection.Open();
cmd.ExecuteNonQuery();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
//CRIO A LISTA
lretorno.Load(reader, LoadOption.OverwriteChanges, "BUSCAFOTO");
connection.Close();
connection.Dispose();
//CARREGO O DATASET E TRANSFORMO PARA IENUMERABLE E RETORNO SEUS VALORES PRO JSON
return lretorno.Tables[0].AsEnumerable().Select(row => new FotoEnvolvido
{
FOTO = (byte[])(row["FOTO"]),
});
}
}