【问题标题】:WCF Request throwing error when connecting with the certificate使用证书连接时 WCF 请求引发错误
【发布时间】:2021-03-26 22:44:02
【问题描述】:

我正在尝试连接到他们使用证书身份验证的第三方开发的 saop 服务。我有证书和 WSDL 文件。我通过添加证书在 Soap UI 和邮递员中测试了请求,那里一切正常。 现在我厌倦了使用 WCF 连接服务在 .net 核心中实现相同的功能。即使我从 StoreLocation 添加了证书,这次我也收到以下错误。

HL7SOAPEndPointSvcSoapClient hL7SOAPEndPointSvcSoapClient = new HL7SOAPEndPointSvcSoapClient(EndpointConfiguration.HL7SOAPEndPointSvcSoap, "endpointtoconnect");
            hL7SOAPEndPointSvcSoapClient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.Root, X509FindType.FindByIssuerName, "certificateiisuername");
            submitMessageRequest submitMessageRequest = new submitMessageRequest() { 
                Body = "meesege to sent"
            };
            hL7SOAPEndPointSvcSoapClient.OpenAsync();
            submitMessageResponse submitMessageResponse  = await hL7SOAPEndPointSvcSoapClient.submitMessageAsync(submitMessageRequest);

得到的错误是

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was "".

我不确定是什么导致了问题,因为相同的证书在 Soap UI 和邮递员中工作正常。

【问题讨论】:

  • 证书不存在。不知道为什么要在 Root 商店中搜索。证书应该在我的商店中。
  • @crypt32 我在 Root 中安装了证书。这就是为什么我从那里得到它。调试时,我可以使用快速监视在“ClientCredentials.ClientCertificate”属性中看到证书。
  • 当你在调试器中看到它有私钥?无论哪种方式,带有私钥的证书都应该安装在我的商店中。
  • 是的,当我使用调试器检查时,它有私钥。而且我也尝试过你提到的在我的商店中安装了证书但得到了同样的错误。

标签: wcf soap wcf-security x509certificate2


【解决方案1】:

我找到了问题的解决方案,我们需要添加如下绑定设置。一旦我添加了以下设置,它就开始工作了

            BasicHttpBinding b = new BasicHttpBinding();
            
            b.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
            b.Security.Transport.ClientCredentialType=HttpClientCredentialType.Certificate;

它可能会帮助其他人,谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-02
    • 1970-01-01
    • 2015-02-12
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多