【问题标题】:Unable to do basic authentification with WCF无法使用 WCF 进行基本身份验证
【发布时间】:2018-02-13 15:03:54
【问题描述】:

我正在尝试创建一个具有基本身份验证的 Web 服务 WCF,followinf this tutorial

但是当我想通过在我的 C# 应用程序中添加服务引用来测试它时,我有一个错误(法语抱歉):

System.NotSupportedException: Les schémas d'authentification configurés sur l'hôte ('Anonymous') n'autorisent pas ceux configurés sur la liaison 'BasicHttpBinding'('基本')。保证 价值 de SecurityMode est Transport 或 TransportCredentialOnly。恩 Outre, ceci peut être résolu en modifiant les schémas d'authentification de cette application par le biais de l'outil de gestion IIS, la propriété ServiceHost.Authentication.AuthenticationSchemes, dans le fichier de 应用配置,au niveau de l'élément , en mettant à jour la propriété ClientCredentialType de la liaison ou en ajustant la propriété AuthenticationScheme de l'élément HttpTransportBindingElement。

它表示“匿名”和“基本”方案之间存在问题。但我不知道它是什么。

这是我的代码:

namespace WcfWebHttpIISHostingSample
{
    [ServiceContract]
    interface ITestService
    {
        [OperationContract]
        string GetData(string data);
    }
    public class ServiceTest : ITestService
    {
        public string GetData(string data)
        {
            return "OK";
        }
    }
}

Web.config:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="UsernameWithTransportCredentialOnly">
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Basic"/>
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>

  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceWithMetaData">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <services>
    <service name="WcfWebHttpIISHostingSample.ServiceTest" behaviorConfiguration="ServiceWithMetaData">
      <endpoint
        address="http://localhost:17625/ServiceTest.svc"
        binding="basicHttpBinding"
        bindingConfiguration="UsernameWithTransportCredentialOnly"
        name="BasicEndpoint"
        contract="WcfWebHttpIISHostingSample.ITestService">
      </endpoint>
    </service>
  </services>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="false" />
</system.serviceModel>

我尝试更改配置中的一些细节,但仍然有错误。

================================================ ====================

我也看到this topic 有同样的问题,但提供的解决方案对我不起作用。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    您的 WCF 服务在 IIS 中支持的身份验证类型(即匿名)与使用 Basic 的 WCF 配置之间似乎存在冲突。

    要么在 IIS 中为 WCF 服务启用身份验证下的“基本”,要么从配置文件中删除 &lt;security&gt; 元素。

    我不确定哪个适合你。

    【讨论】:

    • 我在 IIS 管理器中禁用了 Anonymous Authentification 并启用了 Basic Authentification 但错误仍然存​​在。
    【解决方案2】:

    可能是因为我在创建项目后更改了Authentification类型,解决方法是修改MyProject\.vs\config\applicationhost.config中的文件

    在此文件中,将anonymousAuthentication 设置为false,将basicAuthentication 设置为true

    <security>
    
        <access sslFlags="None" />
    
        <applicationDependencies>
            <application name="Active Server Pages" groupId="ASP" />
        </applicationDependencies>
    
        <authentication>
            <!-- this line was set to "true" -->
            <anonymousAuthentication enabled="false" userName="" />
    
            <!-- this line was set to "false" -->
            <basicAuthentication enabled="true" />
    
    <!-- etc ... -->
    

    【讨论】:

      猜你喜欢
      • 2013-05-30
      • 1970-01-01
      • 2012-01-03
      • 2015-08-12
      • 2017-06-13
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多