0

I want to display document for specified Document Id. For this, I am calling WCF service from MVC project.

In MVC project, in HomeController.cs

FileStreamResult objFileStreamResult = (FileStreamResult)objDocumentServiceClient.RetrieveDocument(DocId);

In WCF Service project, in DocumentService.svc.cs

public FileStreamResult RetrieveDocument(int DocumentID)

Error:

Type 'System.Web.Mvc.FileStreamResult' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. ÿIf the type is a collection, consider marking it with the CollectionDataContractAttribute.

Could anyone please tell me what am I doing wrong?

Nands
  • 379
  • 3
  • 19
  • 1
    Like the exception says: you can't serialize a FileStreamResult. Use som other class for transmitting your data between the WCF and MVC-backend. Then you can use FIleStreamResult to get the document to the browser. – Jon Lindeheim May 12 '14 at 14:09
  • Thanks Jon. Did as you had suggested. – Nands May 13 '14 at 10:31
  • For anyone stumbling on this: you can return a `Stream` object via WCF, then create the `FileStreamResult` from that in your Controller – mBardos Mar 29 '22 at 13:51

0 Answers0