【问题标题】:Get SvcHost assembly location (path) using SvcImplementation assembly使用 SvcImplementation 程序集获取 SvcHost 程序集位置(路径)
【发布时间】:2014-08-21 15:36:43
【问题描述】:

我有 Windows 8.1 x64、Visual Studio 2012 x86、IIS 8.5。

我有 Wcf 服务主机项目(包含 svc 文件)

<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceImplementation.MyService"  %>

我有 Wcf 服务实施项目。

IIS 中托管的 Wcf 服务

我有 2 个程序集:WcfService.Host.dll 和 WcfServiceImplementation.dll

WcfServiceImplementation.dll 中的这段代码:

1)

Assembly.GetEntryAssembly()

得到空值。

2)

Assembly.GetExecutingAssembly()

获取 WcfServiceImplementation。

3)

Assembly.GetCallingAssembly()

获取 System.ServiceModel。

如何在执行 WcfServiceImplementation 程序集的代码中以编程方式获取 Service.Host 程序集位置?

一般来说,对于任何 Wcf 服务或 Web 应用程序,如何获取“主程序集”(wcf 服务主机、Web 应用程序)?

我的踪迹(日志):

ProcessName: w3wp
Is64BitOperatingSystem: True
Is64BitProcess: True
SystemConfigurationFile: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config
ConfigurationFile: C:\TFS\Tests\WcfService\web.config
MainModule.FileName: c:\windows\system32\inetsrv\w3wp.exe
MainModule.ModuleName: w3wp.exe
BaseDirectory: C:\TFS\Tests\WcfService\
ApplicationBase: C:\TFS\Tests\WcfService\
FriendlyName: /LM/W3SVC/2/ROOT-5-130404032112324911
ApplicationName: c36153ea



Code in WcfServiceImplementation assembly:

Assembly.GetEntryAssembly():
GetAssemblyExtendedData. Assembly null

Assembly.GetExecutingAssembly():
Location: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2090c609\c36153ea\assembly\dl3\92d3ec19\b0fa1582_c649cf01\WcfServiceImplementation.dll
ProcessorArchitecture: MSIL

Assembly.GetCallingAssembly():
Location: C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll
ProcessorArchitecture: MSIL

建议?

【问题讨论】:

    标签: wcf .net-assembly servicehost


    【解决方案1】:

    这个在 WCF 服务中为我工作:

    AppDomain.CurrentDomain.RelativeSearchPath

    例如:

    字符串 certFilePath = AppDomain.CurrentDomain.RelativeSearchPath + "\" + CERTIFICATES_DIRECTORY_NAME + "\" + CERTIFICATE_FILE_NAME;

    您可以看到文件被复制到子目录下,并且解决方案中的这些文件被标记为构建操作“复制到输出目录”,它复制目录和文件(我想要我的情况,否则使用资源作为项目中的链接)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      相关资源
      最近更新 更多