如何访问Windows服务中托管的WCF服务的App_Data文件夹中的文件 [英] How To access a file in the App_Data folder of WCF Service Hosted in Windows Service

查看:83
本文介绍了如何访问Windows服务中托管的WCF服务的App_Data文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好,

我有一个WCF服务,其app_data文件夹中有一个xml文件.
我在服务中有一个方法,可以使用System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath访问app_data文件夹中的xml文件.
当我在IIS中托管服务时,它运行良好.
但是当我使用Windows Service托管它时,它不起作用.
然后,我发现了"System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath".当服务托管在Windows Service中时,返回NULL.
请给我一个示例代码,以访问WCF服务的app_data文件夹中的xml文件,以便在我们将其托管在Windows Service中时可以正常工作.

I have a WCF Service That has an xml file in its app_data folder.
I have a method in the service that access the xml file in the app_data folder using System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath.
It worked fine when I hosted the service in IIS.
But It does not work when i host it using Windows Service.
I then discovered that "System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath" returns NULL when the service is hosted in Windows Service.
Please give me an idea with sample code to access the xml file in the app_data folder of the WCF service such that it should work fine when we host it in Windows Service.

推荐答案

使用HostingEnvironment.MapPath();方法,您应该能够找到所需的位置.   IntelliSense将为您提供所需的重载.

Using the HostingEnvironment.MapPath(); method, you should be able to get the location you are looking for.  IntelliSense will give you the overloads you will need.

 

希望这会有所帮助!


这篇关于如何访问Windows服务中托管的WCF服务的App_Data文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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