简体   繁体   中英

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

I have hosted a Rest WCF to my IIS 7 . I tested the everything and it works fine except to importing the 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. 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 . To solve this i tried to put my dll in following places but it didn't help me:( :

  • system32/inetsrv
  • SysWOW64/inetsrv
  • in bin folder
  • 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. At that time i put my dll into bin/debug folder.

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. Is your "school.dll" part of your WCF solution and is it added as an reference? Also does it depend on any other unmanaged dlls? 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.

Well, you should turn on WCF Tracing on the server and see what the actual error/exception is. 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. Just for debugging purposes, try setting the permission on the DLL such that it can be read/executed by "Everyone".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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