WCF サービスを作成しましたが、セキュリティ モードは に設定されてTransport
おり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>
UserName
理論的には、正しい Windows アカウント名とパスワードを入力する必要がありますが、テスト中にと をPassword
として設定できempty
、チャネルを作成できることがわかりました。なんで?
クライアントとサーバーは同じマシン上にありませんが、同じドメインにあります。クライアント マシンのログオン アカウントは、サーバー マシンにログインできます。この場合、空のユーザー名とパスワードを使用して接続を作成し、WCF サービスを呼び出すことができます。