|
using GemCard.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GemCard.Service.Host
{
/// <summary>
/// Windows form to host the SCardService
/// If NET_TCP is defined, the service is using a NetTCPBinding,
/// otherwise it is using NamedPipeBinding
/// </summary>
public partial class MainForm : Form
{
const string
#if NET_TCP
NET_TCP_BASE_ADDRESS = "net.tcp://localhost:8001/",
#else
NET_NAMED_PIPE_BASE_ADDRESS = "net.pipe://localhost/",
#endif
SERVCICE_ADDRESS = "SCardService";
#if NET_TCP
private TCPServiceHostManager<IRemoteCard, RemoteCard>
#else
private NamedPipeServiceHostManager<IRemoteCard, RemoteCard>
#endif
scardService = null;
public MainForm()
{
InitializeComponent();
#if NET_TCP
scardService = new TCPServiceHostManager<IRemoteCard, RemoteCard>(NET_TCP_BASE_ADDRESS, SERVCICE_ADDRESS);
#else
scardService = new NamedPipeServiceHostManager<IRemoteCard, RemoteCard>(NET_NAMED_PIPE_BASE_ADDRESS, SERVCICE_ADDRESS);
#endif
scardService.Closed += ServiceHost_Closed;
scardService.Opened += ServiceHost_Opened;
btnStart.Enabled = true;
btnStop.Enabled = false;
}
void ServiceHost_Opened(object sender, EventArgs e)
{
listBoxStatus.Items.Add("Smart card service started and running...");
btnStop.Enabled = true;
btnStart.Enabled = false;
}
void ServiceHost_Closed(object sender, EventArgs e)
{
listBoxStatus.Items.Add("Smart card service stopped.");
btnStart.Enabled = true;
btnStop.Enabled = false;
}
protected override void OnClosed(EventArgs e)
{
if (scardService != null)
{
scardService.Closed -= ServiceHost_Closed;
scardService.Opened -= ServiceHost_Opened;
scardService.Dispose();
}
base.OnClosed(e);
}
private void btnStart_Click(object sender, EventArgs e)
{
try
{
scardService.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnStop_Click(object sender, EventArgs e)
{
try
{
scardService.Stop();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Software Architect, COM, .NET and Smartcard based security specialist.
I've been working in the software industry since I graduated in Electrical and Electronics Engineering. I chose software because I preferred digital to analog.
I started to program with 6802 machine code and evolved to the current .NET technologies... that was a long way.
For more than 20 years I have always worked in technical positions as I simply like to get my hands dirty and crack my brain when things don't go right!
After 12 years in the smart card industry I can claim a strong knowledge in security solutions based on those really small computers!
I've been back into business to design the licensing system for the enterprise solution for Consistel using a .NET smart card (yes they can run .NET CLR!)
I'm currently designing a micro-payment solution using the NXP DESFire EV1 with the ACSO6 SAM of ACS. I can then add a full proficient expertise on those systems and NFC payments.
This technology being under strict NDA by NXP I cannot publish any related article about it, however I can provide professional consulting for it.
You can contact me for professional matter by using the forum or via my
LinkedIn profile.