当我登录wcf localhost / Service1.svc 时,我收到错误:
主机上配置的身份验证方案(“基本”)不会 允许在绑定'BasicHttpBinding'上配置的那些 ('匿名')。请确保将SecurityMode设置为 运输或运输保险仅限。另外,这可能是 通过更改此应用程序的身份验证方案来解决 通过IIS管理工具,通过 ServiceHost.Authentication.AuthenticationSchemes属性,在 应用程序配置文件在 element,通过更新绑定上的ClientCredentialType属性, 或者通过调整AuthenticationScheme属性 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>
我收到另一个错误:
主机上配置的身份验证方案(“基本”)不允许在绑定“BasicHttpBinding”上配置的身份验证方案 ('谈判')。请确保将SecurityMode设置为 运输或运输保险仅限。另外,这可能是 通过更改此应用程序的身份验证方案来解决 通过IIS管理工具,通过 ServiceHost.Authentication.AuthenticationSchemes属性,在 应用程序配置文件在 element,通过更新绑定上的ClientCredentialType属性, 或者通过调整AuthenticationScheme属性 HttpTransportBindingElement。
答案 0 :(得分:2)
<强> 1。建议的客户端配置:
<bindings>
<basicHttpBinding>
<binding name="basicEndpoint">
<security mode="Transport" >
<transport clientCredentialType="Basic"
proxyCredentialType="None"
realm="" />
</security>
</binding>
</basicHttpBinding>
可能mode="TransportCredentialOnly">
可以
但是<transport clientCredentialType="Windows" />
可能不是最好的
<强> 2。传递凭据:
HelloServiceClient client = new HelloServiceClient();
client.ClientCredentials.UserName.UserName = userName;
client.ClientCredentials.UserName.Password = password;
String msg = client.SayHello(userName);
希望有所帮助