Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private T GetWebChannel<T>(string endpointPath, string user, string pass, bool corsEnabled = false)
- {
- var endpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(T)))
- {
- Address = new EndpointAddress(endpointPath),
- Binding = new WebHttpBinding()
- {
- MaxReceivedMessageSize = 500000000,
- ReceiveTimeout = TimeSpan.FromMinutes(20),
- SendTimeout = TimeSpan.FromMinutes(20),
- OpenTimeout = TimeSpan.FromMinutes(20),
- CloseTimeout = TimeSpan.FromMinutes(20),
- TransferMode = TransferMode.Buffered,
- MaxBufferSize = 500000000,
- MaxBufferPoolSize = 500000000,
- Security = new WebHttpSecurity()
- {
- Mode = WebHttpSecurityMode.TransportCredentialOnly,
- Transport = new HttpTransportSecurity()
- {
- ClientCredentialType = HttpClientCredentialType.Ntlm
- }
- }
- }
- };
- endpoint.EndpointBehaviors.Add(new WebHttpBehavior());
- if (corsEnabled)
- endpoint.EndpointBehaviors.Add(new EnableCrossOriginResourceSharingBehavior());
- var factory = new ChannelFactory<T>(endpoint);
- factory.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
- if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pass))
- {
- factory.Credentials.Windows.ClientCredential.UserName = user;
- factory.Credentials.Windows.ClientCredential.Password = pass;
- }
- return factory.CreateChannel();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement