Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 270191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:57:36+00:00 2026-05-11T23:57:36+00:00

I have written a simple WCF service that accepts and stores messages. It works

  • 0

I have written a simple WCF service that accepts and stores messages. It works fine when hosted locally. I still works when hosted on IIS 6. But when I enable the service’s ability to store the messages to xml I get the following error: Access to c:\windows\system32\inetsrv\Onno.xml has been denied (translated from dutch, so may not match the true English error message).
This is curious as the service does not run from the mentioned directory. Moreover, the file onno.xml is not present. The service should create it as

xelement.Save("onno.xml");

when

File.Exists("onno.xml")==false

What is wrong?

  • Do I have to specify a default directory for File IO operations inside IIS hosted WCF service?
  • Do I have to adjust permissions?

Edit:
I tried to implement Mehrdad’s solution with the MapPath function thus:

   public void Persist(Message message)
    {
        foreach (var recipient in message.Recipients)//recipient is a string
        {
            XElement xml_messages;
            string path;
            try
            {
                path = HttpContext.Current.Server.MapPath("~/"+recipient+FileExtension);
                //FileExtension=".xml"
                //Null reference exception thrown from this line
            }
            catch (Exception e)
            {
                throw new Exception("Trying to get path " + e.Message);
            }
            try
            {
                xml_messages = XElement.Load(path);
            }
            catch
            {
                xml_messages = XElement.Parse("<nothing/>");
            }
            var element = (XElement) message;
            if (xml_messages.IsEmpty)
            {
                xml_messages =
                    new XElement("messages",
                                 new XAttribute("recipient", recipient),
                                 element
                        );  
            }
            else
            {
                xml_messages.Add(element);
            }
            xml_messages.Save(path);
        }
    }

However I am greeted by a null reference exception?! The exception is generated in the MapPath line. Help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:57:36+00:00Added an answer on May 11, 2026 at 11:57 pm

    Yes. You should specify a full path for the file. You can use

    System.Web.HttpContext.Current.Server.MapPath("~/onno.xml")
    

    to get the full path of the file (if you want to write in the application directory).

    Note that HttpContext.Current is unavailable to WCF services not running in ASP.NET compatibility mode. You can enable ASP.NET compatibility mode with

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    

    configuration option and [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] attribute. However, this will limit your WCF service to ASP.NET environment. This is not a good thing.

    Alternatively, you could use a configuration setting for the base path and use

    System.IO.Path.Combine(defaultPath, "onno.xml")
    

    to get the full path. This solution is more flexible.

    Also, NTFS write permission to that location should be granted to the user account under which the application pool is running.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a very simple WCF service, that worked fine (code below), then
I have written a WCF service with the REST template that has the defaultOutgoingResponseFormat
I have written a simple WCF web service in C# which returns records from
I have a simple console app that calls a WCF service over net.tcp and
I have written a WCF service that I am hosting in IIS7 as a
I have written a Windows Service, that opens up a WCF service on port
I have a WCF service written in C# being hosted on a remote machine,
I have written a simple WCF web service which is configured programmaticaly. It exposes
I have written a simple MSN -style program that will send and retrieve messages
Using Visual Studio 2010, I have written a simple WCF service and some integration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.