无法使用WCF

时间:2018-02-13 15:03:55

标签: c# wcf

我正在尝试使用基本身份验证创建一个Web服务WCF,关注this tutorial

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

  

System.NotSupportedException:Lesschémasd'authentification   configurésurl'hôte('Anonymous')n'autorisent pasceuxconfigurés   sur la liaison'BasicHttpBinding'('Basic')。 Assurez-vous que la   valeur de SecurityMode est Transport ou TransportCredentialOnly。恩   outre,cecipeutêtrerésoluenmodifiantlesschémas   d'authentification de cette application par le biais de l'outil de   IIS,lapropriété   ServiceHost.Authentication.AuthenticationSchemes,dans le fichier de   配置应用程序,au niveau de l'élément   ,enmetààjourlapropriété   ClientCredentialType de la liaison ou en ajustantlapropriété   AuthenticationSchemedel'élémentHttpTransportBindingElement。

它表示方案'Anonymous'和'Basic'之间存在问题。但我不知道它是什么。

有我的代码:

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遇到了同样的问题,但提供的解决方案对我不起作用。

2 个答案:

答案 0 :(得分:0)

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

在IIS中为WCF服务的身份验证启用“基本”,或从配置文件中删除<security>元素。

我不确定哪个适合你。

答案 1 :(得分:0)

也许是因为我在创建项目后更改了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 ... -->
相关问题