gpt4 book ai didi

c# - 对 SSPI 的调用失败,第二次运行调用时是否看到内部异常?

转载 作者:行者123 更新时间:2023-11-30 14:11:06 25 4
gpt4 key购买 nike

我有以下代码:

public GetUserDataResponse GetUserDataFromService(X509Certificate2 certificate)
{
ChannelFactory<MyApp4SITHSService.IMyApp4SITHSServiceContract> factory = new ChannelFactory<MyApp4SITHSService.IMyApp4SITHSServiceContract>("NetTcpBinding_IMyApp4SITHSServiceContract_Certificate");
MyApp4SITHSService.IMyApp4SITHSServiceContract service;
GetUserDataResponse response;

factory.Credentials.ClientCertificate.Certificate = certificate;
//factory.Credentials.UserName.UserName = "me";
//factory.Credentials.UserName.Password = "password";

service = factory.CreateChannel();

LogHandler.WriteLine("Connecting to service");
response = service.GetUserData(new GetUserDataRequest());
LogHandler.WriteLine("Data received");

factory.Abort();
return response;
}

我第一次运行它时效果很好,第二次我在 service.GetUserData 上得到以下异常:

A first chance exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in mscorlib.dll

A call to SSPI failed, see inner exception.

The Local Security Authority cannot be contacted

我使用以下配置:

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="CertificateEndpointBehavior">
<clientCredentials>
<!--<clientCertificate findValue="MyAppClient" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="TrustedPeople"/>-->
<!--<clientCertificate findValue="MyAppClient" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>-->
<serviceCertificate>
<authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpCertificate" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="Infinite" sendTimeout="01:00:00" transactionFlow="false"
transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="1000"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxConnections="200" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="Infinite"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
<message clientCredentialType="Certificate" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8135/MyApp4SITHSService/Client/sll"
behaviorConfiguration="CertificateEndpointBehavior" binding="netTcpBinding"
bindingConfiguration="netTcpCertificate" contract="MyApp4SITHSService.IMyApp4SITHSServiceContract"
name="NetTcpBinding_IMyApp4SITHSServiceContract_Certificate">
<identity>
<dns value="MyAppServer" />
</identity>
</endpoint>
</client>
</system.serviceModel>

知道我为什么会遇到这个问题以及如何解决它吗?

最佳答案

服务器没有权限联系本地机器证书存储来验证传入证书的信任

关于c# - 对 SSPI 的调用失败,第二次运行调用时是否看到内部异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21336378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com