如何在WCF 4.0 REST服务上启用基本身份验证?

如何在WCF 4.0 REST服务上启用基本身份验证?,wcf,wcf-security,wcf-rest,Wcf,Wcf Security,Wcf Rest,首先,网上有很多关于这方面的文章,但大多数都是关于WCF3.5的。我正在使用WCF 4.0的一些特性,这使场景有点不同 以下是我的合同: [ServiceContract] public interface IService1 { [OperationContract] [WebGet(UriTemplate="x?v={value}")] string GetData(int value); } 以下是我的服务级别:

首先,网上有很多关于这方面的文章,但大多数都是关于WCF3.5的。我正在使用WCF 4.0的一些特性,这使场景有点不同

以下是我的合同:

[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebGet(UriTemplate="x?v={value}")]
        string GetData(int value);
    }
以下是我的服务级别:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
下面是我的web.config

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint automaticFormatSelectionEnabled="true" />
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
    <handlers>
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
    </handlers>
  </system.webServer>
现在,如果我在web.config中更改标准端点,则启用基本身份验证,如下所示:

<standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint automaticFormatSelectionEnabled="true">
          <security mode="Transport">
            <transport clientCredentialType="Basic" />
          </security>
        </standardEndpoint>
      </webHttpEndpoint>
    </standardEndpoints>

我得到以下错误:

找不到一个 匹配终结点的https方案 使用绑定WebHttpBinding。 注册基址方案包括 [http]


从这一点开始,我应该怎么做才能使它起作用?我在哪里检查每个请求提供的用户名/密码?

这无法在ASP.NET Development Server中测试,在IIS 7.5中运行时,我们必须安装基本身份验证,还需要创建证书并将ssl绑定与该应用程序相关联

所有这些都导致webservice方法需要基本的身份验证,但它是针对AD的

无法更改它以自己验证它

<standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint automaticFormatSelectionEnabled="true">
          <security mode="Transport">
            <transport clientCredentialType="Basic" />
          </security>
        </standardEndpoint>
      </webHttpEndpoint>
    </standardEndpoints>