首页 文章

主机上配置的认证方案('Basic')

提问于
浏览
1

当我登录到wcf localhost/Service1.svc 时,我收到错误:

主机上配置的身份验证方案('Basic')不允许在绑定'BasicHttpBinding'('Anonymous')上配置的身份验证方案 . 请确保将SecurityMode设置为Transport或TransportCredentialOnly . 此外,可以通过IIS管理工具,通过ServiceHost.Authentication.AuthenticationSchemes属性,在元素的应用程序配置文件中更改此应用程序的身份验证方案,通过更新绑定上的ClientCredentialType属性,或通过调整HttpTransportBindingElement上的AuthenticationScheme属性 .

Web.Config中

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />
    <customErrors mode="Off"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="BasicAuthHttpModule"
        type="WCF_Customer_RentalObject.BasicAuthHttpModule, WCF_Customer_RentalObject"/>
    </modules>
  </system.webServer>
</configuration>

Do you know what I have to do?

当我添加这个:

<bindings>
  <basicHttpBinding>
    <binding> <!--Notice, no name attribute set-->
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

我收到另一个错误:

主机上配置的身份验证方案('Basic')不允许在绑定'BasicHttpBinding'('Negotiate')上配置的身份验证方案 . 请确保将SecurityMode设置为Transport或TransportCredentialOnly . 此外,可以通过IIS管理工具,通过ServiceHost.Authentication.AuthenticationSchemes属性,在元素的应用程序配置文件中更改此应用程序的身份验证方案,通过更新绑定上的ClientCredentialType属性,或通过调整HttpTransportBindingElement上的AuthenticationScheme属性 .

1 回答

  • 2

    1. Suggested client config:

    <bindings>
      <basicHttpBinding>
        <binding name="basicEndpoint">
          <security mode="Transport" >
            <transport clientCredentialType="Basic"
                       proxyCredentialType="None"
                       realm="" />
          </security>
        </binding>
      </basicHttpBinding>
    

    可能是 mode="TransportCredentialOnly"> 没关系
    <transport clientCredentialType="Windows" /> 可能不是最好的

    2. Pass the credentials :

    HelloServiceClient client = new HelloServiceClient();
    client.ClientCredentials.UserName.UserName = userName;
    client.ClientCredentials.UserName.Password = password;
    String msg = client.SayHello(userName);
    

    希望能帮助到你

相关问题