小编Ora*_*rac的帖子

如何从HttpResponseMessage读取MultipartContent?

我有以下WebApi,它将MultipartContent返回给客户端,其中包含来自数据库的图像和一些附加数据: -

    public class PhotoController : ApiController
{

    public HttpResponseMessage GetPhoto(Int32 personId)
    {
        var service = new PhotoService();
        var photo = service.SelectPrimaryPhoto(personId);
        if (photo == null)
            return Request.CreateResponse(HttpStatusCode.NoContent);
        HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
        var content = new MultipartContent();
        content.Add(new ObjectContent<Photo.Data>(photo, new JsonMediaTypeFormatter()));
        content.Add(new StreamContent(photo.Image));
        response.Content = content;
        return response;
    }
}
Run Code Online (Sandbox Code Playgroud)

在客户端上,HttpResponseMessage.Content表示为StreamContent类型.如何以MultipartContent的形式访问它?客户端是WPF - 而不是Web浏览器.

.net c# asp.net-web-api

5
推荐指数
2
解决办法
4807
查看次数

标签 统计

.net ×1

asp.net-web-api ×1

c# ×1