我使用需要启动的PC的外部硬件(耗时)。我已经被要求通过编写一些可以启动硬件的软件来加快速度,然后让客户端获得对硬件的引用。目前,他们每次重启软件时都必须重启硬件。
我们使用的所有硬件都是第三方并使用c#编写,因此我无法修改硬件类别。
由于这一切都需要在同一台PC上运行,因此可以使用Windows服务来托管某些软件,这些软件可以实例化硬件类,启动硬件然后根据请求返回引用。
尝试1 是Windows服务中托管的WCF客户端。这最初工作,直到我意识到WCF是一个基于消息的系统,并且不允许访问返回对象的方法...只有数据。我终于意识到我试图让WCF做一些它不打算做的事。我也无法将DataContract属性添加到第三方dll类。
尝试2 正在使用Windows服务中托管的.NET Remoting。这最初起作用,直到我意识到我无法将[Serializable]属性添加到第三方类。我可以继承一个类并添加MarshalByRefObject,但这只能让我远程调用该对象,这对我们来说太慢了。
我试图强制WCF使用共享程序集并尝试在运行时添加属性,但两种想法都不会飞。
我的下一次尝试是使用COM,但我认为这真的很难......我想我会咨询SO社区,看看我是否只是错过了什么。
这里要说明的是我希望在服务中实例化的第三方类的示例,并将副本返回给客户端。
public class afDigitizer : IDigitizerHandle, IDisposable
{
public afDigitizerCalibrate Calibrate;
public afDigitizerCapture Capture;
public afDigitizerEventOnError EventOnError;
public afDigitizerEventOnWarning EventOnWarning;
public afDigitizerListMode ListMode;
public afDigitizerLO LO;
public afDigitizerLVDS LVDS;
public afDigitizerModulation Modulation;
public afDigitizerRF RF;
public afDigitizerTimer Timer;
public afDigitizerTrigger Trigger;
public afDigitizer();
public afDigitizer(string installDir);
~afDigitizer();
public int BootInstrument(string LoResource, string RfResource, int LoIsPlugin);}
// and the code to instantiate the object and boot it.
private afDigitizer vsa = new afDigitizer();
errorCode = vsa.BootInstrument(this.LO, this.RF,-1);
// Now i want to return the vsa object.