Skip to main content
 首页 » 编程设计

c#之.net 客户端使用 X509 证书和用户名/密码身份验证调用 JAX-WS web 服务

2024年01月01日45insus

我在从 .net 客户端使用 JAX-WS Webservice 时遇到问题。 我能够打开与 WS 的连接,但是当我尝试使用任何方法时,我得到了这个错误:

我得到的第一个错误是:

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

我的 app.config 看起来像:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<system.serviceModel> 
        <customBinding> 
            <binding name="SrvPortBinding"> 
                <security defaultAlgorithmSuite="Basic128" authenticationMode="UserNameForCertificate" 
                    requireDerivedKeys="false" securityHeaderLayout="Strict" includeTimestamp="true" 
                    keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeEncrypt" 
                    messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10" 
                    requireSignatureConfirmation="false"> 
                    <localClientSettings cacheCookies="true" detectReplays="true" 
                        replayCacheSize="900000" maxClockSkew="00:05:00" maxCookieCachingTime="Infinite" 
                        replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00" 
                        sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true" 
                        timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" /> 
                    <localServiceSettings detectReplays="true" issuedCookieLifetime="10:00:00" 
                        maxStatefulNegotiations="128" replayCacheSize="900000" maxClockSkew="00:05:00" 
                        negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00" 
                        sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00" 
                        reconnectTransportOnFailure="true" maxPendingSessions="128" 
                        maxCachedCookies="1000" timestampValidityDuration="00:05:00" /> 
                    <secureConversationBootstrap /> 
                </security> 
                <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
                    messageVersion="Soap11WSAddressing10" writeEncoding="utf-8"> 
                    <readerQuotas maxDepth="32" maxStringContentLength="98192" maxArrayLength="916384" 
                        maxBytesPerRead="94096" maxNameTableCharCount="916384" /> 
                </textMessageEncoding> 
                <httpsTransport manualAddressing="false" maxBufferPoolSize="9524288" 
                    maxReceivedMessageSize="965536" allowCookies="false" authenticationScheme="Anonymous" 
                    bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard" 
                    keepAliveEnabled="true" maxBufferSize="965536" proxyAuthenticationScheme="Anonymous" 
                    realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" 
                    useDefaultWebProxy="true" requireClientCertificate="false" /> 
            </binding> 
        </customBinding> 
    </bindings> 
    <client> 
      <endpoint address="https://amms.someDomain.com:443/mmew1/Srv" 
          binding="customBinding" bindingConfiguration="SrvPortBinding" 
          contract="InfoMedica1.Srv" name="SrvPort" > 
 
      </endpoint>             
    </client> 
</system.serviceModel> 

`

然后我改变了这个:

<client> 
      <endpoint address="https://amms.someDomain.com:443/mmew1/Srv" 
          binding="customBinding" bindingConfiguration="SrvPortBinding" 
          contract="InfoMedica1.Srv" name="SrvPort" > 
 
      </endpoint>             
    </client> 

到:

<client> 
      <endpoint address="https://amms.someDomain.com:443/mmew1/Srv" 
          binding="customBinding" bindingConfiguration="SrvPortBinding" 
          contract="InfoMedica1.Srv" name="SrvPort" > 
        <identity> 
          <dns value="*.someDomain.com"/> 
        </identity> 
      </endpoint>             
    </client> 

现在我有异常(exception): 从另一方收到了不安全或不正确的错误。故障代码和详细信息请参见内部 FaultException。 内部异常:无效的安全 header

有没有人遇到这种错误并让它正常工作? 是否会因为 *.someDomain.com 中的此 * 字符而发生此错误?

我检查过服务器和客户端的时间是一样的。在添加此 X509 和用户名/密码身份验证之前,Web 服务正常工作。

如果需要任何进一步的信息,请在评论中询问:)

编辑:

当我尝试像那样禁用服务证书验证时:

<client> 
      <endpoint address="https://amms.someDomain.com:443/mmew1/Srv" 
          binding="customBinding" bindingConfiguration="SrvPortBinding" 
          contract="InfoMedica1.Srv" name="SrvPort" behaviorConfiguration="DisableServiceCertificateValidation"> 
        <identity> 
          <dns value="*.someDomain.com"/> 
        </identity> 
      </endpoint>             
    </client> 

异常发生:

There is no endpoint behavior named 'DisableServiceCertificateValidation' 

感谢提前:)

请您参考如下方法:

这是网络服务的问题。写它的人改变了一些不确定到底是什么但它开始工作:)

也许有人有类似的问题所以在这里 ;)

感谢所有感兴趣的人的帮助;)