Reputation: 1
I need to connect the library native x86 C/C++ *.dll to the service WCF C# 4.0 hosted local in my computer(IIS7.5). I calling service method by http request (method [WebGet]). I get the error:
http://s1.ipicture.ru/uploads/20120509/H8TVURsE.jpg
DllNotFoundException was unhandled by user code
Can not load DLL Li.dll: Access denied (Exclussion from HRESULT: 0x80070005 (E_ACCESSDENIED))
The efficiency of the library Li.dll tested in a console application C # - working successfully.
Windows 7 x86 .NET 4.0 VS 2010 IIS7.5
Structure solutions service WCF:
http://s1.ipicture.ru/uploads/20120430/vBXivN71.jpg
native C/C++ x86 Li.dll:
Li.h
extern "C" {
__declspec(dllexport) int __cdecl SimulateGameDLL (int a, int b);
}
Li.cpp
#include "Li.h"
extern int __cdecl SimulateGameDLL (int num_games, int rand_in) {
return 121;
}
C#
WcfServiceLibrary1.IService1
[ServiceContract] public interface IService1{
[OperationContract][WebGet] string GetData();
}
WcfServiceLibrary1.Service1
public class Service1 : IService1{
public string GetData(){
ClassLibrary1.Class1 cl = new ClassLibrary1.Class1();
var rt = cl.M();
return string.Format("Value = : {0}", rt);
}
}
ClassLibrary1.Class1
public class Class1{
[DllImport("Li.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int SimulateGameDLL(int a, int b);
public int M() {
var r = SimulateGameDLL(10, 20);
return r;
}
}
strong text
Upvotes: 0
Views: 1155
Reputation: 2258
Might be you should grant access to user NETWORK SERVICE
to access the dll file.
Upvotes: 1