使用互操作库与生物识别设备连接但在ASP.Net中不起作用 [英] Interfacing with biometric device using interop library but it does not work in ASP.Net
问题描述
我从客户那里得到了这个要求,他们将多个生物识别设备放置在3-4个位置,有时同一个用户需要在这些不同的设备上打卡以获得访问控制或打卡要求。要求是跨设备同步用户信息和指纹模板。
供应商提供了互操作库,我用它来与设备接口
他们是
1. AxInterop.zkemkeeper.DLL
2. Interop.zkemkeeper.DLL。
但是当你从这些库中创建一个类时,它需要具有
1.给出错误,因为ctivex互操作程序集需要STAApartment,我使用线程给它STA公寓我从哪个方法调用方法(是不是在ASP.Net页面下创建线程,是否推荐)
2.它给出了以下错误可能是因为activex互操作库需要将自己嵌入到Windows Forms的某个容器中
$ / $
System.Windows.Forms.AxHost.InvalidActiveXStateException未处理< br />
消息=类型'System.Windows.Forms.AxHost + InvalidActiveXStateException异常'被抛出。< br />
来源= AxI nterop.zkemkeeper< br />
StackTrace:< br />
at Axzkemkeeper.AxCZKEM.Connect_Net(String iPAdd,Int32 port)< br />
at WebApplication1._Default.Connect (AxCZKEM activeXagent,String strConnect,String cIP,Int32 cPort)在E:\ Orwell \ WindstFormsApplication1 \ WebApplication1 \Default.aspx.cs:第101行< br />
....... .....................< br />
InnerException:< br />
我在这一点上陷入困境,因为如果我尝试将它嵌入到网络表单中,我就无法为这个库创建一个兼容的容器。
- -------------------------------------------------- ------------------------------------------------ <无线电通信/>
我有替代方案首先
1.创建一个将从ASP或ASP.Net调用的Web服务
2.在Windows服务下托管此Web服务,该服务将具有将执行这些互操作库调用的Windows窗体项目这是因为activex互操作库需要将自己嵌入到Windows Forms的某个容器中。
3. Web服务通过Windows服务将内部路由调用到此表单应用程序/类。
我有另外选择两个
1.在表之间保留一个所有需要的信息将从ASP或ASP.Net传递
2.创建一个独立的应用程序,轮询该表以获取设备调用并将在其中执行这些互操作库调用,这是因为activex互操作库需要将自身嵌入某些容器(Windows窗体)。
3.报告表格中的结果将由ASP / ASP.Net报告。
请告诉我您的通知同样如此。
代码贴在下面
----------- ----------------
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用Axzkemkeeper;
使用zkemkeeper;
使用System.Configuration;
名称空间WebApplication1
{
public partial class _Default:System.Web.UI.Page
{
string cIPFrom =192.168.2.101;
int cPortFrom = 4370;
int gbMachineNumberFrom = 10;
string gbEnrollNumberFrom =12345;
int gbFingerIndexFrom = 0;
string cIPTo =192.168.2.101;
int cPortTo = 4370;
int gbMachineNumberTo = 10;
string gbEnrollNumberTo =12345;
int gbFingerIndexTo = 0;
string gbTmpData =;
string strCommand =;
protected void Page_Load(object sender,EventArgs e)
{
System.Threading.ThreadStart mtThreadStart = new System.Threading.ThreadStart(CallMeThread);
//System.Action myAction = new Action(CallMeThread);
System.Threading.Thread myThred = new System.Threading.Thread(mtThreadStart);
//System.Threading.Thread(myAction);
//myThred.RunSynchronously();
myThred.SetApartmentState(System.Threading.ApartmentState.STA);
//myThred.Join();
myThred.Start();
}
private void CallMeThread()
{
AxCZKEM activeXagent = new AxCZKEM();
System.Windows.Forms.Form myForm = new System.Windows.Forms.Form();
myForm.Controls.Add(activeXagent);
string gbResult =;
cIPFrom =请求[FromConnectIP] == null? 192.168.2.101:请求[FromConnectIP]; // ConfigurationSettings.AppSettings [ConnectIP]。ToString();
cPortFrom = int.Parse(Request [FromConnectPort] == null?4370:Request [FromConnectPort]); // int.Parse(ConfigurationSettings.AppSettings [ConnectPort]);
gbMachineNumberFrom = int.Parse(Request [FromMachineNumber] == null?10:Request [FromMachineNumber]); // int.Parse(ConfigurationSettings.AppSettings [MachineNumber]);
gbEnrollNumberFrom =(Request [FromEnrollNumber] == null?12345:Request [FromEnrollNumber]);
gbFingerIndexFrom = int.Parse(Request [FromFingerIndex] == null?0:Request [FromFingerIndex]);
cIPTo =请求[ToConnectIP] == null? 192.168.2.101:请求[ToConnectIP]; // ConfigurationSettings.AppSettings [ConnectIP]。ToString();
cPortTo = int.Parse(Request [ToConnectPort] == null?4370:Request [ToConnectPort]); // int.Parse(ConfigurationSettings.AppSettings [ConnectPort]);
gbMachineNumberTo = int.Parse(Request [ToMachineNumber] == null?10:Request [ToMachineNumber]); // int.Parse(ConfigurationSettings.AppSettings [MachineNumber]);
gbEnrollNumberTo =(Request [ToEnrollNumber] == null?12345:Request [ToEnrollNumber]);
gbFingerIndexTo = int.Parse(Request [ToFingerIndex] == null?0:Request [ToFingerIndex]);
gbTmpData = Request [TmpData];
strCommand =请求[DeviceCommand] ==? GetThumbnail:请求[DeviceCommand];
switch(strCommand)
{
caseGetThumbnail:
Connect(activeXagent,Connect,cIPFrom,cPortFrom);
gbTmpData = GetThumbNail(activeXagent,gbMachineNumberFrom,gbEnrollNumberFrom,gbFingerIndexFrom);
gbResult =从设备中检索缩略图..+ gbEnrollNumberFrom;
Connect(activeXagent,DisConnect,cIPFrom,cPortFrom);
休息;
// caseDelThumbnail:
// Connect(Connect,cIPFrom,cPortFrom);
// DelThumbnail(gbMachineNumberFrom,gbEnrollNumberFrom,gbFingerIndexFrom);
// gbResult =从设备删除缩略图..用于+ gbEnrollNumberFrom;
// Connect(DisConnect,cIPFrom,cPortFrom);
//休息;
// caseSetThumbnail:
// Connect(Connect,cIPFrom,cPortFrom);
// SetThumbnail(gbMachineNumberTo,gbEnrollNumberTo,gbFingerIndexTo);
// gbResult =Thumbnail在设备上更新..用于+ gbEnrollNumberFrom;
// Connect(DisConnect,cIPFrom,cPortFrom);
//休息;
// caseGetAndSetThumbnail:
// Connect(Connect,cIPFrom,cPortFrom);
// gbTmpData = GetThumbNail(gbMachineNumberFrom,gbEnrollNumberFrom,gbFingerIndexFrom);
// Connect(DisConnect,cIPFrom,cPortFrom);
//连接(连接,cIPTo,cPortTo);
// SetThumbnail(gbMachineNumberTo,gbEnrollNumberTo,gbFingerIndexTo,gbTmpData);
//连接(DisConnect,cIPTo,cPortTo);
// gbResult =从DeviceIP更新的缩略图+ cIPFrom +To Device+ cIPTo +.. For+ gbEnrollNumberFrom;
//休息;
}
idResult.Text = gbResult;
//Response.Write gbResult;
}
private void Connect(AxCZKEM activeXagent,string strConnect,string cIP,int cPort)
{
bool boolResult = true;
if(strConnect ==Connect)
{
boolResult = activeXagent.Connect_Net(cIP,cPort);
if(boolResult)
{
}
}
else
{
activeXagent.Disconnect();
}
}
您确实意识到ASP.NET代码完全在Web服务器上运行,正确?
您的所有生物识别设备都将直接连接到网络服务器吗?
这个听起来好像你不应该写一个用这些设备做认证的网站。
我有同样的问题 as you.Finally I Solved It。
就在你的ThreadMethod的最后一个添加 Application.Run();它将会好。
请参阅:
< a href = http://www.codeproject.com / Questions / 711973 /使用-Zkemkeeper-dll-from-SDK-for-Biometric-scanne>使用Zkemkeeper dll 来自 SDK 用于生物识别扫描程序在 Windows服务< / a > [< a href = < span class =code-string> http://www.codeproject.com/Questions/711973/Using-Zkemkeeper-dll-from-SDK-for-Biometric-scanne target = _ blank title = 新窗口> ^ < / a > 跨度>
间op.zkemkeeper.dllregsvr32 error 或 InitializeComponent
然后 你 需要 已完成 step 以下内容:
1 。 Go to webiste: http: // www.zktechnology.com
2 。 下载 - >软件下载 - > ZK 访问 for C3 panel
3 < /跨度>。 提取 文件
4 。 安装
5 。 打开 visual studio - > 解决方案项目 - >参考 - > 添加 Interop 。 zkemkeeper 。 dll
好 运气
如果 已成功 则 你 访问 网站 me http: // phuphat.com或http://thoigianso.com以直接hihi
Hi,
I have this requirement in short from customer they have multiple biometric devices placed in 3-4 locations and sometime same user need to punchin on these different devices for access control or punchin requirements. Requirement is to synchronize user information and finger print template across devices.
Vendor has provided interop libraries which I am using to interface with device
they are
1. AxInterop.zkemkeeper.DLL
2. Interop.zkemkeeper.DLL.
But when you are creting a class from these libraries it demands to have
1. Gives error as ctivex interop assembly requires STAApartment which I did using thread giving it STA apartment from which I am calling method (Is it right to create thread under ASP.Net page, is it recommended)
2. It gives below error may be because activex interop library requires to embed itself under some container which is Windows Forms
System.Windows.Forms.AxHost.InvalidActiveXStateException was unhandled<br /> Message=Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.<br /> Source=AxInterop.zkemkeeper<br /> StackTrace:<br /> at Axzkemkeeper.AxCZKEM.Connect_Net(String iPAdd, Int32 port)<br /> at WebApplication1._Default.Connect(AxCZKEM activeXagent, String strConnect, String cIP, Int32 cPort) in E:\Orwell\WindowsFormsApplication1\WebApplication1\Default.aspx.cs:line 101<br /> ............................<br /> InnerException: <br />
I m stuck at this point as I can not create a compatible container for this library if I try to embed it in web form it does not work.
---------------------------------------------------------------------------------------------------
I do have as an alternative First
1. Creating a web service which will be called from ASP or ASP.Net
2. Hosting this web service under a Windows service which will have windows forms project which will have these interop library calls executed this is because activex interop library requires to embed itself under some container which is Windows Forms.
3. Web service internally routing calls through windows service to this forms application/class.
I do have as an alternative Two
1. Keeping one in between table in which all needed information will be passed from ASP or ASP.Net
2. Creating a standalone application which poll this table to get the device calls to be made and will have these interop library calls executed within it this is because activex interop library requires to embed itself under some container which is Windows Forms.
3. Reporting back the outcome in table which will be taken by ASP/ASP.Net.
Do let me know your throughts on same as well.
Code pasted below
---------------------------
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Axzkemkeeper; using zkemkeeper; using System.Configuration; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { string cIPFrom = "192.168.2.101"; int cPortFrom = 4370; int gbMachineNumberFrom = 10; string gbEnrollNumberFrom = "12345"; int gbFingerIndexFrom = 0; string cIPTo = "192.168.2.101"; int cPortTo = 4370; int gbMachineNumberTo = 10; string gbEnrollNumberTo = "12345"; int gbFingerIndexTo = 0; string gbTmpData = ""; string strCommand = ""; protected void Page_Load(object sender, EventArgs e) { System.Threading.ThreadStart mtThreadStart = new System.Threading.ThreadStart(CallMeThread); //System.Action myAction = new Action(CallMeThread); System.Threading.Thread myThred = new System.Threading.Thread(mtThreadStart); //System.Threading.Thread(myAction); //myThred.RunSynchronously(); myThred.SetApartmentState(System.Threading.ApartmentState.STA); //myThred.Join(); myThred.Start(); } private void CallMeThread() { AxCZKEM activeXagent = new AxCZKEM(); System.Windows.Forms.Form myForm = new System.Windows.Forms.Form(); myForm.Controls.Add(activeXagent); string gbResult = ""; cIPFrom = Request["FromConnectIP"] == null ? "192.168.2.101" : Request["FromConnectIP"]; // ConfigurationSettings.AppSettings["ConnectIP"].ToString(); cPortFrom = int.Parse(Request["FromConnectPort"] == null ? "4370" : Request["FromConnectPort"]); // int.Parse(ConfigurationSettings.AppSettings["ConnectPort"]); gbMachineNumberFrom = int.Parse(Request["FromMachineNumber"] == null ? "10" : Request["FromMachineNumber"]);//int.Parse(ConfigurationSettings.AppSettings["MachineNumber"]); gbEnrollNumberFrom = (Request["FromEnrollNumber"] == null ? "12345" : Request["FromEnrollNumber"]); gbFingerIndexFrom = int.Parse(Request["FromFingerIndex"] == null ? "0" : Request["FromFingerIndex"]); cIPTo = Request["ToConnectIP"] == null ? "192.168.2.101" : Request["ToConnectIP"]; // ConfigurationSettings.AppSettings["ConnectIP"].ToString(); cPortTo = int.Parse(Request["ToConnectPort"] == null ? "4370" : Request["ToConnectPort"]); // int.Parse(ConfigurationSettings.AppSettings["ConnectPort"]); gbMachineNumberTo = int.Parse(Request["ToMachineNumber"] == null ? "10" : Request["ToMachineNumber"]);//int.Parse(ConfigurationSettings.AppSettings["MachineNumber"]); gbEnrollNumberTo = (Request["ToEnrollNumber"] == null ? "12345" : Request["ToEnrollNumber"]); gbFingerIndexTo = int.Parse(Request["ToFingerIndex"] == null ? "0" : Request["ToFingerIndex"]); gbTmpData = Request["TmpData"]; strCommand = Request["DeviceCommand"] == "" ? "GetThumbnail" : Request["DeviceCommand"]; switch (strCommand) { case "GetThumbnail": Connect(activeXagent, "Connect", cIPFrom, cPortFrom); gbTmpData = GetThumbNail(activeXagent, gbMachineNumberFrom, gbEnrollNumberFrom, gbFingerIndexFrom); gbResult = "Thumbnail Retrieved From Device.." + gbEnrollNumberFrom; Connect(activeXagent, "DisConnect", cIPFrom, cPortFrom); break; //case "DelThumbnail": // Connect("Connect",cIPFrom,cPortFrom); // DelThumbnail(gbMachineNumberFrom, gbEnrollNumberFrom, gbFingerIndexFrom); // gbResult = "Thumbnail Deleted From Device.. For" + gbEnrollNumberFrom; // Connect("DisConnect",cIPFrom,cPortFrom); // break; //case "SetThumbnail": // Connect("Connect",cIPFrom,cPortFrom); // SetThumbnail(gbMachineNumberTo, gbEnrollNumberTo, gbFingerIndexTo); // gbResult = "Thumbnail Updated On Device.. For" + gbEnrollNumberFrom; // Connect("DisConnect",cIPFrom,cPortFrom); // break; //case "GetAndSetThumbnail": // Connect("Connect",cIPFrom,cPortFrom); // gbTmpData = GetThumbNail(gbMachineNumberFrom, gbEnrollNumberFrom, gbFingerIndexFrom); // Connect("DisConnect",cIPFrom,cPortFrom); // Connect("Connect",cIPTo,cPortTo); // SetThumbnail(gbMachineNumberTo, gbEnrollNumberTo, gbFingerIndexTo, gbTmpData); // Connect("DisConnect",cIPTo,cPortTo); // gbResult = "Thumbnail Updated From DeviceIP" + cIPFrom + " To Device" + cIPTo + " .. For" + gbEnrollNumberFrom; // break; } idResult.Text = gbResult; //Response.Write gbResult; } private void Connect(AxCZKEM activeXagent, string strConnect, string cIP, int cPort) { bool boolResult = true; if (strConnect == "Connect") { boolResult = activeXagent.Connect_Net(cIP, cPort); if (boolResult) { } } else { activeXagent.Disconnect(); } }
You do realize that ASP.NET code runs entirely on the web server, correct?
Are all of your biometric devices going to be attached directly to the web server?
This sounds as though you should NOT be writing a web site that does the authentication stuff with these devices.
I have the same problem as you.Finally I Solved It. Just at the last of your ThreadMethod Add "Application.Run();" It will OK. please see: <a href="http://www.codeproject.com/Questions/711973/Using-Zkemkeeper-dll-from-SDK-for-Biometric-scanne">Using Zkemkeeper dll from SDK for Biometric scanner in Windows Service</a>[<a href="http://www.codeproject.com/Questions/711973/Using-Zkemkeeper-dll-from-SDK-for-Biometric-scanne" target="_blank" title="New Window">^</a>]
Interop.zkemkeeper.dllregsvr32 error or InitializeComponent Then you need done the step following: 1. Go to webiste: http://www.zktechnology.com 2. Download ->Software Download->ZK Access for C3 panels 3. Extract files 4. Install 5. Open visual studio -> Solution Project->references-> Add Interop.zkemkeeper.dll Good luck If successfully then you visit website of me http://phuphat.com or http://thoigianso.com to hepl direct hihi
这篇关于使用互操作库与生物识别设备连接但在ASP.Net中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!