11

在尝试连接到核心服务时,我收到以下错误:

客户端身份验证方案“匿名”禁止 HTTP 请求

Tridion 环境使用来自 SiteMinder 的 SSO 进行配置。

这是我的代码:

public static ICoreService2010 GetTridionClient()
{
    var binding = new BasicHttpBinding()
    {
        Name = "BasicHttpBinding_TridionCoreService",
        CloseTimeout = new TimeSpan(0, 1, 0),
        OpenTimeout = new TimeSpan(0, 1, 0),
        ReceiveTimeout = new TimeSpan(0, 10, 0),
        SendTimeout = new TimeSpan(0, 1, 0),
        AllowCookies = false,
        BypassProxyOnLocal = false,
        HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
        MaxBufferSize = 4194304, // 4MB
        MaxBufferPoolSize = 4194304,
        MaxReceivedMessageSize = 4194304,
        MessageEncoding = WSMessageEncoding.Text,
        TextEncoding = System.Text.Encoding.UTF8,
        TransferMode = TransferMode.Buffered,
        UseDefaultWebProxy = true,
        ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
        {
            MaxDepth = 32,
            MaxStringContentLength = 4194304, // 4MB
            MaxArrayLength = 4194304,
            MaxBytesPerRead = 4194304,
            MaxNameTableCharCount = 16384
        },
        Security = new BasicHttpSecurity()
        {
            Mode = BasicHttpSecurityMode.TransportCredentialOnly,
            Transport = new HttpTransportSecurity()
            {
                ClientCredentialType = HttpClientCredentialType.None,
            },
            Message = new BasicHttpMessageSecurity()
            {
                ClientCredentialType = BasicHttpMessageCredentialType.UserName
            }
        }
    };

    string hostname = ConfigurationManager.AppSettings["TridionUrl"];
    string username = ConfigurationManager.AppSettings["TridionUsername"];

    hostname = string.Format("{0}{1}{2}", 
                              hostname.StartsWith("http") ? "" : "http://",
                              hostname, 
                              hostname.EndsWith("/") ? "" : "/");
    var endpoint = new EndpointAddress(hostname +
                              "/webservices/CoreService.svc/basicHttp_2010");
    var factory = new ChannelFactory<ICoreService2010>(binding, endpoint);
    factory.Credentials.UserName.UserName = username;

    return factory.CreateChannel();
}

是否有人有使用 Windows 以外的身份验证类型与核心服务交互的经验?

更新:

我现在得到错误:

客户端身份验证方案“基本”禁止 HTTP 请求。

应该在 /webservices/web.config 中为绑定使用什么 clientCredentialType?

当我在 /webservies/web.config 中取消注释 SsoAgentHttpModule 时,我们在 web 服务上收到 500 错误,因此 SDL 告诉我们不要将此注释掉。

我认为 CoreService 需要此模块才能使用身份验证方案“基本”进行身份验证?

4

1 回答 1

6

您的代码有两个问题:

  1. 您已在服务器上将身份验证设置为匿名,并假设应该在客户端上设置相同的身份,但事实并非如此。您还在服务器上启用了 LDAP SSO 模块,一旦您打开匿名身份验证,该模块就会启动。在客户端,它看起来像普通的基本身份验证,所以你的客户端安全代码应该是这样的:

    Security = new BasicHttpSecurity() 
        { 
            Mode = BasicHttpSecurityMode.TransportCredentialOnly, 
            Transport = new HttpTransportSecurity() 
            { 
                ClientCredentialType = HttpClientCredentialType.Basic, 
            }
        } 
    
  2. 您已设置用户名,但未设置密码,因此:

    factory.Credentials.UserName.UserName = username;
    factory.Credentials.UserName.Password = password; 
    

另外,请记住,您可能需要在设置用户时指定用户名限定符(默认为 SSO),例如 SSO\user

如果您仍然有问题,这应该会让您更近一步 - 请更新您的问题,最近有例外。

于 2012-03-09T07:44:04.320 回答