Search code examples
c#activexwcf-data-servicescredit-card

Dealing with activeX without form


I have been given a project in which I have to use activeX control without form.

That activex control belong to a Card swiper device. So what I have to do is, to create a rest service by which any browser client can access card's swiped data.

So I created a webservice method which creates a new sta thread as soon as request comes. In this sta thread I create ActiveXcontrol like given below and stores data in static class. Again for the second request I do the same.

try
{
    axOPOSMSR1 = new AxOposMSR_CCO.AxOPOSMSR();
    axOPOSMSR1.CreateControl();
    if (axOPOSMSR1.Open("IDTECH_SECUREMAG_USBHID") == 0)
    {
        axOPOSMSR1.ClaimDevice(100);
        axOPOSMSR1.DeviceEnabled = true;
        axOPOSMSR1.DataEventEnabled = true;
        axOPOSMSR1.DecodeData=true;
        axOPOSMSR1.ParseDecodeData = true;

        while (!Devicedisable && (axOPOSMSR1.Track1Data == ""))
        {
        }

        axOPOSMSR1.ClearInput();
        axOPOSMSR1.ReleaseDevice();
        axOPOSMSR1.Close();
        axOPOSMSR1.Dispose();
        axOPOSMSR1.ContainingControl = null;
        axOPOSMSR1 = null;
        GC.Collect();
    }

For the first time this program is doing well but as soon as I make another request (make another thread) nothing get stored in (static class) as data.

I make second request after first has been served.


Solution

  • What i have understand about your problem is:

    • You created a object of Swiper class with a new thread.
    • Now you are accessing Chipper data using a WCF service.

    I don't have such hardware device but would you please put

    Thread.sleep(10000); 
    

    after the while condition and tell me the output.