WebServiceHostFactory和IIS身份验证

时间:2009-02-22 14:55:36

标签: wcf

我在IIS中使用WebServiceHostFactory时遇到问题。

“IIS指定的身份验证方案'IntegratedWindowsAuthentication,匿名',但绑定仅支持一种身份验证方案的规范。有效的身份验证方案是摘要,协商,NTLM,基本或匿名。更改IIS设置,以便只有一个使用认证方案。“

I wanted to keep both authentication schemes and managed to do so by not using the factory but setting up the endpoint manualy in web.config.

我的问题是WebServiceHostFactory做什么来获得这个结果?我的印象是WebServiceHostFactory会将绑定设置为我在配置中使用的webHttpBinding。

编辑: 我在反射器中查看了WebServiceHostFactory,它没有做任何聪明的事情。它只是WebServiceHost的一个简单工厂。

如果在config中设置端点,IIS是否仍然使用服务主机?或者WebServiceHost的设置方式不同。

4 个答案:

答案 0 :(得分:3)

这对我有用。如下所示,在早期(在服务主机打开之前)添加虚拟端点似乎已经成功了。 (这篇MSDN文章暗示了http://msdn.microsoft.com/en-us/library/bb412178.aspx。)

public class MyWebServiceHost : WebServiceHost
{
    public MyWebServiceHost (Type serviceType, params Uri[] baseAddresses) : base(serviceType, baseAddresses)
    {
        // Inserting this dummy endpoint config seemingly does the trick:
        AddServiceEndpoint(typeof(IMyContract), new WebHttpBinding(), string.Empty);
    }

    protected override void ApplyConfiguration()
    {
        // Typical programmatic configuration here per:
        // http://msdn.microsoft.com/en-us/library/aa395224.aspx
    }
}

我猜这会阻止WebServiceHost创建默认端点,从而关闭一堆功能。

答案 1 :(得分:1)

我不确定WebServiceHostFactory,但听起来你在IIS中托管服务并且它选择了多个身份验证方法。如果您有IIS 5或6,请尝试进入IIS并查看包含您的服务的网站或虚拟目录的属性。转到“目录安全性”选项卡,单击“匿名访问和身份验证控制”下的“编辑”按钮,然后取消选中“匿名访问”或“集成Windows身份验证”。我不确定IIS7。

答案 2 :(得分:1)

在IIS7下,您可能找不到可以管理集成Windows身份验证设置的位置。要在IIS7管理控制台中查看设置,您需要按照以下文章中描述的步骤操作:http://msdn.microsoft.com/en-us/library/x8a5axew.aspx(标题为“错误:调试因未启用集成Windows身份验证而失败”,如果链接不起作用)

希望它有所帮助。

答案 3 :(得分:-1)

在web.config->中禁用安全性配置标签

  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding>
          <security mode="None">
            <transport clientCredentialType="Windows"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

那么你的wcf服务不需要身份验证......

相关问题