Comment insérer un type blob avec entity framework et wcf?

Fermé
souhir00 Messages postés 1 Date d'inscription mercredi 14 novembre 2012 Statut Membre Dernière intervention 14 novembre 2012 - 14 nov. 2012 à 23:03
 fakher - 25 nov. 2012 à 16:35
Bonjour,
Ma tache consiste à ajouter un document en utilisant le wcf et entity framework.
J'ai fai une table Document qui possédent les champs:id/title/type/contenu/date
Au niveau WCF j'ai 3 classes:
Iservice qui contient les appels des méthodes
DTO datacontract:
public class DTO
{
[DataMember]
public int idDocument { get; set; }
[DataMember]
public string title_document { get; set; }
[DataMember]
public string type_document { get; set; }
[DataMember]
public decimal size_document { get; set; }
[DataMember]
public DateTime document_date { get; set; }
[DataMember]
public bool validation { get; set; }
[DataMember]
public string document_owner { get; set; }
[DataMember]
public byte[] container { get; set; }

}
Converter.cs:
public class Converter
{
public static DTO ConvertWCFtoWCFDTO(Document obj)
{
DTO objdto = new DTO();
objdto.idDocument = obj.id_document;
objdto.title_document = obj.title_document;
objdto.type_document = obj.type_document;
objdto.size_document = (decimal)obj.size_document;
objdto.validation = (bool)obj.validation;
objdto.document_date = (DateTime) obj.document_date;
objdto.document_owner = obj.document_owner;
objdto.container = obj.container;
return objdto;
}

public static Document ConvertWCFDTOtoWCF(DTO obj)
{
Document objdto = new Document();
objdto.id_document = obj.idDocument;
objdto.title_document = obj.title_document;
objdto.type_document = obj.type_document;
objdto.size_document = obj.size_document;
objdto.validation = obj.validation;
objdto.document_owner = obj.document_owner;
objdto.document_date = (DateTime)obj.document_date;
objdto.container = obj.container;
return objdto;
}
}

Service.cs
public void InsertData(DTO obj)
{
ent = new SASPEEntities2();
Document insertobject = Converter.ConvertWCFDTOtoWCF(obj);
ent.AddObject("Document", insertobject);
ent.SaveChanges();
}

Bon au niveau du test:
private void button1_Click(object sender, EventArgs e)
{
Service1Client proxy = new Service1Client();

OpenFileDialog openFile = new OpenFileDialog();

openFile.DefaultExt = "*";
openFile.Filter = "All files (*.*)|*.*";
openFile.ShowDialog();

if (openFile.FileName.Length > 0)
{
file = openFile.FileName;
name = Path.GetFileNameWithoutExtension(file);
extension = Path.GetExtension(file);
size = openFile.FileName.Length;
contenu = File.ReadAllBytes(file);
}

DTO doc1 = new DTO();
doc1.title_document = name;
doc1.type_document = extension;
doc1.size_document = size;
doc1.document_date = dt;
doc1.validation = validation;
doc1.container = contenu;
doc1.document_owner = "souhir";

proxy.InsertData(doc1);

}
}

Ca marche pour tous sauf pour contenu du document svp veuillez m'aider je suis bloqué :((
A voir également:

1 réponse

bon soir ,svp lein de site de PFE
0