简体   繁体   English

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

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

I have hosted a Rest WCF to my IIS 7 . 我已经为我的IIS 7托管了一个Rest WCF I tested the everything and it works fine except to importing the dll . 我测试了一切,除了导入dll之外它工作正常。 My instance class code are following: 我的实例类代码如下:

[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);

Whereas the definition of above methods are : 鉴于上述方法的定义是:

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);
     }

When tried to run localhost:8085/service.svc/getname?name=kajn&len=21 : it returns "It's working" , which is correct but whenever i tried to call localhost:8085/service.svc/getcallfromdll?name=kajn&len=21 : It returns The server encountered an error processing the request. See server logs for more details. 当试图运行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.

I searched for it and somehow i got to know that it all happening due to service are not bale to find the DLL . 我搜索它,不知怎的,我知道由于服务而发生的一切都不是很难找到DLL To solve this i tried to put my dll in following places but it didn't help me:( : 为了解决这个问题,我试图将我的dll放在以下位置,但它没有帮助我:(:

  • system32/inetsrv SYSTEM32 / INETSRV
  • SysWOW64/inetsrv Syswow64资料/ INETSRV
  • in bin folder 在bin文件夹中
  • i also put the same folder where the project exists. 我也把项目所在的文件夹放在同一个文件夹中。

But nothing works for me. 但没有什么对我有用。 Please suggest me a solution. 请建议我一个解决方案。

NOTE: there are no problem with the dll because i call the dll methods from a self hosted WCF application and it was working perfectly. 注意:dll没有问题,因为我从自托管的WCF应用程序调用dll方法,并且它运行正常。 At that time i put my dll into bin/debug folder. 那时我把我的dll放到bin/debug文件夹中。

I would guess that it could be related to the fact that IIS may copy binaries to shadow location and when it does that it may not realize the unmanaged dll may be required. 我猜这可能与IIS可能将二进制文件复制到阴影位置的事实有关,当它这样做时,它可能没有意识到可能需要非托管dll。 Is your "school.dll" part of your WCF solution and is it added as an reference? 你的“school.dll”是你的WCF解决方案的一部分吗?它是作为参考添加的吗? Also does it depend on any other unmanaged dlls? 它还取决于任何其他非托管dll? Next time you get that error you can try to search your system to find all instances of your WCF dll, then if you find one in shadow location, take a look if your "school.dll" is there too. 下次出现该错误时,您可以尝试搜索系统以查找WCF dll的所有实例,然后如果在阴影位置找到一个实例,请查看您的“school.dll”是否存在。

Well, you should turn on WCF Tracing on the server and see what the actual error/exception is. 那么,你应该打开服务器上的WCF跟踪,看看实际的错误/异常是什么。 But I would suspect some sort of permissions-related error... ie the DLL can be found, but the IIS worker process doesn't have the right permissions to read it or to execute methods in it. 但我怀疑某种与权限相关的错误...即可以找到DLL,但IIS工作进程没有正确的权限来读取它或执行其中的方法。 Just for debugging purposes, try setting the permission on the DLL such that it can be read/executed by "Everyone". 仅出于调试目的,尝试在DLL上设置权限,以便“Everyone”可以读取/执行它。

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

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