使用客户端证书签名 XMLDsig、WS-Security 或 XADES 配置 WCF

Configure WCF with client certificate signing XMLDsig, WS-Security or XADES

使用VS2019,ASP.NET项目运行.net 4.0.

我创建了将服务引用添加到 wsdl 文件的 soap 客户端。现在我正在配置证书和调用方法。

这种方式在旧的 soap 服务器上有效,但现在 soap 服务器发生了变化。我使用相同的 Basic Auth 配置对 SoapUI 进行了测试并且工作完美,但不适用于我的 .Net 4.0 客户端...

Web.config

<system.serviceModel>
<bindings>
  <customBinding>
     <binding name="PLATAFORMA">
  <textMessageEncoding messageVersion="Soap11WSAddressing10" />
  <security 
    authenticationMode="MutualCertificateDuplex" 
    messageProtectionOrder="SignBeforeEncrypt"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
    <secureConversationBootstrap />
  </security>
      <httpsTransport />
    </binding>
  </customBinding>
</bindings> 
  <behaviors>
    <endpointBehaviors>
      <behavior name="CERT">
        <clientCredentials>
          <clientCertificate findValue="ClientCert" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
            <serviceCertificate>
              <defaultCertificate findValue="*.ServerCert.com" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
            </serviceCertificate>
          </clientCredentials>  
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <client>
    <endpoint
      address="endpointURI"
          binding="customBinding"
          bindingConfiguration="PLATAFORMA"
      behaviorConfiguration="CERT"
      contract="ServiceReference1.RequestPort1"
      name="Request.Request1">
      <identity>
        <dns value="*.ServerCert.com" />
      </identity>
    </endpoint>
  </client>
</system.serviceModel>

XML Outoing header(被拦截器捕获):

<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <a:Action s:mustUnderstand="1">peticionSincrona</a:Action>
    <a:MessageID>urn:uuid:e3a5c4bd-f159-48c1-8f3f-cf22da6b7e3b</a:MessageID>
    <ActivityId CorrelationId="035f2491-0772-4b1e-a286-9be30720d5ea" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">4d7f76c2-0486-4a81-93ad-32aecf02b035</ActivityId>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo9ph/BcvvnBFuLQYdch+LyYAAAAAHsOKxYeqzk+Do5pQmamNIPUdiXOiYjpBl1dsV5pp+SMACQAA</VsDebuggerCausalityData>
  </s:Header>

我知道需要一些信息,我如何指定签署为XMLDsig?为什么不是 soap/envelope/encoding?我需要帮助来配置 soap 客户端。

服务器 return 错误 500 与默认 tomcat 错误,甚至不是 soapenv:fault 或类似。我认为请求信封未正确生成。

编辑:必须结束 soap11

这是更改SOAP服务器后生成的客户端配置吗?如果需要Basic认证,为什么不用提供username/password,只需要提供客户端证书(根据绑定类型)? 我建议您通过添加服务引用重新生成客户端代理 class。这也会在 webconfig 文件中生成正确的配置。
此外,由于服务器发生变化,用于实现HTTPS安全的服务器证书也可能发生变化,因此我们在客户端提供的默认证书也应该发生变化。

<serviceCertificate>
              <defaultCertificate findValue="*.ServerCert.com" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
            </serviceCertificate>

相互证书认证需要客户端和服务器之间存在信任关系。

<security 
    authenticationMode="MutualCertificateDuplex"

我们不仅需要在新服务器上安装客户端证书以信任客户端,我们还需要在客户端安装服务器证书。 详情请
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security-with-a-certificate-client
如果有什么我可以帮忙的,请随时告诉我。