在Wcf中使用ScardConnect函数(winscard.dll)

时间:2015-11-02 14:54:30

标签: c# wcf dll smartcard winscard

我正在尝试在我的WCF项目中使用winscard.dll的连接功能连接到智能卡。 Wcf服务,使用远程机器发布,该机器安装在Windows Server 8.1

ScardConnect函数返回值为6。

public int Connect()
                {
                    int returnCode = -2;
                    string[] tempStr = new string[3];

                    returnCode = ModWinsCard.SCardEstablishContext(ModWinsCard.SCARD_SCOPE_USER,
 0, 0, ref hContext);

                    if (returnCode == ModWinsCard.SCARD_S_SUCCESS)
                    {
                        returnCode = ModWinsCard.SCardConnect(hContext, "ACS ACR1281 1S Dual Reader PICC 0", ModWinsCard.SCARD_SHARE_SHARED, ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref pdwActiveProtocol);

                        if (returnCode == ModWinsCard.SCARD_S_SUCCESS)
                            return 1;
                        else
                            return returnCode;
                    }
                    else
                        return returnCode;
                }


  Interface (IService1)

[OperationContract的]         [FaultContract(typeof运算(服务1))]         int Connect(int hContext,string szReaderName,ref int phCard,ref int ActiveProtocol);

ScardConnect功能

[DllImport("winscard.dll")]
    public static extern int SCardConnect(int hContext, string szReaderName, int dwShareMode, int dwPrefProtocol, ref int phCard, ref int ActiveProtocol);

返回代码' 6'是什么意思。

注意:Wcf项目构建操作:x86 客户端项目构建操作:x86

1 个答案:

答案 0 :(得分:0)

检查“hContext”的值。读者姓名可能出错。所以我建议您先拨打SCardListReaders函数来获取确切的读者姓名。