C# (WCF)服务未对调用方进行身份验证

C# (WCF)服务未对调用方进行身份验证,c#,authentication,wcf-ria-services,C#,Authentication,Wcf Ria Services,我已经创建了WCF服务+客户端,并将该服务部署到另一台电脑上。该服务正在运行。但当我通过VisualStudio在调试模式下执行客户机时,我得到了一个错误:调用方未通过服务的身份验证。 PC机、客户端和服务器都在同一个本地网络上 服务器端(服务) 客户端配置文件: <?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings&g

我已经创建了WCF服务+客户端,并将该服务部署到另一台电脑上。该服务正在运行。但当我通过VisualStudio在调试模式下执行客户机时,我得到了一个错误:调用方未通过服务的身份验证。 PC机、客户端和服务器都在同一个本地网络上

服务器端(服务)


客户端配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_ILabSat" 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"
            allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.228.65:8000/LabSat3/service" binding="wsHttpBinding"
          bindingConfiguration="WSHttpBinding_ILabSat" contract="ILabSat"
          name="WSHttpBinding_ILabSat">
        <identity>
          <servicePrincipalName value="host/MBO-NEW" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

我认为问题可能是由客户端凭据引起的。 据我所知,wsHttpBinding传输安全模式默认为Message,当我们将传输安全设置为Message时,客户端凭据类型默认为windows。因此,我们需要明确地提供可由服务器端进行身份验证的凭证

client.ClientCredentials.Windows.ClientCredential.UserName = "username";
   client.ClientCredentials.Windows.ClientCredential.Password = "password";
这是官方文件。

还可能需要识别服务器端,然后客户端需要手动指定endpointidentity。这取决于您的配置和托管环境。

client.ClientCredentials.Windows.ClientCredential.UserName = "username";
   client.ClientCredentials.Windows.ClientCredential.Password = "password";