此WCF服务返回一个TIFF图像。它检查它是否连接到我们的存储库 - 并从数据文件中获取字节。它检查文件是PDF,tiff还是图像,并返回适当的MIME类型。我现在可以调用该服务并返回相应的文件 - 但图像名称为“documentID”.tif。我如何设置它返回的图像的文件名?这个WCF服务返回一个TIFF图像 - 我如何设置它返回的图像的文件名?
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate="File/{documentID}")]
Stream GetDocumentFile_GET(string documentID);
public Stream GetDocumentFile_GET(string documentID)
{
if (ProprietaryClass.IsConnected)
{
ProprietaryClass _documentForViewer = new ProprietaryClass(documentID);
string _fileType = ProprietaryClass.NativeFileType;
string _mimetype = "image/tiff";
switch (_fileType)
{
case "TIF":
_mimetype = "image/tiff";
break;
case "PDF":
_mimetype = "application/pdf";
break;
case "PNG":
_mimetype = "image/png";
break;
};
if (ProprietaryClass.ProprietaryMethod(_documentForViewer))
{
ProprietaryClass _downloadToViewer = new ProprietaryClass();
if (_documentForViewer.TiffFile != null)
{
_downloadToViewer = _documentForViewer.TiffFile;
}
else
{
_downloadToViewer = _documentForViewer.NativeFile;
}
MemoryStream fileStream = new MemoryStream(_downloadToViewer.FileData);
// fileStream is now array of bytes
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = _mimetype;
return (Stream)fileStream;
}
else
{
return new MemoryStream(Encoding.UTF8.GetBytes("Document type not supported by native viewer"));
}
}
else
{
return new MemoryStream(Encoding.UTF8.GetBytes("Not connected"));
}
}
到目前为止,这对我有效。 – 2012-03-28 16:30:08