我有一個爲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