本文介绍了调用SSPI失败的GSSAPI操作失败,出现错误-提供的状态代码无效(SPNEGO找不到协商机制)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个ASP.NET Core WebApi应用程序,它将成为在Windows计算机上工作的WCF服务应用程序的客户端。这是我的服务客户端类:

public class VITServicesClient : ServicesClient, IDisposable
{

    static SpnEndpointIdentity spn = new SpnEndpointIdentity("BtaIntercardSPN");
    static EndpointIdentity endPointIdent = (spn as EndpointIdentity);
    static readonly NetTcpBinding binding;
    public static string Address { get; set; }


    private static AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
    private static AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);
    private static AddressHeader[] addressHeaders = new AddressHeader[2] { addressHeader1, addressHeader2 };

    static VITServicesClient()
    {
        binding = new NetTcpBinding(SecurityMode.Transport);
        binding.Name = "NetTcpBinding";
        TcpTransportSecurity transportSecurity = new TcpTransportSecurity();
        transportSecurity.SslProtocols = SslProtocols.Tls12;
        transportSecurity.ClientCredentialType = TcpClientCredentialType.Windows;
        binding.Security.Mode = SecurityMode.Transport;
        binding.Security.Transport = transportSecurity;
        binding.SendTimeout = new TimeSpan(0, 3, 0);
        binding.MaxReceivedMessageSize = 1024 * 1024 * 100; //100MB max message size
    }

    public VITServicesClient() : base (binding, new EndpointAddress(new Uri(Address+":31716/IServices"), endPointIdent, addressHeaders))
    {
    }


    public void Dispose()
    {
    }

}

这是执行WCF服务方法的Web控制器:

public async Task<string> GetDocumentByCountryCode(string countryCode)
    {
        try
        {
            VITServicesClient.Address = "net.tcp://10.64.4.61";
            using (var service = new VITServicesClient())
            {
                var result = await service.GetDocumentSamplesByCountryCodeAsync(countryCode.ToString(), 1);
                return (result as DocumentSamplesData[])[0].document_code;
            }
        }
        catch (Exception ex)
        {
            return "failed " + ex.Message + ex.InnerException.InnerException.Message;
        }

    }

当我在Windows下运行客户端应用程序时没有问题,但是当我在Ubuntu 16.04上部署应用程序并运行它,并且当它尝试连接到Windows计算机上的WCF服务时,我收到了该异常-对SSPI的调用失败,请参阅内部异常。GSSAPI操作失败并出现错误-提供了无效的状态代码(SPNEGO找不到协商机制)

我搜索了该问题,Windows中的Kerberos身份验证肯定有问题。问题是否出在我在代码中使用的配置中,或者Ubuntu中可能有必须更改的选项。

推荐答案

必须在Linux上安装gss-ntlmssp若要解决该问题,请使用以下命令

这篇关于调用SSPI失败的GSSAPI操作失败,出现错误-提供的状态代码无效(SPNEGO找不到协商机制)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 20:03