特定计算机上的WCF身份验证问题

时间:2014-02-11 07:24:42

标签: windows wcf authentication

我的WCF服务/应用程序存在问题。我正在使用Windows身份验证的TCP绑定(动态设置凭据)。

该服务托管在机器A上。我的测试客户端应用程序在机器B,C,D和E上运行正常。当测试客户端应用程序在计算机A(自身)上运行时,它告诉我,如果实际上它们是正确的,我的凭据无效。

在机器B上托管服务时,机器B上的测试客户端本身认证正常。即使测试客户端在A上,它也会在B上成功验证自己。

我会说机器A有问题,但我无法弄清楚是什么。

任何帮助?

提前致谢。

ķ

客户端配置:

  

public static EndpointAddress BuildServiceEndpointAddress()   {

        var host = Settings.Default.Host;
        var port = Settings.Default.Port;

        string endpointAddress;
        if (port == 0)
            endpointAddress = string.Format("net.tcp://{0}/Service", host);
        else
            endpointAddress = string.Format("net.tcp://{0}:{1}/Service", host, port);

        Console.WriteLine("Endpoint: {0}", endpointAddress);

        //var endpointAddressObj = new EndpointAddress(endpointAddress );
        return new EndpointAddress(new Uri(endpointAddress), new DnsEndpointIdentity("MyCert"));
    }

    public static IChannelFactory<IService> BuildChannelFactory(EndpointAddress endpointAddress)
    {
        var netTcpBinding = new NetTcpBinding()
        {
            MaxReceivedMessageSize = int.MaxValue,
            Security = new NetTcpSecurity()
            {
                Mode = SecurityMode.Transport,
                Transport = new TcpTransportSecurity()
                {
                    ClientCredentialType = TcpClientCredentialType.Windows,
                }
            },
            TransferMode = TransferMode.Streamed 
        }; 

        var factory = new ChannelFactory<IService>(netTcpBinding);
        factory.Endpoint.Address = endpointAddress;

        factory.Credentials.Windows.ClientCredential.Domain = Settings.Default.Domain;
        factory.Credentials.Windows.ClientCredential.UserName = Settings.Default.Username;
        factory.Credentials.Windows.ClientCredential.Password = Settings.Default.Password;

        Console.WriteLine("Opening Channel Factory ... ");
        factory.Open();
        Console.WriteLine("Opening Channel Factory ... done");

        return factory;
    }

服务配置:

var netTcpBinding = new NetTcpBinding()
            {
                MaxReceivedMessageSize = int.MaxValue,
                Security = new NetTcpSecurity()
                {
                    Mode = SecurityMode.Transport,
                    Transport = new TcpTransportSecurity()
                    {
                        ClientCredentialType = TcpClientCredentialType.Windows,
                    }
                },
                TransferMode = TransferMode.Streamed
            };                

            var endpoint = serviceHost.AddServiceEndpoint(
                typeof(IService),
                netTcpBinding,
                new Uri(string.Format("net.tcp://0:{0}/Service", tcpPort)));

            ServiceSecurityAuditBehavior newAudit = new ServiceSecurityAuditBehavior();
            newAudit.AuditLogLocation = AuditLogLocation.Application;
            newAudit.MessageAuthenticationAuditLevel = AuditLevel.SuccessOrFailure;
            newAudit.ServiceAuthorizationAuditLevel = AuditLevel.SuccessOrFailure;
            newAudit.SuppressAuditFailure = false;


            serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                MetadataExchangeBindings.CreateMexTcpBinding(),
                string.Format("net.tcp://localhost:{0}/Service/mex", tcpPort));

            serviceHost.Description.Behaviors.Remove<ServiceSecurityAuditBehavior>();
            serviceHost.Description.Behaviors.Add(newAudit);

            serviceHost.Opening += (sender, eventArgs) => LogDebug("Opening Connection ...");
            serviceHost.Opened += (sender, eventArgs) => LogDebug("Opened Connection ...");

            serviceHost.Closing += (sender, eventArgs) => LogDebug("Closing connection ...");
            serviceHost.Closed += (sender, eventArgs) => LogDebug("Closed connection ...");

            serviceHost.Faulted += (sender, eventArgs) => LogError("Fault detected on WCF host");

1 个答案:

答案 0 :(得分:0)

我刚刚解决了这个问题!

我换了:

  

返回新的EndpointAddress(新的Uri(endpointAddress),new   DnsEndpointIdentity( “MyCert”));

  

返回新的EndpointAddress(new Uri(endpointAddress));

因为Windows身份验证不需要证书。

虽然我仍然感到困惑,为什么它在其他机器上工作。