gpt4 book ai didi

c# - 无法连接到远程 WCF 服务 - SecurityNegotiationException

转载 作者:行者123 更新时间:2023-11-30 16:20:55 24 4
gpt4 key购买 nike

我从 WCF 开始,我正在关注 the samples from MSDN .我设法在一台机器上运行入门示例,并在不同的机器上部署客户端和服务并远程访问该服务。

我的目标是实现 Publish/Subscribe design pattern .我设法在一台机器上运行它,没有任何大问题。但是当我在不同的机器上部署客户端和服务时,我的客户端无法连接到该服务。我得到以下异常:

System.ServiceModel.Security.SecurityNegotiationException was unhandled
Message=The caller was not authenticated by the service.
Source=mscorlib

(如有必要,我可以分享堆栈跟踪。)

这是我的配置:

服务 - web.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="wsDualHttpBinding"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

客户端 - app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_ISampleContract" clientBaseAddress="http://<SERVICE MACHINE PUBLIC IP>:8000/myClient/"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default"/>
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://<SERVICE MACHINE PUBLIC IP>/ServiceModelSamples/service.svc"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_ISampleContract"
contract="ISampleContract" name="WSDualHttpBinding_ISampleContract">
<identity>
<servicePrincipalName value="host/<SERVICE MACHINE PUBLIC IP>" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>

我已经搜索了解决方案,但没有任何效果。我试图找到一种方法来禁用服务端的安全/身份验证(只是为了让它工作),但也没有成功。

我该如何解决这个问题?

最佳答案

wsDualHttpBinding默认情况下使用 Windows 身份验证。如果您暂时不需要此身份验证,您可以更改配置以将其关闭:

<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="wsHttpDual">
<security mode="None">
<transport clientCredentialType="None" protectionLevel="EncryptAndSign" />
<message clientCredentialType="None" algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="wsDualHttpBinding" bindingConfiguration="wsHttpDual"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

以同样的方式更改客户端配置中的安全部分:

      <security mode="None">
<transport clientCredentialType="None" protectionLevel="EncryptAndSign" />
<message clientCredentialType="None" algorithmSuite="Default" />
</security>

关于c# - 无法连接到远程 WCF 服务 - SecurityNegotiationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13823487/

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