Calling an unmanaged DLL from a web service.

Discussion in 'ASP .Net Web Services' started by Chris Bardon, Jun 14, 2004.

  1. Chris Bardon

    Chris Bardon Guest

    I have some code in an unmanaged DLL that I want to call from a web
    service. What I've done is use DLLIMPORT statements to create a
    wrapper class like so:

    public class Import
    {
    [DllImport("unmanaged.dll")] public static extern short Fn1(short
    s);
    }

    And called it like so:

    Import.Fn1(5);

    I've placed the unmanaged.dll file in the path, and have used this
    code in a local windows forms app with no problems. When I try to
    place this same code in a web service though, I get a
    System.DLLNotFoundException saying that it is unable to load the
    managed DLL. I've tried placing copies of the DLL in various
    locations (web service bin directory, wwwroot, etc) with no
    improvements.

    Thinking it might be a security problem, I tried running my windows
    forms app as a different user, and confirmed that both the anonymous
    web service user and the ASPNET account were able to run the program
    and find the DLL. Is there another configuration issue here that I'm
    missing? There should be no reason that I can't use this DLL in this
    way, correct?
     
    Chris Bardon, Jun 14, 2004
    #1
    1. Advertising

  2. Chris Bardon

    Daryl Davis Guest

    This appears to be a simular issue to mine. Works great except when I call
    it from a WebService.
    Daryl Davis
    "Chris Bardon" <> wrote in message
    news:...
    > I have some code in an unmanaged DLL that I want to call from a web
    > service. What I've done is use DLLIMPORT statements to create a
    > wrapper class like so:
    >
    > public class Import
    > {
    > [DllImport("unmanaged.dll")] public static extern short Fn1(short
    > s);
    > }
    >
    > And called it like so:
    >
    > Import.Fn1(5);
    >
    > I've placed the unmanaged.dll file in the path, and have used this
    > code in a local windows forms app with no problems. When I try to
    > place this same code in a web service though, I get a
    > System.DLLNotFoundException saying that it is unable to load the
    > managed DLL. I've tried placing copies of the DLL in various
    > locations (web service bin directory, wwwroot, etc) with no
    > improvements.
    >
    > Thinking it might be a security problem, I tried running my windows
    > forms app as a different user, and confirmed that both the anonymous
    > web service user and the ASPNET account were able to run the program
    > and find the DLL. Is there another configuration issue here that I'm
    > missing? There should be no reason that I can't use this DLL in this
    > way, correct?
     
    Daryl Davis, Jun 14, 2004
    #2
    1. Advertising

  3. Chris:

    Two suggestions from out of the blue.

    Have you tried using identity impersonation in web.config? Perhaps you
    could then use the %PATH% of the impersonated user for the dll location?

    OR

    This may or may not work. DLLImport states it takes a dll name in the
    constructor. Can the DLL name be a full path? I've never tried it
    before, but...

    As a test, place the dll in a known location (C:\unmanaged.dll).
    Does [DllImport("c:\unmanaged.dll")] work?

    Just some SWAGs.

    Jeff Clausius



    (Chris Bardon) wrote in
    news::

    > I have some code in an unmanaged DLL that I want to call from a web
    > service. What I've done is use DLLIMPORT statements to create a
    > wrapper class like so:
    >
    > public class Import
    > {
    > [DllImport("unmanaged.dll")] public static extern short Fn1(short
    > s);
    > }
    >
    > And called it like so:
    >
    > Import.Fn1(5);
    >
    > I've placed the unmanaged.dll file in the path, and have used this
    > code in a local windows forms app with no problems. When I try to
    > place this same code in a web service though, I get a
    > System.DLLNotFoundException saying that it is unable to load the
    > managed DLL. I've tried placing copies of the DLL in various
    > locations (web service bin directory, wwwroot, etc) with no
    > improvements.
    >
    > Thinking it might be a security problem, I tried running my windows
    > forms app as a different user, and confirmed that both the anonymous
    > web service user and the ASPNET account were able to run the program
    > and find the DLL. Is there another configuration issue here that I'm
    > missing? There should be no reason that I can't use this DLL in this
    > way, correct?
     
    Jeff Clausius, Jun 15, 2004
    #3
  4. Chris Bardon

    Russ Guest

    I think Jeff is on the right track here. I ran into the same thing.
    It seems that the Web Service will not look into it's own bin folder
    for the unmanaged dll. Why, I don't know. Anyway I 'solved' the
    problem by putting the unmanaged DLL in the %system32% directory.

    Of course the pain of that is well known...

    Good Luck, Russ

    On Tue, 15 Jun 2004 06:30:10 -0700, Jeff Clausius
    <> wrote:

    >Chris:
    >
    >Two suggestions from out of the blue.
    >
    >Have you tried using identity impersonation in web.config? Perhaps you
    >could then use the %PATH% of the impersonated user for the dll location?
    >
    > OR
    >
    >This may or may not work. DLLImport states it takes a dll name in the
    >constructor. Can the DLL name be a full path? I've never tried it
    >before, but...
    >
    >As a test, place the dll in a known location (C:\unmanaged.dll).
    >Does [DllImport("c:\unmanaged.dll")] work?
    >
    >Just some SWAGs.
    >
    >Jeff Clausius
    >
    >
    >
    > (Chris Bardon) wrote in
    >news::
    >
    >> I have some code in an unmanaged DLL that I want to call from a web
    >> service. What I've done is use DLLIMPORT statements to create a
    >> wrapper class like so:
    >>
    >> public class Import
    >> {
    >> [DllImport("unmanaged.dll")] public static extern short Fn1(short
    >> s);
    >> }
    >>
    >> And called it like so:
    >>
    >> Import.Fn1(5);
    >>
    >> I've placed the unmanaged.dll file in the path, and have used this
    >> code in a local windows forms app with no problems. When I try to
    >> place this same code in a web service though, I get a
    >> System.DLLNotFoundException saying that it is unable to load the
    >> managed DLL. I've tried placing copies of the DLL in various
    >> locations (web service bin directory, wwwroot, etc) with no
    >> improvements.
    >>
    >> Thinking it might be a security problem, I tried running my windows
    >> forms app as a different user, and confirmed that both the anonymous
    >> web service user and the ASPNET account were able to run the program
    >> and find the DLL. Is there another configuration issue here that I'm
    >> missing? There should be no reason that I can't use this DLL in this
    >> way, correct?
     
    Russ, Jul 2, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weston Fryatt
    Replies:
    2
    Views:
    1,035
    Weston Fryatt
    Jan 1, 2005
  2. David Taylor
    Replies:
    0
    Views:
    172
    David Taylor
    Oct 11, 2004
  3. Delf

    Web Service and unmanaged DLL using ADO

    Delf, May 10, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    250
    Lionel LASKE
    May 10, 2005
  4. David Palau

    Strategies for Web Service to Unmanaged DLL

    David Palau, Oct 20, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    168
    David Palau
    Oct 20, 2006
  5. P Chase

    .Net Web Service and unmanaged DLL

    P Chase, Mar 26, 2008, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    153
    P Chase
    Mar 26, 2008
Loading...

Share This Page