-2

I have a WCF REST service that has to provide a video in one of its methods. The interface looks like under here (I did not provide the implementation because the problem lies here). [ContentType] is recognized but I get a System.Net.Mime.ContentType is a type but is used like a variable.

Please Help! I know NOT what to do

public interface MyService
{    
    //stream video from camera
    [WebGet(ContentType("video/x-msvideo"), UriTemplate = "video/preview")]
    [OperationContract]
    Bitmap VideoPreview();     
}
Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Tumelo
  • 301
  • 3
  • 18
  • http://stackoverflow.com/questions/7967741/vendor-specific-mime-as-content-type-in-incoming-wcf-rest-post-request-e-g-app – Faizan Mubasher Feb 19 '14 at 07:39
  • [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). You have problem X ("only allow a certain content-type") and thought Y ("try adding `ContentType(foo)` to my WebGet attribute") would solve that. Please explain your problem X properly, as Y isn't going to work: the attribute doesn't support that. Take a look at @Faizan's suggestion. – CodeCaster Feb 19 '14 at 07:43
  • add content type like this: WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"; – Milee Feb 19 '14 at 07:48
  • I tried adding it like this: – Tumelo Feb 19 '14 at 08:19
  • Scratches head! XY Problem? – Tumelo Feb 19 '14 at 08:23
  • @Anony: do I add it within WebGet? how do I add it . . .I tried; [WebGet(WebOperationContext.Current.OutgoingResponse.Contenttype = "video/x-msvideo")] and it does not like that. And also [WebGet. . .][WebOperationContext.Current.OutgoingResponse.ContentType = "video/x-msvideo"] then it says "Identifier expected" – Tumelo Feb 19 '14 at 08:27
  • This way: http://social.msdn.microsoft.com/Forums/vstudio/en-US/c2672206-f255-4b14-b45e-7e3d057f4ffc/setting-weboperationcontextcurrentoutgoingresponsecontenttype-has-no-effect?forum=wcf – Milee Feb 19 '14 at 08:58
  • _"Scratches head! XY Problem?"_ - yes, the term is a link (click it and learn), and I provided an explanation after that. For a better question, explain what you are trying to do, not only what is failing. :) – CodeCaster Feb 19 '14 at 16:52

1 Answers1

0

ContentType is not an attribute, nor is it a property of WebGetAttribute.

As per @Faizan's link, you cannot accomplish what you are trying to do with REST services - they simply do not support this. What you can try is explicitly setting the output format in your implementation as per @anony's link:

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";
    }     

}

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
  • Okay fine, I took the content type and put it as a stand alone thingy like this: [OperationContract] [(WebOperationContext.Current.OutgoingResponse.ContentType="video/x-msvideo")] [WebGet(UriTemplate = "video/preview" )] Bitmap VideoPreview(); – Tumelo Feb 19 '14 at 08:22
  • @Ian Kemp: yep ;-). Delete the comment. – Micha Feb 19 '14 at 09:27
  • YESLYK! You guys are very effective @Anony, Lan Kemp & Faizan (not Micha). . .the darn 'thing' is working now :-D. Thanks julle! – Tumelo Feb 19 '14 at 09:40