2015-11-03 75 views
1

上配置的認證方案當我登錄到WCF 本地主機/ Service1.svc我得到錯誤:主機( '基本')

The authentication schemes configured on the host ('Basic') do not allow those configured on the binding 'BasicHttpBinding' ('Anonymous'). Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly. Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.

的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> 

你知道我必須做什麼嗎?

當我補充一點:

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

我得到另一個錯誤:

The authentication schemes configured on the host ('Basic') do not allow those configured on the binding 'BasicHttpBinding' ('Negotiate'). Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly. Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.

+0

是的,我讀,但我不'噸知道如何在web.config中更改此 –

+0

你谷歌嗎? https://msdn.microsoft.com/en-us/library/ms731884(v=vs.110).aspx –

回答

2

1.推薦客戶端配置:

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

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

2.憑據傳遞:

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

希望它可以幫助