【问题标题】:How to SetDefaultCertificate from the client to invoke Server web method in WCF如何从客户端 SetDefaultCertificate 调用 WCF 中的服务器 Web 方法
【发布时间】:2012-06-18 00:57:51
【问题描述】:

以下是我在服务器 web.config 文件中的配置设置,该文件是 WCF 应用程序。这里我使用 makecert.exe 创建 X509 证书。

<serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType= "WcfService1.CCustomValidatorClass,WcfService1"/> <serviceCertificate findValue="CN=SignedByCA1" x509FindType="FindBySubjectDistinguishedName" storeLocation="CurrentUser" storeName="My" /> </serviceCredentials>

"CN=SignedByCA1" 是私钥,现在,我想从客户端调用 WCF 服务上的 Web 方法。 但是我需要从客户端设置 SetDefaultCertificate,请您帮忙我如何获取访问私钥 X509 证书的密钥。

ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();

        obj.ClientCredentials.UserName.UserName = "Sukesh";
        obj.ClientCredentials.UserName.Password = "Sukesh";

        obj.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
             System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser, 
             System.Security.Cryptography.X509Certificates.StoreName.My,
             System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectDistinguishedName,
             "XYZ");

    string str = obj.GetData(1); // web method

请帮帮我...

错误:{“X.509 证书 CN=SignedByCA1 链构建失败。使用的证书具有无法验证的信任链。更换证书或更改 certificateValidationMode。吊销功能无法检查吊销证书。\r\n"}

谢谢, 苏克什。

【问题讨论】:

    标签: wcf


    【解决方案1】:

    由于自签名证书而出现错误。

    您可以使用 http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback(v=vs.100).aspx 忽略错误

    或者您可以将客户端证书安装到服务器的受信任根授权中(假设这只是为了开发)。

    当然,您也可以签署证书。

    【讨论】:

    • 如果您可以使用更多信息更新您的帖子,我可以提供更多详细信息。错误发生在服务器上?您可以发布您的网络配置的 system.servicemodel 部分吗?
    • 非常感谢您的回复,能否请您告诉我如何根据服务器私钥证书创建客户端证书。
    • 我可以粘贴服务器 web.config 文件,但无法使用添加评论按钮提交。
    • 它太大了,无法添加为评论,编辑您的开场问题并将其添加到那里。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多