Transport
我创建了一个 WCF 服务,并且安全模式已设置ClientCredentialType
为Windows
. 下面是我的客户端代码:
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
ChannelFactory<IServices> factory factory = new ChannelFactory<IServices>(binding, service);
NetworkCredential credential = factory.Credentials.Windows.ClientCredential;
credential.UserName = string.Empty;
credential.Password = string.Empty;
IServices connect = factory.CreateChannel();
bResult = connect.IsServerOnline();
服务器配置:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcpConSecure" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="TestService.Services">
<endpoint address="tcp" behaviorConfiguration="EndpointBe" binding="netTcpBinding" bindingConfiguration="tcpConSecure" contract="TestServiceInterface.IServices" />
</service>
</services>
</system.serviceModel>
理论上我应该输入正确的windows账号和密码,但是在测试过程中发现可以设置UserName
andPassword
为empty
,仍然可以创建频道。为什么?
客户端和服务器不在同一台机器上,但它们在同一个域中。客户端机器的登录帐户可以登录服务器机器。在这种情况下,我可以使用空的用户名和密码来创建连接并调用 WCF 服务。