用于32位dll访问的自托管WCF服务 [英] Self-Hosted WCF Service for 32 bit dll access

查看:99
本文介绍了用于32位dll访问的自托管WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows Forms应用程序的Visual Studio解决方案,其中有一些类库是我的应用程序模块。我的应用程序在 Any CPU下运行,并且不能更改为 x86,因为它使用了大量64位dll引用。



我有一个Native我需要在其中一个应用程序模块中使用C ++ 32位dll ,但这是完全不可能的,并且不想使用Wrappers,所以我读到,最简单的方法是使用自托管WCF服务。



我正在考虑的方法是创建一个控制台应用程序(32位)项目,该项目将引用我的解决方案中的Native C ++ 32位dll,并将托管该程序。 WCF服务,然后当用户打开应用程序模块时,我将调用 Process.Start(自托管的wcf控制台app.exe),以便启动我的WCF服务,然后从Windows窗体应用程序中启动访问方法等。然后我将能够使用本机32位dll方法。



我认为这被称为进程外应用程序。 / p>

有人认为有更好的方法吗?我真的不喜欢必须使用.EXE应用程序(主应用程序exe和自托管的wcf.exe),我可以将自托管的wcf 32位项目保存在我的主app.exe 64位项目中吗?



预先感谢

解决方案

我在我的项目中做到了,我们用_x64或_x86命名了这些项目,只需更改构建设置,就可以使两个项目处于同一解决方案中。我们将其命名为进程隔离。

请确保以下几点:




  • 父进程死后会发生什么

  • 子进程死亡时会发生什么情况

  • 父进程何时知道子进程还活着时-请开始使用wcf。

  • 您需要x86的调用是异步的吗?然后使用适当的异步模式



您可以从我的问题中获得以下答案:



验证子进程WCF服务已启动:



关闭托管进程:关闭托管进程的最佳方法



项目参考工作环境:项目参考工作环境.net 4.5和.net 3.5


I have a Visual Studio Solution for a Windows Forms application with some Class Libraries that are my Application Modules. My application run under "Any CPU" and can't be changed to "x86" because it uses lots of 64 bit dll references.

I have a Native C++ 32 bit dll that I need to use inside of one of the app modules but it's quite impossible and dont want to use Wrappers, so I have read that the easiest is to use a Self-Hosted WCF Service.

The approach that I was thinking is to create a Console Application (32 bit) project, that will be referencing the Native C++ 32 bit dll, within my solution and that will host the WCF Service, then when the user opens the app module, I will call a Process.Start(the self hosted wcf console app.exe) so my WCF service starts and then from my windows form application I can access the methods, etc.. and then I will be able to use the native 32 bit dll methods.

I think this is known as Out-of Process application.

Does anyone think there is a better way to do this? I really dont like to have to .EXE apps (the main app exe and the self hosted wcf.exe), can I have the self hosted wcf 32 bit project to live inside my main app.exe 64 bit project? if its possible, how can I call it?

Thanks in advance

解决方案

I did it in my project, we named the projects with _x64 or _x86, you can have both projects in same solution just change the build setting. we named it process isolation.
Make sure of the following:

  • what happens when parent process dies
  • what happens when child process dies
  • when does parent process knows child process is alive - start using the wcf..
  • you need the calls for x86 to be async ? then use the proper async pattern

you can get answers for these from my questions:

Verify Child Process WCF Service started: C# .net 3.5 inter process communication verify the child process has started ok

Close Hosted Process: best way to close hosted process

Project Reference Work-Around: Project reference work-around .net 4.5 and .net 3.5

这篇关于用于32位dll访问的自托管WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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