locked
MineType attribute example on ServiceOperations? RRS feed

  • Question

  •  

    Hi Guys,

     

     

    Is there an example of to use the MineTypes attribute on ServiceOperations

     

     

    Thanks

     

    John

    Thursday, April 3, 2008 12:52 AM

Answers

  •  

    Here's an example:

     

    Code Snippet

    class MyDataService: WebDataService

    {

    [SingleResult]

    [WebGet]

    [MimeType("text/html;level=1")]

    public IQueryable<string> Op()

    {

    return new string[] { "howdy" }.AsQueryable();

    }

    }

     

     

     

    In the current bits, we have changed the MimeType to be specified on type (in this case on MyDataService), but in the CTP bits, this is how you can specify a mime type for a service operation.

     

    Note, mime types are only helpful if the service operation returns a primitive type.

     

    Thanks

    Pratik

    Thursday, April 3, 2008 5:36 PM
    Moderator
  • The only way to do this will be to set the mime type attribute on the property and set the mime type as application/pdf. Then astoria service will allow this to be rendered as application/pdf.

     

    Hope this helps.

    Thanks

    Pratik

     

    Tuesday, April 22, 2008 8:59 PM
    Moderator

All replies

  •  

    Here's an example:

     

    Code Snippet

    class MyDataService: WebDataService

    {

    [SingleResult]

    [WebGet]

    [MimeType("text/html;level=1")]

    public IQueryable<string> Op()

    {

    return new string[] { "howdy" }.AsQueryable();

    }

    }

     

     

     

    In the current bits, we have changed the MimeType to be specified on type (in this case on MyDataService), but in the CTP bits, this is how you can specify a mime type for a service operation.

     

    Note, mime types are only helpful if the service operation returns a primitive type.

     

    Thanks

    Pratik

    Thursday, April 3, 2008 5:36 PM
    Moderator
  • Hi Pratik,

     

    Thanks for the example and this works and the browser renders the result as html in the browser.  I tried the same approach for pdf data using the adventure works as a data source, however this failed to render as a pdf, here is a code example:

     

    Code Snippet

     

    [WebGet]

    [MimeType("application/pdf; level=1")]

    [SingleResult]

    public IQueryable<string> GetIllustration()

    {

    IQueryable<string> query = from illustration in this.CurrentDataSource.Illustration

    where illustration.IllustrationID == 3

    select illustration.Diagram;

     

    return query.AsQueryable();

    }

     

    Any idea what I need to do to make this work?

     

    Thanks

     

    John

    Tuesday, April 8, 2008 12:34 PM
  • The only way to do this will be to set the mime type attribute on the property and set the mime type as application/pdf. Then astoria service will allow this to be rendered as application/pdf.

     

    Hope this helps.

    Thanks

    Pratik

     

    Tuesday, April 22, 2008 8:59 PM
    Moderator