c# - 如何将 native C/C++ *.dll 连接到 IIS 中托管的 WCF C#?

标签 c# c++ wcf iis dll

我需要将 native x86 C/C++ *.dll 库连接到我的计算机 (IIS7.5) 中本地托管的服务 WCF C# 4.0。我通过 http 请求调用服务方法(方法 [WebGet])。我收到错误:

http://s1.ipicture.ru/uploads/20120509/H8TVURsE.jpg

DllNotFoundException 未被用户代码处理

无法加载 DLL Li.dll:访问被拒绝(从 HRESULT 中排除:0x80070005 (E_ACCESSDENIED))

您能告诉我可能是什么问题吗?


在控制台应用程序 C# 中测试的库 Li.dll 的效率 - 运行成功。

window 7 x86 .NET 4.0 对比 2010 IIS7.5

结构解决方案服务 WCF:

http://s1.ipicture.ru/uploads/20120430/vBXivN71.jpg

源代码

native C/C++ x86 Li.dll:

李.h

extern "C" {
    __declspec(dllexport) int __cdecl SimulateGameDLL (int a, int b); 
}

李.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);  
}
}

类库1.类1

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;
    }
}

强文本

最佳答案

您可能应该授予用户 NETWORK SERVICE 访问 dll 文件的权限。

关于c# - 如何将 native C/C++ *.dll 连接到 IIS 中托管的 WCF C#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10492094/

相关文章:

c# - 如何创建二维动态长度数组?

c++ - GDI+图像类问题

c++ - Win32 API : How to catch escape key in Edit control?

.net - WCF WebHttp 混合身份验证(基本和匿名)

c# - C# 中的自定义 Windows 控件库

c# - 如何在 C# 中传递列表对象中的值?

c# - 将一种类型转换为另一种类型

c++ - 错误 C2783 : '_Ty &&std::forward(remove_reference<_Ty>::type &&) throw()' : could not deduce template argument for '_Ty'

wcf - 客户端证书身份验证 WCF

wcf - 如何使用 silverlight 应用程序中的遗留业务逻辑?