1

I am trying Connecting to smartcard with using connect function of winscard.dll in my WCF project. Wcf service, is publishing with remote machine which machine is installed on windows server 8.1

ScardConnect function is returning value of 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(Service1))] int Connect(int hContext, string szReaderName, ref int phCard, ref int ActiveProtocol);

ScardConnect function

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

What does it mean return code '6'.

Note: Wcf project build action : x86 Client project build action: x86

TheDebugger
  • 149
  • 2
  • 9

1 Answers1

2

Check the value of "hContext". Possible error in name of reader.So I would suggest you first call SCardListReaders function to get the exact reader name.

jiten
  • 5,128
  • 4
  • 44
  • 73
  • I am using reader name in parameter and I can take value of hContext from SCardEstablishContext function. In desktop application the function (Connect) is runnign true. But if using in WCF project and after publishing it returns '6'. have an idea ? @vikky – TheDebugger Nov 03 '15 at 08:54
  • Ok. I am edited it. All of codes in here. Only I want to connect to card reader with WCF using to winscard.dll. if I can see, I can complete to planning phase of my project. @vikky – TheDebugger Nov 03 '15 at 11:28
  • You proved that stack overflow is a better documentation than MS docs. Thank you kind stranger. – Aykhan Hagverdili Jul 30 '20 at 15:04
  • The hContext was key, I didnøt store and reuse it. (context handle) The 6 is found here: https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- (handle not correct) – kfn Aug 23 '21 at 10:37