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.Threading.Thread myThred = new System.Threading.Thread(mtThreadStart);
myThred.SetApartmentState(System.Threading.ApartmentState.STA);
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"];
cPortFrom = int.Parse(Request["FromConnectPort"] == null ? "4370" : Request["FromConnectPort"]);
gbMachineNumberFrom = int.Parse(Request["FromMachineNumber"] == null ? "10" : Request["FromMachineNumber"]);
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"];
cPortTo = int.Parse(Request["ToConnectPort"] == null ? "4370" : Request["ToConnectPort"]);
gbMachineNumberTo = int.Parse(Request["ToMachineNumber"] == null ? "10" : Request["ToMachineNumber"]);
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;
}
idResult.Text = 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();
}
}