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

C# 无法连接到远程WCF服务-SecurityNegotiationException,c#,wcf,C#,Wcf,我从一开始,我跟着。我设法在一台机器上运行Getting Started示例,并在不同的机器上部署客户机和服务并远程访问该服务 我的目标是实施该计划。我设法在一台机器上运行它,没有任何大问题。但是,当我在不同的计算机上部署客户机和服务时,我的客户机无法连接到该服务。我得到以下例外情况: System.ServiceModel.Security.SecurityNegotiationException was unhandled Message=The caller was not authe

我从一开始,我跟着。我设法在一台机器上运行Getting Started示例,并在不同的机器上部署客户机和服务并远程访问该服务

我的目标是实施该计划。我设法在一台机器上运行它,没有任何大问题。但是,当我在不同的计算机上部署客户机和服务时,我的客户机无法连接到该服务。我得到以下例外情况:

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>
<?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>

客户端-app.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>
<?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>

我一直在寻找解决办法,但什么都不管用。我试图找到一种在服务端禁用安全性/身份验证的方法(只是为了让它工作),但在这方面也没有成功

如何解决此问题?

默认情况下使用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>


您的配置中实际设置了吗?@ValtasarIII是,先生。:)只是上面代码中的一个小问题。wsDualHttpBinding不支持传输安全性。因此,如果我们在没有传输安全性的情况下使用这些配置,则上述配置是正确的。Rest很好,似乎正在为我工作。我已经尝试过了,但现在我收到了以下错误:“打开操作未在分配的超时00:00:59.7710000内完成。分配给此操作的时间可能是更长超时的一部分。”。请提出一些建议。