WebServiceHostFactory 和 IIS 身份验证 [英] WebServiceHostFactory and IIS authentication

查看:25
本文介绍了WebServiceHostFactory 和 IIS 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I encounter a problem with using the WebServiceHostFactory in IIS.

"IIS 指定了身份验证方案 'IntegratedWindowsAuthentication, Anonymous',但绑定只支持指定一个身份验证方案.有效的身份验证方案是 Digest、Negotiate、NTLM、Basic 或 Anonymous.更改 IIS 设置,以便只有一个使用身份验证方案."

"IIS specified authentication schemes 'IntegratedWindowsAuthentication, 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."

我想保留两种身份验证方案,并通过不使用工厂而是在 web.config 中手动设置端点来设法做到这一点.

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

My question is what is WebServiceHostFactory doing to get this result? I was under the impression that WebServiceHostFactory would set the binding to the same webHttpBinding that I used in my config.

我在反射器中查看了 WebServiceHostFactory 并且它没有做任何聪明的事情.它只是 WebServiceHost 的一个简单工厂.

I have looked at WebServiceHostFactory in reflector and it is not doing anything clever. It is just a simple factory for the WebServiceHost.

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

Does IIS still use a service host if you set up the endpoint in config? Or is the WebServiceHost setting things up differently.

推荐答案

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

This is what worked for me. Adding a dummy endpoint early on (before the service host is opened) as shown below seems to have done the trick. (This MSDN article hinted at this 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 创建默认端点,从而关闭一系列功能.

I'm guessing this prevents WebServiceHost from creating a default endpoint, and thus shutting down a bunch of functionality.

这篇关于WebServiceHostFactory 和 IIS 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆