在托管在IIS6 WCF服务的默认目录? [英] Default Directory in a WCF service that is hosted in IIS6?

查看:168
本文介绍了在托管在IIS6 WCF服务的默认目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了接受和存储信息简单的WCF服务。本地托管当它工作正常。在IIS 6,托管时,我仍然有效,但是,当我能够存储信息为xml我得到以下错误的服务的能力:进入C:\ WINDOWS \ SYSTEM32 \ INETSRV \ Onno.xml已被拒绝(来自荷兰语翻译,所以可能不符合真正的英文错误消息)。 这是好奇,服务不自提目录中运行。此外,该文件onno.xml不是present。服务应该将其创建为

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");

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

什么是错的?

What is wrong?

  • 请我一定要指定IIS内部文件IO操作的缺省目录承载WCF服务?
  • 请我一定要调整的权限?

编辑: 我试图执行迈赫达德的与MapPath的功能从而解决办法:

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

不过,我用一个空引用异常正在招呼?唯一的例外是在MapPath的线路产生。帮助?

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

推荐答案

是的。您应指定该文件的完整路径。您可以使用

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).

注意 HttpContext.Current 是无法使用WCF服务的 ASP.NET兼容模式。您可以启用ASP.NET兼容模式

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" />

配置选项和 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 属性。然而,这会限制你的WCF服务,ASP.NET环境。这是不是一件好事。

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.

此外,NTFS写入权限,该位置应授予其下的应用程序池正在运行的用户帐户。

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

这篇关于在托管在IIS6 WCF服务的默认目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆