通过HTTP进行基本身份验证的WCF服务

时间:2016-04-28 09:47:15

标签: c# wcf iis

我正在使用

开发WCF服务应用程序
  • 托管该应用的服务器位于域
  • 使用基本身份验证授权客户端
  • 将用户名和密码映射到AD用户
  • HTTP
  • IIS仅允许Basic Auth

我找到了this MSDN article,但这是 HTTPS 的示例。

已经对web.config进行了巨大的挂载尝试,但我无法弄清楚如何配置。

任何帮助将不胜感激:)

由于

1 个答案:

答案 0 :(得分:0)

您可以将绑定更改为基本绑定而不是wsBining

<basicHttpBinding>
        <binding name="BasicBinding" receiveTimeout="00:01:00"
          sendTimeout="00:01:00">
          <security mode="None">
            <transport clientCredentialType="Basic"/>
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </basicHttpBinding>

另一个选项是,您可以向应用程序添加自定义用户验证方法(Class)并在其中创建身份验证

<serviceBehaviors>
<behavior name="ServiceBehaviour">
<useRequestHeadersForMetadataAddress />
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication customCertificateValidatorType="WCFServices.clsCertificateValidator, App_Code/WCFServices" certificateValidationMode="Custom" revocationMode="NoCheck" />
</clientCertificate>
<userNameAuthentication userNamePasswordValidationMode="Custom"              customUserNamePasswordValidatorType="WCFServices.clsUserValidator, App_Code/WCFServices" />
<peer>
<peerAuthentication customCertificateValidatorType="WCFServices.clsCertificateValidator, App_Code/WCFServices" certificateValidationMode="Custom" revocationMode="NoCheck" />
<messageSenderAuthentication customCertificateValidatorType="WCFServices.clsCertificateValidator, App_Code/WCFServices" certificateValidationMode="Custom" revocationMode="NoCheck" />
</peer>
<issuedTokenAuthentication audienceUriMode="Never" customCertificateValidatorType="WCFServices.clsCertificateValidator, App_Code/WCFServices" certificateValidationMode="Custom" revocationMode="NoCheck" allowUntrustedRsaIssuers="true" />
</serviceCredentials>
</behavior>
</serviceBehaviors>

在此课程中,如果您需要停止用户抛出异常。