PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Atlassian.Jira/Remote/JiraRemoteServiceFactory.cs

https://bitbucket.org/seansparkman/atlassian.net-sdk
C# | 62 lines | 48 code | 6 blank | 8 comment | 3 complexity | 03417d0bdca98cccda1bf95c699005be MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ServiceModel;
  6. using System.Xml;
  7. using System.ServiceModel.Dispatcher;
  8. using System.ServiceModel.Description;
  9. using System.ServiceModel.Channels;
  10. using System.IO;
  11. namespace Atlassian.Jira.Remote
  12. {
  13. /// <summary>
  14. /// Factory for JiraSoapServiceClient proxy
  15. /// </summary>
  16. public static class JiraRemoteServiceFactory
  17. {
  18. /// <summary>
  19. /// Creates and configures a JiraSoapServiceClient
  20. /// </summary>
  21. /// <param name="jiraBaseUrl">Base url to JIRA server</param>
  22. /// <returns>JiraSoapServiceClient</returns>
  23. public static JiraSoapServiceClient Create(string jiraBaseUrl)
  24. {
  25. if (!jiraBaseUrl.EndsWith("/"))
  26. {
  27. jiraBaseUrl += "/";
  28. }
  29. var endPointUri = new Uri(jiraBaseUrl + "rpc/soap/jirasoapservice-v2");
  30. BasicHttpBinding binding = null;
  31. if (endPointUri.Scheme == "https")
  32. {
  33. binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
  34. }
  35. else
  36. {
  37. binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
  38. }
  39. binding.TransferMode = TransferMode.Buffered;
  40. binding.UseDefaultWebProxy = true;
  41. binding.MaxReceivedMessageSize = int.MaxValue;
  42. binding.SendTimeout = new TimeSpan(0, 10, 0);
  43. binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
  44. binding.ReaderQuotas = new XmlDictionaryReaderQuotas()
  45. {
  46. MaxStringContentLength = int.MaxValue,
  47. MaxNameTableCharCount = int.MaxValue,
  48. };
  49. binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
  50. var endpoint = new EndpointAddress(endPointUri);
  51. var jiraSoapServiceClient = new JiraSoapServiceClient(binding, endpoint);
  52. jiraSoapServiceClient.Endpoint.Behaviors.Add(new RemoteWorklogPatchBehavior());
  53. return jiraSoapServiceClient;
  54. }
  55. }
  56. }