如何让IIS加载我的WCF服务引用的本机DLL? [英] How do I get IIS to load a native DLL referenced by my WCF service?

查看:175
本文介绍了如何让IIS加载我的WCF服务引用的本机DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务包含一些C#代码,引用一个C ++ / CLI dll,它引用一些本机DLL。我包括我的IIS应用程序的bin文件夹中的所有必需的DLL,但是当IIS加载托管DLL时,似乎将它们复制到一个深层目录,如:

I have a WCF service that contains some C# code, which references a C++/CLI dll, which references some native DLLs. I include all of the necessary DLLs in the bin folder for my IIS application, but when IIS loads the managed DLLs, it seems to be copying them to a deep directory like:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\testwcf\73473be6\e625098c\assembly\dl3\aada7c33\85a7332b_2f9acc01

它将每个受管的DLL复制到其自己的目录并加载它。当它到达我的C ++ / CLI DLL,它将其复制到一个类似上面的目录,然后它无法加载依赖项。如果我手动将所有本地DLL复制到此文件夹,它将运行,但这不是一个很好的解决方案。

It copies each managed DLL to its own directory and loads it. When it gets to my C++/CLI DLL, it copies it to a directory like above, and then it is unable to load the dependencies. If I manually copy all of the native DLLs into this folder, it will run, but that's not a great solution.

我的web.config是由VS创建的股票,具有基于MSDN文章定义的端点。

My web.config is the stock one created by VS, with an endpoint defined based on an MSDN article.

<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WcfService.Service1">
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="WcfService.IService1" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

如何让这些DLL自动获取?

How can I get these DLLs to be picked up automatically?

推荐答案

这个帖子,似乎本地DLL需要在某些目录或路径中可用:

From this post, it seems that the native DLLs need to be available in certain directories or on the path:


导致此问题的核心原因是操作系统
在运行时加载本机DLL。本地DLL是使用
下面的逻辑加载的,它不包括临时ASP.net文件和
应用程序/ bin文件夹。如果Native DLL不包含在/ bin文件夹中,而
为.EXE文件,或者DLL不在路径环境变量中,则此问题也会发生在任何.Net
应用程序中。

The core cause to this problem is in the way the operating system loads native DLL's at runtime. Native DLL's are loaded using the following logic which does not include the Temporary ASP.net Files nor the applications /bin folder. This problem will also occur in any .Net application if the Native DLL is not included in the /bin folder with the .EXE file or if the DLL is not in the Path Environment Variable.


  1. 应用程序加载的目录。在
    ASP.Net的情况下,这将解析为%windir%\Microsoft.Net\Framework\v ### \
    或%windir%\system32\inetsrv为IIS 6。

  2. 当前目录。在ASP.Net的情况下,这将解析为%6的%windir%\System32 \inetsrv
    。如果使用内置的Web服务器,这将解析为一个路径
    在C: \Program Files \Microsoft Visual Studio 8.

  3. Windows系统
    目录。使用GetSystemDirectory函数获取
    此目录的路径。

  4. Windows目录。使用GetWindowsDirectory
    函数获取此目录的路径。

  5. 在PATH环境变量中列出的
    的目录。

  1. The directory from which the application loaded. In the case of ASP.Net, this will resolve to %windir%\Microsoft.Net\Framework\v###\ or %windir%\system32\inetsrv for IIS 6.
  2. The current directory. In the case of ASP.Net, this will resolve to %windir%\System32\inetsrv for IIS 6. If using the built-in web server, this resolves to a path under C:\Program Files\Microsoft Visual Studio 8.
  3. The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
  4. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  5. The directories that are listed in the PATH environment variable.


提供的解决方案如下:



  1. 使用DLLImport在
    运行时使用相对路径或绝对路径加载dll。

  2. 设置PATH环境变量,可以
    找到C ++ DLL。您可以在运行时设置此属性,以便
    只影响运行您的代码的进程。您还可以在系统属性(环境变量| PATH
    属性)中全局设置此
    。以编程方式设置不需要重新引导和
    ,如果您希望
    能够对ASP.Net应用程序执行XCopy部署,则可以将PATH指向Web应用程序的/ bin文件夹。这里
    是从ASP.Net以编程方式设置路径的步骤。


也是与#2相关的一些更复杂的解决方案,涉及以编程方式更新PATH。

There are also some more complex solutions related to #2 which involve programmatically updating the PATH.

这篇关于如何让IIS加载我的WCF服务引用的本机DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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