Calling an unmanaged DLL from a web service.


C

Chris Bardon

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?
 
Ad

Advertisements

D

Daryl Davis

This appears to be a simular issue to mine. Works great except when I call
it from a WebService.
Daryl Davis
 
J

Jeff Clausius

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



(e-mail address removed) (Chris Bardon) wrote in
 
Ad

Advertisements

R

Russ

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

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



(e-mail address removed) (Chris Bardon) wrote in
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?
 

Top