【问题标题】:WCF: Occasional rejection of client credentialsWCF:偶尔拒绝客户端凭据
【发布时间】:2020-11-16 12:25:11
【问题描述】:

我们目前正在将旧 WCF 应用程序的服务迁移到新域中的服务器。由于迁移,以下提到的错误时有发生。

发生异常...

异常详细信息:服务器已拒绝客户端凭据。

System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]:服务器已拒绝客户端凭据。 (Fault Detail等于An ExceptionDetail,可能由IncludeExceptionDetailInFaults=true创建,其值为:

System.ServiceModel.Security.SecurityNegotiationException:服务器已拒绝客户端凭据。

System.Security.Authentication.InvalidCredentialException:服务器已拒绝客户端凭据。

System.ComponentModel.Win32Exception:登录尝试失败 --- 内部 ExceptionDetail 堆栈跟踪结束 ---

在 System.Net.Security.NegoState.ProcessReceivedBlob(Byte[] message, LazyAsyncResultlazyResult)
在 System.Net.Security.NegoState.StartSendBlob(字节 [] 消息,LazyAsyncResultlazyResult)
在 System.Net.Security.NegoState.StartSendBlob(字节 [] 消息,LazyAsyncResultlazyResult)
在 System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResultlazyResult)
在 System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential credential, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
在...)。

困难的是,所有呼叫在 95% 的时间内都可以正常工作,而且呼叫突然失败并没有明显的原因。

配置和调用如下所示:

来电者:

<binding name="Binding_ServiceTCP" 
         closeTimeout="00:30:00" openTimeout="00:30:00" 
         receiveTimeout="infinite" sendTimeout="infinite" 
         transferMode="Buffered" maxBufferSize="2147483647" 
         maxReceivedMessageSize="2147483647">
   <security mode="Transport">
       <transport clientCredentialType="Windows" />
   </security>
   <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" 
                 maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"  
                 maxStringContentLength="2147483647" />
</binding>

<Channel ChannelType="IWcfInterface" Name="ServiceName" 
         Binding="Binding_ServiceTCP" Address="net.tcp://serverinnewdomain:59886/Service" Identity="" />
objectOfIWcfInterfaceImplementingClass.WcfCall();

收件人:

<service behaviorConfiguration="BehaviourName" name="ServiceName">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="Binding_ServiceTCP" contract="IWcfInterface" />
    <host>
        <baseAddresses>
            <add baseAddress="net.tcp://serverinnewdomain:59886/Service" />
        </baseAddresses>
    </host>
</service>
  
<behavior name="BehaviourName">
    <serviceMetadata httpGetEnabled="false" />
    <serviceDebug includeExceptionDetailInFaults="true" />
    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
  
<binding name="Binding_ServiceTCP" 
         closeTimeout="00:30:00" openTimeout="00:30:00" 
         receiveTimeout="infinite" sendTimeout="infinite" 
         transferMode="Buffered" maxBufferSize="2147483647" 
         maxReceivedMessageSize="2147483647">
    <security mode="Transport">
        <transport clientCredentialType="Windows" />
    </security>
    <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" 
                  maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" 
                  maxStringContentLength="2147483647" />
</binding>
[ServiceContract(Namespace = "http://some.cool/namespace")]
[XmlSerializerFormat]
public interface IWcfInterface
{
    [OperationContract]
    [XmlSerializerFormat(SupportFaults = true)]
    SomeClass WcfCall();
}

实现是通过城堡注册的。

container.Register(Component.For<IWcfInterface>().ImplementedBy<WcfClass>().LifeStyle.PerWcfOperation());

在旧服务器上安装 .NET 4.7,在新服务器上安装 4.8。

怀疑凭据在从呼叫者到接收者的途中丢失了,我联系了网络团队,但他们告诉我这是不可能的。

我想查看哪些凭据到达服务。如果这是不可能的,我也会对任何其他解决方案感到满意。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    这主要是由于 Windows 域不匹配,有两种解决方案:

    1. 将应用服务器和客户端放在同一个 Windows 域中。

    2. 如果机器在同一个域中,请验证用于运行服务的用户帐户是域帐户,而不是本地服务器帐户。

    注意,如果使用windows认证,客户端域和服务器必须在同一个windows域中。

    另一种解决方法是不使用windows认证:

    <bindings>
      <netTcpBinding>
        <binding name="TcpBinding">
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>
    

    【讨论】:

    • 安全模式="None" 为一个特定的渠道节省一天!谢谢一百万
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多