【发布时间】: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 有同样的问题,但提供的解决方案对我不起作用。
【问题讨论】: