locked
RESTful Service Error RRS feed

  • Question

  • Following the screencast at Enpoint.tv I created a restful service

    public interface IMediaService
      {
        [OperationContract]
        [WebGet(UriTemplate="media/{name}")]
        Stream GetMedia(string name);
        [OperationContract]
        [WebGet(UriTemplate = "medias")]
        string ListMedia(); 
      }
    
     public class MediaService : IMediaService
      {
    
        #region IMediaService Members
    
        public Stream GetMedia(string name)
        {
          var dir = HttpContext.Current.Server.MapPath("~");
          var file = String.Format("{0}.wmv", name);
          var filePath = Path.Combine(dir, file);
          //return filePath.ToString();
          return File.OpenRead(filePath);
        }
        public string ListMedia()
        {
          return (HttpContext.Current.Server.MapPath("/media.svc"));
        }
    
        #endregion
      }

    now when I call my service http://localhost/mediaSite/media.svc/medias

     

    I am hosting the Service using IIS and ther media.svc file is

    <%@ ServiceHost Service="MediaStreamingLibrary.MediaService" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

    I get an error

    The server encountered an error processing the request. See server logs for more details.

     


    Monday, April 26, 2010 6:13 AM

Answers

  • The problem was with HttpContext.Current.Server.MapPath,

    I changed it to AppDomain.CurrentDomain.BaseDirectory

    So it's all fine now

    :)

    • Marked as answer by Xaria Monday, April 26, 2010 7:28 AM
    Monday, April 26, 2010 6:44 AM

All replies

  • Hi

    Firstyl, did you check if the service is working as expected?That is the ListMedia operation working fine without any errors.You can try WCF tracing to check if there is any exceptions in the service side.

    You can read more about WCF Tracing from MSDN: Configuring Tracing.

    Microsoft provides a Service Trace Viewer Tool to read .svclog files.

    Make sure the path defined in initializeData is writable by your service.

    Next,how are you invokign the service?Can you pls post the code that is used by you to get the response.


    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    Monday, April 26, 2010 6:32 AM
  • The problem was with HttpContext.Current.Server.MapPath,

    I changed it to AppDomain.CurrentDomain.BaseDirectory

    So it's all fine now

    :)

    • Marked as answer by Xaria Monday, April 26, 2010 7:28 AM
    Monday, April 26, 2010 6:44 AM