Search code examples
c#wcfrestwebhttpbindingoperationcontract

WCF REST Service: I get a System.Net.Mime.ContentType is a type but is used like a variable


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();     
}

Solution

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

    }