我有一个为JSON数据结构提供服务的WCF Rest服务项目。我已经定义在接口文件就像一个合同:在WCF REST服务中返回非JSON,非XML数据
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "location/{id}")]
Location GetLocation(string id);
现在的WebService需要返回多媒体(图片,PDF文档)像一个标准的Web服务器一样。 ResponseFormat
的WCF WebMessageFormat
仅支持JSON或XML。我如何在界面中定义返回文件的方法?
喜欢的东西:
[OperationContract]
[WebInvoke(Method="GET",
ResponseFormat = ?????
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "multimedia/{id}")]
???? GetMultimedia(string id);
这样:如下图所示wget http://example.com/multimedia/10
返回id为10
看看这个:http://stackoverflow.com/questions/2992095/attaching-files-to-wcf-rest-service-responses – pdiddy
谢谢你pdiddy它解决了这个问题,并包含一些有趣的额外信息。 – Pierre