jhorsman
3/15/2018 - 10:47 AM

Get a Tridion Core Service client

void Main()
{
        var client =
               getClient("SERVER", "USER", "PASSWORD", "DOMAIN");
        Console.WriteLine("Starting V" + client.GetApiVersion());

}

SessionAwareCoreServiceClient getClient(string hostName, string username,string password, string domain = null)
        {
            var httpBinding = new WSHttpBinding
                {
                    MaxReceivedMessageSize = 2147483647,
                    ReaderQuotas = new XmlDictionaryReaderQuotas
                        {
                            MaxStringContentLength = 2147483647,
                            MaxArrayLength = 2147483647
                        }
                };

        var remoteAddress =
               new EndpointAddress(
                       string.Format("http://{0}/webservices/CoreService2013.svc/wsHttp", hostName));

        var coreServiceClient = new SessionAwareCoreServiceClient(httpBinding, remoteAddress);

        if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
        {
               coreServiceClient.ClientCredentials.Windows.ClientCredential.UserName = username;
               coreServiceClient.ClientCredentials.Windows.ClientCredential.Password = password;
        }

        if (!string.IsNullOrEmpty(domain))
               coreServiceClient.ClientCredentials.Windows.ClientCredential.Domain = domain;

        return coreServiceClient;
}