none
Accessing IIS Virtual Directories from a WCF Web Service

    Question

  • Hi,

    Scenario
    I have a C# WCF Web Service that has a IIS folder containing many Virtual Directories which in turn point to directories on the hosting server's local hard drive and to Windows File Shares on remote servers. The Web Service needs to open and read the media files stored in those directories, on a binary level (passing data back to the client). Ultimately the (silverlight) client will play those media files back, through the Media Element.

    Problem

    I've used Server.MapPath to get the UNC path that the Virtual Directories point to, but my Web Service doesn't seem to have permission to access the files or folders. The Client can access the media files over HTTP as expected.

    Question
    How do I configure IIS or what code do I need to write to gain access to the local/remote files from the Web Service?

    Thanks in advance

    Matt

    Tuesday, August 16, 2011 4:58 PM

Answers

  • Here's how to do it.

    1. Add a new Application Pool in IIS, and set the Process Model Identity to an account that has access to the share folders on the local and remote machines. You can do this via the "Advanced Settings" dialog, when right clicking the new Application Pool.

    2. Right click your Application in IIS and select "Manage Application"->"Advanced Settings". Set the "Application Pool" to the one you defined in step 1.

     

    Job done.

    • Marked as answer by MattHousley Wednesday, August 17, 2011 7:55 AM
    Wednesday, August 17, 2011 7:55 AM

All replies

  • On 8/16/2011 12:58 PM, MattHousley wrote:
    > Hi,
    >
    > Scenario
    > I have a C# WCF Web Service that has a IIS folder containing many
    > Virtual Directories which in turn point to directories on the hosting
    > server's local hard drive and to Windows File Shares on remote servers.
    > The Web Service needs to open and read the media files stored in those
    > directories, on a binary level (passing data back to the client).
    > Ultimately the (silverlight) client will play those media files back,
    > through the Media Element.
    >
    > Problem
    >
    > I've used Server.MapPath to get the UNC path that the Virtual
    > Directories point to, but my Web Service doesn't seem to have permission
    > to access the files or folders. The Client can access the media files
    > over HTTP as expected.
    >
    > Question
    > How do I configure IIS or what code do I need to write to gain access to
    > the local/remote files from the Web Service?
    >
     
    Well,  it comes down to what account is the WCF ASP.NET Web service
    using at the time of the permission denied when the service presented
    credentials to NTFS and the O/S running on the machine the service was
    trying to access folders on the machine local or remote machine.
     
    That's usually going to be the the user account you told the WCF ASP.NET
    Web service it could use when you created the Web service in the virtual
    directory. If you just defaulted and did nothing, then the service is
    using the ASP.NET Worker Process account.
     
    Your problem is what account credentials is the WCF ASP.NET Web service
    using when it presents credentials and does the credentials has the
    proper permissions on a share or folder.
     
     
    Tuesday, August 16, 2011 6:06 PM
  • Thanks for getting back to me darnold924.

    I hadn't associated a user with the Web Service in IIS (I'm using manager 7.5). I'm new to WCF and to be fair I've found it a pretty steep learning curve!

    So, could you teach me to suck eggs, and flesh out what you mentioned above, or point me in the direction of a good blog post.

    I clearly need to associate a user with the Web Service.

    Thanks

    Matt

    Tuesday, August 16, 2011 8:26 PM
  • On 8/16/2011 4:26 PM, MattHousley wrote:
    > Thanks for getting back to me darnold924.
    >
    > I hadn't associated a user with the Web Service in IIS (I'm using
    > manager 7.5). I'm new to WCF and to be fair I've found it a pretty steep
    > learning curve!
    >
    > So, could you teach me to suck eggs, and flesh out what you mentioned
    > above, or point me in the direction of a good blog post.
    >
    > I clearly need to associate a user with the Web Service.
    >
    > Thanks
    >
    > Matt
    >
     
    You can have at it.
     
     
     
    Tuesday, August 16, 2011 8:49 PM
  • Here's how to do it.

    1. Add a new Application Pool in IIS, and set the Process Model Identity to an account that has access to the share folders on the local and remote machines. You can do this via the "Advanced Settings" dialog, when right clicking the new Application Pool.

    2. Right click your Application in IIS and select "Manage Application"->"Advanced Settings". Set the "Application Pool" to the one you defined in step 1.

     

    Job done.

    • Marked as answer by MattHousley Wednesday, August 17, 2011 7:55 AM
    Wednesday, August 17, 2011 7:55 AM