呼叫者未通过同一机器上的服务进行身份验证

时间:2019-04-24 23:52:07

标签: wcf iis

我在IIS的Windows 2016服务器上托管了WCF服务。我也有Windows应用程序来测试此WCF服务。如果我在承载WCF的服务器以外的任何计算机上运行此Windows应用程序,则服务工作正常。以下是我对WCF的配置。我无法弄清楚服务出了什么问题。

<system.serviceModel>
<services>
  <service behaviorConfiguration="TestBehavior" name="">
    <endpoint address="" binding="wsHttpBinding" contract="" bindingConfiguration="TestSecConfig">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="TestSecConfig">

    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="TestBehavior">

      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />

      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

我的问题与该问题中描述的完全相同,但是解决方案无效。 the caller was not authenticated by the service -- when using host name in site and call locally

1 个答案:

答案 0 :(得分:1)

默认情况下,Wshttpbinding安全模式的凭据是Windows凭据,以下配置是等效的。

<bindings>
  <wsHttpBinding>
    <binding name="TestSecConfig">
    </binding>
  </wsHttpBinding>
</bindings>

<wsHttpBinding>
            <binding>
              <security mode="Message">
                <message clientCredentialType="Windows"/>
              </security>
            </binding>
          </wsHttpBinding>
    </bindings>

因此,调用者在调用此服务时应指定Windows凭据。 Windows凭据是服务器Windows帐户(托管WCF服务的主机)。

ServiceReference2.Service1Client client = new ServiceReference2.Service1Client();
            client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
            client.ClientCredentials.Windows.ClientCredential.Password = "123456";

根据您的要求,您还可以指定 clientCredentialType =“ None”
https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.wshttpbinding.security?view=netframework-4.8
https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.wshttpsecurity.message?view=netframework-4.8#System_ServiceModel_WSHttpSecurity_Message
随时让我知道是否有什么可以帮助您的。