在wcf服务中引用c ++库 [英] Reference c++ library in wcf service

查看:124
本文介绍了在wcf服务中引用c ++库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这个很长时间,但还没有看到答案。

I been searching this for a long time but haven't seen an answer.

我在wcf服务库中引用了两个dll,这是一个C ++库API,它在从wcftestclient调用wrapped方法时工作得很好。但是当自己托管的库在一个websericice它说找不到程序集xxx.dll(它的一个c ++ API dll)或其依赖之一。但我可以看到它说缺少的dll被自动复制到主机webserive项目的bin / debug文件夹。另外,我可以在一个简单的控制台项目中托管库,其中调用wrapper方法没有问题。

I'm referencing two dlls, which are a C++ library API for .NET, in a wcf service library, it works fine when invoking the wrapped method from wcftestclient. But when self hosting the library in a websercice it says"can't find assembly xxx.dll (it's one of the c++ API dll) or one of its dependency". But I can see the dll it says missing is auto copied to the bin/debug folder for the host webserive project. Also, I can host the library in a simple console project in which calling the wrapper method has no problem at all.

我希望这是一个简单的配置设置,我缺少指定在Web配置文件,任何人有任何建议?谢谢。

I hope this is a simple config setting that i'm missing to specify in the web config file, anyone has any suggestion? Thanks.

推荐答案

我花了差不多三天时间解决这个问题,现在解决了。如果这可以帮助别人在这里可能有相同的情况是为什么。
两个c ++库.net api dll是后期绑定,所以它在运行时之前不会查找它的依赖。我甚至试图在GAC中注册整个外部库包,它没有帮助;这是因为两个.net api dll中的一个是一个弱集合,因此CLR甚至不会在GAC中寻找它。我做的是为服务创建一个静态构造函数,并在静态构造函数中加载后期绑定程序集到AppDomain。我使用 Assembly.LoadFrom(string filePath)方法(其他方法是可用的Assembly类来做到这一点)。现在我可以在IIS上托管服务,并在任何客户端中使用它。所以如果clr抱怨它找不到一个程序集,但你可以看到它在bin / debug文件夹,它可能是一个后期绑定程序集,需要预先加载到AppDomain; AppDomain的好处是你只需要加载一次装配,它不会卸载单个装配。

I spent almost three days on this problem and now it's resolved. In case this can help someone else who might have the same situation here is why. The two c++ library .net api dlls are late binding so it won't look for its dependency until runtime. I even tried to registry the whole external library package in GAC and it didn't help; this was because one of two .net api dlls is a weak assembly hence CLR won't even bother looking for it in GAC. What I did was create a static constructor for the service and within the static constructor load the late binding assembly into AppDomain. I am using Assembly.LoadFrom(string filePath) method (other methods are available on Assembly class to do this). Now I can host the service on IIS and consume it in any client. So if clr is complaining it can't find an assembly but you can see it in the bin/debug folder, it's probably a late bind assembly which needs to be pre-loaded into the AppDomain; the good thing about AppDomain is you only need to load the assembly once and it will never unload an individual assembly.

这篇关于在wcf服务中引用c ++库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆