Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Created March 15, 2018 10:47
Show Gist options
  • Select an option

  • Save jhorsman/ebefd5826715ddf461166badb1873f39 to your computer and use it in GitHub Desktop.

Select an option

Save jhorsman/ebefd5826715ddf461166badb1873f39 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment