我有一个由 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/