3

I have created the .NET application by using Core Service, specifically ISessionAwareCoreService. Tridion used Windows authentication, but it is modified to LDAP authentication.

So I have to modify the Core Service application to use LDAP authentication, but it doesn't work so far.

Any idea to modify following source code to use LDAP authentication?

public static ISessionAwareCoreService GetCoreSeriviceClient()
{
    ISessionAwareCoreService client;
    ConfigFile.ConfigIni configFile = new ConfigFile.ConfigIni();
    ChannelFactory<ISessionAwareCoreService> factory = new ChannelFactory<ISessionAwareCoreService>("netTcp_201603");
    NetworkCredential networkCredential = new NetworkCredential("UserName", "Password");
    factory.Credentials.Windows.ClientCredential = networkCredential;

    client = factory.CreateChannel();
    return client;
}

UPDATE

I modified my program following answers and did some trials, but I couldn't make ISessionAwareCoreService work with LDAP authentication. So I replaced ISessionAwareCoreService to ICoreService , and replaced netTcp binding to basicHttp binding.

public static ICoreService GetCoreSeriviceClient()
{
    ICoreService client;
    ConfigFile.ConfigIni configFile = new ConfigFile.ConfigIni();
    ChannelFactory<ICoreService> factory = new ChannelFactory<ICoreService>("basicHttp_201603");

    factory.Credentials.UserName.UserName = configFile.GetValue("user", "name");
    factory.Credentials.UserName.Password = configFile.GetValue("user", "password");

    client = factory.CreateChannel();
    return client;
}

And binding configuration is followning, set Basic to clientCredentialType

  <basicHttpBinding>
    <binding name="basicHttp" maxReceivedMessageSize="2147483647"  sendTimeout="00:20:00">
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
      <security mode="TransportCredentialOnly">
        <!-- For LDAP or SSO authentication of transport credentials, use clientCredentialType="**Basic**" -->
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
  • Your code looks fine to me. Did you configure your [Tridion-Home]\webservices\Web.config to LDAP authentication? I can see you are using the NetTcpEndpoint, Is that core service you are running inside the cms server? – Velmurugan Jun 28 '18 at 12:50
3

First of all, you will have to change both server-side and client-side WCF configuration, so Message based security based on username/password is used instead of Windows authentication.

Secondly, you will have to provide the username/password in code in a different way than you have in your example:

factory.Credentials.Windows.ClientCredential = networkCredential;

Is specific for Windows authentication.

For a general username/password token, you use something like:

factory.Credentials.UserName.UserName = userName;
factory.Credentials.UserName.Password = password;
1

Sample code for without config to call coreservice:

static ISessionAwareCoreService GetCoreSeriviceClient(string hostname, string username, string password)
        {
            var binding = new NetTcpBinding
            {
                MaxBufferSize = int.MaxValue,
                MaxBufferPoolSize = int.MaxValue,
                MaxReceivedMessageSize = int.MaxValue,
                Name = "netTcp_201603",
                TransactionFlow = true,
                TransactionProtocol = TransactionProtocol.OleTransactions,
                ReaderQuotas = new XmlDictionaryReaderQuotas
                {
                    MaxStringContentLength = int.MaxValue,
                    MaxArrayLength = int.MaxValue
                }
            };

            var endpoint = new EndpointAddress(String.Format("net.tcp://{0}:2660/CoreService/201603/netTcp",hostname));
            var factory = new ChannelFactory<ISessionAwareCoreService>(binding, endpoint);

            var credentialBehaviour = factory.Endpoint.Behaviors.Find<System.ServiceModel.Description.ClientCredentials>();
            credentialBehaviour.UserName.UserName = username;
            credentialBehaviour.UserName.Password = password;
            return factory.CreateChannel();
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.