繁体   English   中英

无法在IIS托管的其他WCF服务中加载第三方dll

[英]Not able to load the third party dll in IIS hosted rest WCF service

我已经为我的IIS 7托管了一个Rest WCF 我测试了一切,除了导入dll之外它工作正常。 我的实例类代码如下:

[OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getname?name={name}&age={age}", ResponseFormat = WebMessageFormat.Json)]
    bool getname(string name, string age);

[OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getcallfromdll?name={name}&age={age}", ResponseFormat = WebMessageFormat.Json)]
    bool getcallfromdll(string name, string age);

鉴于上述方法的定义是:

public string getname(string name, int len)
    {
        return "It's working";
    }
public string getcallfromdll(string name, int len)
    {
        return UnsafeNativeMethods.getvalue(name, len); //Unsafe.. is a internal structure
    }

internal static class UnsafeNativeMethods
    {
        const string _dllLocation = "school.dll";

        [DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool getvalue(string name, String len);
     }

当试图运行localhost:8085/service.svc/getname?name=kajn&len=21 :它返回"It's working" ,这是正确的,但每当我试图调用localhost:8085/service.svc/getcallfromdll?name=kajn&len=21 :它返回The server encountered an error processing the request. See server logs for more details. The server encountered an error processing the request. See server logs for more details.

我搜索它,不知怎的,我知道由于服务而发生的一切都不是很难找到DLL 为了解决这个问题,我试图将我的dll放在以下位置,但它没有帮助我:(:

  • SYSTEM32 / INETSRV
  • Syswow64资料/ INETSRV
  • 在bin文件夹中
  • 我也把项目所在的文件夹放在同一个文件夹中。

但没有什么对我有用。 请建议我一个解决方案。

注意:dll没有问题,因为我从自托管的WCF应用程序调用dll方法,并且它运行正常。 那时我把我的dll放到bin/debug文件夹中。

我猜这可能与IIS可能将二进制文件复制到阴影位置的事实有关,当它这样做时,它可能没有意识到可能需要非托管dll。 你的“school.dll”是你的WCF解决方案的一部分吗?它是作为参考添加的吗? 它还取决于任何其他非托管dll? 下次出现该错误时,您可以尝试搜索系统以查找WCF dll的所有实例,然后如果在阴影位置找到一个实例,请查看您的“school.dll”是否存在。

那么,你应该打开服务器上的WCF跟踪,看看实际的错误/异常是什么。 但我怀疑某种与权限相关的错误...即可以找到DLL,但IIS工作进程没有正确的权限来读取它或执行其中的方法。 仅出于调试目的,尝试在DLL上设置权限,以便“Everyone”可以读取/执行它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM