Last active
March 1, 2016 21:19
-
-
Save DavidForster/a35f4824a8d9f59f0cba to your computer and use it in GitHub Desktop.
Configuration-less Core Service Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static ICoreService GetClient(string hostname, string username, string password) | |
{ | |
var binding = new BasicHttpBinding() | |
{ | |
MaxBufferSize = int.MaxValue, | |
MaxBufferPoolSize = int.MaxValue, | |
MaxReceivedMessageSize = int.MaxValue, | |
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas() | |
{ | |
MaxStringContentLength = int.MaxValue, | |
MaxArrayLength = int.MaxValue, | |
}, | |
Security = new BasicHttpSecurity() | |
{ | |
Mode = BasicHttpSecurityMode.TransportCredentialOnly, | |
Transport = new HttpTransportSecurity() | |
{ | |
ClientCredentialType = HttpClientCredentialType.Windows, | |
} | |
} | |
}; | |
hostname = string.Format("{0}{1}{2}", hostname.StartsWith("http") ? "" : "http://", hostname, hostname.EndsWith("/") ? "" : "/"); | |
var endpoint = new EndpointAddress(hostname + "/webservices/CoreService2012.svc/basicHttp"); | |
var factory = new ChannelFactory<ICoreService>(binding, endpoint); | |
factory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential(username, password); | |
return factory.CreateChannel(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment