我需要将库本机x86 C / C ++ * .dll连接到我的计算机本地托管的服务WCF C#4.0(IIS7.5)。我通过http请求调用服务方法(方法[WebGet])。我收到错误:
http://s1.ipicture.ru/uploads/20120509/H8TVURsE.jpg
用户代码未处理DllNotFoundException
无法加载DLL Li.dll:访问被拒绝(来自HRESULT的Exclussion:0x80070005(E_ACCESSDENIED))
在控制台应用程序C#中测试的库Li.dll的效率 - 成功运行。
Windows 7 x86 .NET 4.0 VS 2010 IIS7.5
结构解决方案服务WCF:
http://s1.ipicture.ru/uploads/20120430/vBXivN71.jpg
原生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;
}
}
强文
答案 0 :(得分:1)
您可能应该授予用户NETWORK SERVICE
访问dll文件的权限。