【问题标题】:Binding configuration in soap client service肥皂客户端服务中的绑定配置
【发布时间】:2021-11-16 19:00:26
【问题描述】:

我正在尝试在 VisualStudio 中制作一个肥皂客户端。 我所做的第一件事是使用交付的 WSDL 文件生成代理类(使用 VisualStudio 中的添加服务引用选项)。 它是使用错误的绑定配置生成的 - 消息安全性应为:
DefaultAsymmetricSignatureAlgorithm - "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" DefaultCanonicalizationAlgorithm - "http://www.w3.org/2001/10/xml-exc-c14n#"DefaultDigestAlgorithm - "http://www.w3.org/2001/04/xmlenc#sha256",

当它是: DefaultAsymmetricSignatureAlgorithm "http://www.w3.org/2000/09/xmldsig#rsa-sha1" DefaultCanonicalizationAlgorithm "http://www.w3.org/2001/10/xml-exc-c14n#"DefaultDigestAlgorithm "http://www.w3.org/2000/09/xmldsig#sha1".

我尝试通过添加以下内容来更改 App.conf 中的 basicHttpBinding 设置:

<security mode="Message">
            <message algorithmSuite="Basic256Sha256" clientCredentialType="Certificate"/>
</security>

和证书:

var cert = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "//cert.p12", "Pass");
client.ChannelFactory.Credentials.ClientCertificate.Certificate = cert;
client.ClientCredentials.ClientCertificate.Certificate = cert;

但我得到了例外:

没有为目标“http://.../service”提供服务证书。在 ClientCredentials 中指定服务证书。

但我认为我根本没有服务证书(服务属于另一家公司)。我尝试对 ClientCertificate 和 ServiceCertificate 使用相同的证书。

client.ClientCredentials.ServiceCertificate.DefaultCertificate = cert;

但我收到错误:所使用的证书具有无法验证的信任链。更换证书或更改 certificateValidationMode。

将模式更改为无会导致异常找不到安全性

一般来说,使用 SoupUI 发送请求可以正常工作,但我无法在客户端服务中进行正确配置以发送任何请求。

编辑1: 我尝试添加:

          <serviceBehaviors>
                <behavior name="mLegServiceSoapBehaviour">
                    <serviceCredentials>
                        <clientCertificate>
                            --><!--dont use on production--><!--
                            <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
                        </clientCertificate>
                    </serviceCredentials>
                </behavior>
            </serviceBehaviors>

但什么也没发生。我也试过了:

            <endpointBehaviors>
                <behavior name="endpointBehavior">
                    <clientCredentials>
                        <serviceCertificate>
                            <authentication certificateValidationMode="None" revocationMode="NoCheck"/>
                        </serviceCertificate>
                    </clientCredentials>
                </behavior>
            </endpointBehaviors>

但我遇到了另一个错误:

„外发消息的身份检查失败。远程端点的预期 DNS 身份是“nameA”,但远程端点提供了 DNS 声明“nameB”。如果这是一个合法的远程端点,您可以通过在创建通道代理时将 DNS 身份“nameB”明确指定为 EndpointAddress 的 Identity 属性来解决此问题。 ”

【问题讨论】:

    标签: visual-studio ssl wcf-binding wcf-security


    【解决方案1】:

    我想您使用自签名证书。WCF 将验证所有颁发者链,并期望最终链将以根受信任权限结束。您可以将以下行添加到 app.config 以禁用检查。但是,最好不要在生产环境中使用:serviceBehaviors/behavior/serviceCredentials/clientCertificate。

    <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck" />
    

    【讨论】:

    • 我不知道是不是我做错了什么,但是我添加了该行并没有发生任何事情。我得到了和以前一样的错误。我也尝试添加client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust; 之类的设置,但仍然无法正常工作。
    • 一个新的异常表明预期的远程端点与现有的不一致。请检查远程端点并重新运行它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多