嗨,我在 Web Api 服务中有获取个人图像的方法
public HttpResponseMessage GetPersonnelPicture( int personnelId)
{
JamsazERPLiteEntities db = new JamsazERPLiteEntities();
var fingerPrint = db.FingerPrints.FirstOrDefault(c => c.SequenceNumber == fingerNumber && c.MAC == MAC && !c.IsDeleted);
if (fingerPrint != null && fingerPrint.Personnel != null)
{
try
{
var result = new HttpResponseMessage(HttpStatusCode.OK);
FileStream fileStream =
new FileStream(@"\\atlas\Personnel Pictures\" + personnelId + ".jpg",
FileMode.Open);
Image image = Image.FromStream(fileStream);
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Jpeg);
result.Content = new ByteArrayContent(memoryStream.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
memoryStream.Close();
memoryStream.Dispose();
fileStream.Close();
fileStream.Dispose();
return result;
}
catch { }
}
return null;
}
当在 IIS Express 中的 Visual Studio 2017 中运行 Web 服务并成功从客户端发送请求时(我通过 Postman 应用程序从发送请求测试localhost:23254/api/Weight/GetPersonnelPicture/?personnelId=2154
)
但是当发布到本地 IIS 时,邮递员应用程序出现流动错误
{ “Message”:“发生错误。”,“ExceptionMessage”:“在期望 HttpResponseMessage 实例的地方返回空值。”,“ExceptionType”:“System.InvalidOperationException”,“StackTrace”:“在 System .Web.Http.Controllers.ResponseMessageResultConverter.Convert(HttpControllerContext controllerContext, Object actionResult)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- 上一个堆栈跟踪结束引发异常的位置 ---\r\n 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n 在 System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- 堆栈跟踪从上一个异常位置结束被抛出 ---\r\n 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n 在 System.Web.Http。 Dispatcher.HttpControllerDispatcher.d__0.MoveNext()" }