【问题标题】:use of ScardConnect function (winscard.dll) in Wcf在 Wcf 中使用 ScardConnect 函数 (winscard.dll)
【发布时间】:2015-11-02 14:54:29
【问题描述】:

我正在尝试在我的 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)

[操作合同] [FaultContract(typeof(Service1))] 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

【问题讨论】:

  • 你能分享更多的代码吗?
  • 好的,我编辑了。你能检查一下吗? @MichaelRoland
  • 好吧,这两个问题仍然问的完全一样。因此,关闭其中一个问题,否则就有被关闭为重复项的风险。

标签: c# wcf dll smartcard winscard


【解决方案1】:

检查“hContext”的值。阅读器名称可能有错误。所以我建议您先调用SCardListReaders 函数以获取确切的阅读器名称。

【讨论】:

  • 我在参数中使用读卡器名称,我可以从 SCardEstablishContext 函数中获取 hContext 的值。在桌面应用程序中,功能 (Connect) 为真。但如果在 WCF 项目中使用并在发布后返回“6”。有想法吗? @vikky
  • 好的。我正在编辑它。所有代码都在这里。只有我想使用winscard.dll 连接到带有WCF 的读卡器。如果我能看到,我可以完成项目的规划阶段。 @vikky
  • 您证明了堆栈溢出是比 MS 文档更好的文档。谢谢你好心的陌生人。
  • hContext 是关键,我没有存储和重用它。 (上下文句柄)6 在这里找到:docs.microsoft.com/en-us/windows/win32/debug/…(句柄不正确)
猜你喜欢
  • 1970-01-01
  • 2021-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 2023-03-27
  • 1970-01-01
相关资源
最近更新 更多