Advertisement
Guest User

Untitled

a guest
Apr 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. private T GetWebChannel<T>(string endpointPath, string user, string pass, bool corsEnabled = false)
  2. {
  3. var endpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(T)))
  4. {
  5. Address = new EndpointAddress(endpointPath),
  6. Binding = new WebHttpBinding()
  7. {
  8. MaxReceivedMessageSize = 500000000,
  9. ReceiveTimeout = TimeSpan.FromMinutes(20),
  10. SendTimeout = TimeSpan.FromMinutes(20),
  11. OpenTimeout = TimeSpan.FromMinutes(20),
  12. CloseTimeout = TimeSpan.FromMinutes(20),
  13. TransferMode = TransferMode.Buffered,
  14. MaxBufferSize = 500000000,
  15. MaxBufferPoolSize = 500000000,
  16. Security = new WebHttpSecurity()
  17. {
  18. Mode = WebHttpSecurityMode.TransportCredentialOnly,
  19. Transport = new HttpTransportSecurity()
  20. {
  21. ClientCredentialType = HttpClientCredentialType.Ntlm
  22. }
  23. }
  24. }
  25. };
  26. endpoint.EndpointBehaviors.Add(new WebHttpBehavior());
  27. if (corsEnabled)
  28. endpoint.EndpointBehaviors.Add(new EnableCrossOriginResourceSharingBehavior());
  29.  
  30. var factory = new ChannelFactory<T>(endpoint);
  31. factory.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
  32. if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pass))
  33. {
  34. factory.Credentials.Windows.ClientCredential.UserName = user;
  35. factory.Credentials.Windows.ClientCredential.Password = pass;
  36. }
  37. return factory.CreateChannel();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement