使用 SvcImplementation 程序集获取 SvcHost 程序集位置(路径) [英] Get SvcHost assembly location (path) using SvcImplementation assembly
问题描述
我有 Windows 8.1 x64、Visual Studio 2012 x86、IIS 8.5.
I have windows 8.1 x64, Visual Studio 2012 x86, IIS 8.5.
我有 Wcf 服务主机项目(包含 svc 文件)
I have Wcf Service Host project (contains svc file)
<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceImplementation.MyService" %>
我有 Wcf 服务实施项目.
I have Wcf Service implementation project.
在 IIS 中托管的 Wcf 服务
Wcf Service hosted in IIS
我有 2 个程序集:WcfService.Host.dll 和 WcfServiceImplementation.dll
I have 2 assemblies: WcfService.Host.dll and WcfServiceImplementation.dll
WcfServiceImplementation.dll 中的这段代码:
This code in WcfServiceImplementation.dll:
1)
Assembly.GetEntryAssembly()
为空.
2)
Assembly.GetExecutingAssembly()
获取 WcfServiceImplementation.
gets WcfServiceImplementation.
3)
Assembly.GetCallingAssembly()
获取 System.ServiceModel.
gets System.ServiceModel.
如何在执行 WcfServiceImplementation 程序集的代码中以编程方式获取 Service.Host 程序集位置?
How can I get Service.Host assembly location programatically in the code that execute WcfServiceImplementation assembly?
一般来说,对于任何 Wcf 服务或 Web 应用程序,如何获得主程序集"(wcf 服务主机、Web 应用程序)?
In general, for any Wcf Service or Web Application, how get the "main assembly" (the wcf service host, the web application) ?
我的踪迹(日志):
ProcessName: w3wp
Is64BitOperatingSystem: True
Is64BitProcess: True
SystemConfigurationFile: C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config
ConfigurationFile: C:TFSTestsWcfServiceweb.config
MainModule.FileName: c:windowssystem32inetsrvw3wp.exe
MainModule.ModuleName: w3wp.exe
BaseDirectory: C:TFSTestsWcfService
ApplicationBase: C:TFSTestsWcfService
FriendlyName: /LM/W3SVC/2/ROOT-5-130404032112324911
ApplicationName: c36153ea
Code in WcfServiceImplementation assembly:
Assembly.GetEntryAssembly():
GetAssemblyExtendedData. Assembly null
Assembly.GetExecutingAssembly():
Location: C:WindowsMicrosoft.NETFramework64v4.0.30319Temporary ASP.NET Files
oot2090c609c36153eaassemblydl392d3ec190fa1582_c649cf01WcfServiceImplementation.dll
ProcessorArchitecture: MSIL
Assembly.GetCallingAssembly():
Location: C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.ServiceModelv4.0_4.0.0.0__b77a5c561934e089System.ServiceModel.dll
ProcessorArchitecture: MSIL
建议?
推荐答案
这个在 WCF 服务中对我有用:
This one worked for me in WCF service:
AppDomain.CurrentDomain.RelativeSearchPath
AppDomain.CurrentDomain.RelativeSearchPath
例如:
字符串 certFilePath =AppDomain.CurrentDomain.RelativeSearchPath + "" +CERTIFICATES_DIRECTORY_NAME + "" + CERTIFICATE_FILE_NAME;
string certFilePath = AppDomain.CurrentDomain.RelativeSearchPath + "" + CERTIFICATES_DIRECTORY_NAME + "" + CERTIFICATE_FILE_NAME;
您可以看到文件被复制到子目录下,并且解决方案中的这些文件被标记为构建操作复制到输出目录",它复制目录和文件(我想要我的情况,否则使用资源作为项目中的链接).
You can see the files are copied under sub-directory and these files in the solution are marked as build-action "Copy to output directory" which copies directory as well as files (which I wanted for my case, otherwise use resources as the link in the project).
这篇关于使用 SvcImplementation 程序集获取 SvcHost 程序集位置(路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!