2014-02-19 32 views
-2

我有一個WCF REST服務必須在其方法中提供一個視頻。界面看起來像這裏(我沒有提供實現,因爲問題在這裏)。 [ContentType]被公認,但我得到了System.Net.Mime.ContentType is a type but is used like a variableWCF REST服務:我得到一個System.Net.Mime.ContentType是一個類型,但像變量一樣使用

請幫忙!我知道不該做什麼

public interface MyService 
{  
    //stream video from camera 
    [WebGet(ContentType("video/x-msvideo"), UriTemplate = "video/preview")] 
    [OperationContract] 
    Bitmap VideoPreview();  
} 
+0

http://stackoverflow.com/questions/7967741/vendor-specific-mime-as- content-type-in​​-incoming-wcf-rest-post-request-eg-app –

+0

[XY問題](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。你有問題X(「只允許某種內容類型」)並且認爲Y(「嘗試向我的WebGet屬性添加'ContentType(foo)')可以解決這個問題。請正確解釋您的問題X,因爲Y不會工作:該屬性不支持。看看@ Faizan的建議。 – CodeCaster

+0

添加內容類型如下:WebOperationContext.Current.OutgoingResponse.ContentType =「text/xml」; – Milee

回答

0

ContentType不是一個屬性,也不是它的WebGetAttribute屬性。

根據@ Faizan的鏈接,您無法完成您嘗試使用REST服務的方式 - 他們根本不支持這一點。你可以嘗試明確設置在執行輸出格式爲每@ anony的鏈接:

public interface MyService 
{ 
    //stream video from camera 
    [WebGet(UriTemplate = "video/preview")] 
    [OperationContract] 
    Bitmap VideoPreview();  
} 

public class MyServiceImpl : MyService 
{ 
    public Bitmap VideoPreview() 
    { 
     // code to get video etc... 
     WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.ContentType] = "video/x-msvideo"; 
    }  

}

+0

好吧,我把內容類型,並把它作爲一個獨立的事情像這樣:[OperationContract] [(WebOperationContext.Current.OutgoingResponse.ContentType =「video/x-msvideo」)] [WebGet(UriTemplate = 「video/preview」)] Bitmap VideoPreview(); – Tumelo

+0

@Micha:公平地說,這個「問題」實際上並不要求任何東西...... –

+0

@Ian Kemp:是的;-)。刪除評論。 – Micha

相關問題