3

这真让我抓狂。我正在尝试通过 ASP.NET Web 表单访问 WCF 服务,我正在为channelfactoryup 设置绑定,如下所示:

BasicHttpBinding b = null;

if (Communication.SlServiceURL.StartsWith("https"))
    b = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
else
{
    b = new BasicHttpBinding();
    b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
}

b.MaxBufferSize = 2147483647;
b.MaxReceivedMessageSize = 2147483647;
b.Security.Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.Ntlm, ProxyCredentialType = HttpProxyCredentialType.None };
b.Security.Message = new BasicHttpMessageSecurity { ClientCredentialType = BasicHttpMessageCredentialType.UserName };

然后我通过以下方式创建一个新的 Channel Wrapper:

public ClientChannelWrapper(Binding binding, EndpointAddress remoteAddress)
{
    m_Factory = new ChannelFactory<T>(binding, remoteAddress);
}

我将绑定和https://[myservice]/myservice.svc URL 作为remoteAddress.

问题是:当我使用 IIS 7 在我的生产服务器中调用服务时,站点上启用了 Windows 身份验证,并且只有“NTLM”作为身份验证的提供者,其他所有内容都被禁用(没有匿名、表单等)我得到了例外:

异常类型:MessageSecurityException

异常消息:HTTP 请求未经客户端身份验证方案“Ntlm”授权。从服务器收到的身份验证标头是“NTLM”。

这很奇怪,我似乎找不到解决方法。我还有一个托管在另一个 ASP.NET 表单中的Silverlight应用程序,它与这个绑定工作得很好,这让我感到害怕,因为为什么在同一个 IIS 站点中托管的 ASP.NET 站点中不能正常工作。

也很奇怪:当使用 F5 从 Visual Studio 启动站点时,它在访问 IIS7 机器中的生产 WCF 服务时工作。一旦我部署该站点,我就会得到异常。

编辑:现在很清楚为什么Silverlight的行为与 ASP.NET 不同,因为Silverlight直接通过客户端计算机与服务进行通信。除了例外,仍然没有运气。

4

0 回答 0