c# - 获取 wcf 服务程序集中文件的路径

标签 c# .net wcf .net-assembly filepath

我有一个由 IIS 中托管的 WCF 服务引用的程序集。该程序集使用了一些 XSLT 文件,我很困惑将这些文件转储到哪里,要么在程序集项目本身中创建一个文件夹,要么在 WCF 服务端创建一个文件夹,以及如何在程序集中获取 xslt 文件的物理路径?

最佳答案

由于 IIS 托管的 WCF 服务只倾向于将 DLL 复制到临时文件夹而不是设置为复制到输出的项目内容,因此需要引用 dll 的实际代码库。

var codeBase = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
                    codeBase = codeBase.Substring(8); //Remove the "file:///" prefix in front of the actual path.

var dir = codeBase.Substring(0, codeBase.LastIndexOf("/", System.StringComparison.Ordinal) + 1); //Cut out the dll file name.

var file = @"ErrorMessages.xml";

var targetPath = dir + file;

关于c# - 获取 wcf 服务程序集中文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6176448/

相关文章:

c# - WCF ServiceHost 访问权限

c# - 有更好的方法吗: Joins on different Datatables?

c# - MyProject.resources 上的 FileNotFoundException

c# - 单元测试本地化字符串

c# - 创建适用于 System.Object 的扩展方法的良好做法?

c# - 使用 SSL 加密在 IIS 10 上托管 WCF 服务库

c# - 从 BindingList 中删除最后一条记录会选择导致 DataGridView 滚动的最后一行

c# - 线程 : Locking Under the hood of

.net - 我应该将.NET Framework目录添加到PATH吗?

c# - 为什么 WebInvoke 不允许此方法,但 WebGet 可以?