wcf - 如何禁用 WCF 数据服务的身份验证方案

标签 wcf wcf-data-services

当我将 WCF 数据服务部署到生产托管时,我开始收到以下错误(或类似错误,具体取决于哪些身份验证方案处于事件状态):

IIS specified authentication schemes 'Basic, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.

显然,WCF 数据服务(一般来说是 WCF?)无法处理多个事件身份验证方案。

好的,我知道我可以通过 IIS 控制面板在 Web 应用程序上禁用除一个之外的所有身份验证方案....通过支持请求!!

有没有办法在 web.config 中的每个服务级别指定单一身份验证方案?

我认为这可能就像更改 <system.serviceModel> 一样简单但是...事实证明,WCF 数据服务不会在 Web 配置中自行配置。如果你看DataService<>类它没有实现 [ServiceContract]因此您不能在 <service><endpoint> 中引用它...我认为通过 XML 更改其配置将需要它。

附注我们的主机使用的是 II6,但 IIS6 和 IIS7 的两种解决方案都值得赞赏。

最佳答案

首先可以在 Web 配置文件上配置数据服务。 DataService 使用的契约称为 System.Data.Services.IRequestHandler。

您可以在 Web 配置文件中执行以下操作来配置它。

在 system.servicemodel 元素的服务标记上添加

<service name="{you service type name including the namespace i.e. myapplication.myservice}">
    <endpoint address="" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler">
    </endpoint>
</service>

一旦掌握了这些,您就可以开始使用标准 WCF 配置元素来配置各种事物。

其次,要启用或禁用 IIS 中特定服务的身份验证方法,您可以执行以下操作:

在 IIS 管理单元上,右键单击您的服务文件(即 yourservice.svc),然后单击“属性”。 进入属性后,转到文件安全选项卡,然后选择身份验证和访问控制组框中的编辑按钮。之后就像在 IIS 中设置目录安全一样。

最后一个建议是,根据任何故障排除,在使用 xml 配置进行配置时启用 wcf 诊断非常重要,因为数据服务日志记录是用 WCF 编写的,所以 wcf 内容丰富且信息丰富。

您可以在WCF Administration and Diagnostics上找到更多相关信息。

希望我能帮助您解决问题

让我知道事情进展如何。

问候

丹尼尔·波特拉

更新:

嗨施耐德

要在 xml 中指定身份验证方案,请阅读下面的内容

以windows身份验证为例

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="MyBindingName" >
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="{you service type name including the namespace i.e. myapplication.myservice}">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="MyBindingName" contract="System.Data.Services.IRequestHandler">
        </endpoint>
      </service>
    </services>
  </system.serviceModel>
</configuration>

对于其他类型的身份验证,请查看 MSDN 库以获取示例

Common Scenarios for security

关于wcf - 如何禁用 WCF 数据服务的身份验证方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2542119/

相关文章:

asp.net - WCF 如何作为数据源工作?

c# - ADO 数据服务的预测

c# - config.DataServiceBehavior.MaxProtocolVersion 从 V3.0 到 V2.0 的更改无法恢复

java - 在java中连接到https服务——主机名中有 "_"?

c# - 是否有用于序列化自定义对象的 ODataSerializer?

c# - 将现有接口(interface)重新用作 WCF 接口(interface)。契约(Contract)装饰是否影响现有应用程序?有什么坏处吗?

jquery - WCF - "Encountered unexpected character ' c'。”

wcf - 您可以将 WCF 数据服务(ne OData、ne Astoria、ne ADO.NET 数据服务)与 NetTcpBinding 一起使用吗?

.net - WCF 即服务 : Modifying app. 配置文件

.net - Web 服务中的异常(exception)