我可以使用 Win-form 应用程序连接到我的 WCF 服务,但是我无法使用我的 Windows 服务来连接。每当我向代理触发 open() 时,它都会引发以下错误
服务器已拒绝客户端凭据
内部异常:System.Security.Authentication.InvalidCredentialException:服务器已拒绝客户端凭据。
---> System.ComponentModel.Win32Exception:登录尝试失败
---内部异常堆栈跟踪结束---
在 System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResultlazyResult)
在 System.Net.Security.NegotiateStream.AuthenticateAsClient
System.Net.Security.NegotiateStream.AuthenticateAsClient (NetworkCredential credential, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel) 上的(NetworkCredential credential、ChannelBinding 绑定、String targetName、ProtectionLevel requiredProtectionLevel、TokenImpersonationLevel allowedImpersonationLevel)
在 System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(流流、SecurityMessageProperty 和 remoteSecurity)
尝试搜索解决方案,但不符合我的要求,因此发布。
请帮忙...
更新1:
@AR,尝试使用
client.ClientCredentials.Windows.AllowedImpersonationLevel =
System.Security.Principal.TokenImpersonationLevel.Impersonation;
但无济于事。
更新 2:
WCF 服务配置
<system.serviceModel>
<diagnostics performanceCounters="All" />
<bindings>
<netTcpBinding>
<binding name="myBindingForLargeData" maxReceivedMessageSize="5242880" maxConnections="10">
<readerQuotas maxDepth="64" maxStringContentLength="5242880" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="WCFService.ServiceBehavior"
name="WCFService.CollectorService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="myBindingForLargeData"
name="netTcpEndPoint" contract="WCFService.ICollectorService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="mexTcpEndPoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8010/WCFService.CollectorService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFService.ServiceBehavior">
<serviceMetadata httpGetEnabled="False"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceThrottling
maxConcurrentCalls="32"
maxConcurrentSessions="32"
maxConcurrentInstances="32"
/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>