public bool Init() { if (!Common.Initialized) { throw new InvalidOperationException("Сервис не инициализирован. Используйте метод InitService()"); } string endpoint = Common.EndpointAddressDictionary ?? throw new ArgumentNullException(nameof(Common.EndpointAddressDictionary)); var addr = new EndpointAddress(Common.EndpointAddressDictionary); var binding = new BasicHttpBinding { Security = new BasicHttpSecurity { Mode = BasicHttpSecurityMode.Transport, Transport = new HttpTransportSecurity() { ClientCredentialType = HttpClientCredentialType.Basic } } }; service = new EnterpriseServicePortTypeClient(binding, addr); service.ClientCredentials.UserName.UserName = Common.UserName; service.ClientCredentials.UserName.Password = Common.UserPassword; return(true); }
private static void GetBusinessEntities() { EnterpriseServicePortTypeClient soap = new EnterpriseServicePortTypeClient(); soap.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings.Get("UserName"); soap.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings.Get("Password"); getBusinessEntityListRequest getBusinessEntityListRequest = new getBusinessEntityListRequest(); getBusinessEntityListResponse getBusinessEntityListResponse = new getBusinessEntityListResponse(); getBusinessEntityListRequest.listOptions = new ListOptions { count = _count.ToString(), offset = _offset.ToString() }; try { //BusinessEntity[] students = { // new BusinessEntity { active = true, createDate = DateTime.Now, guid = Guid.NewGuid().ToString() }, // new BusinessEntity { active = true, createDate = DateTime.Now, guid = Guid.NewGuid().ToString() }, // new BusinessEntity { active = true, createDate = DateTime.Now, guid = Guid.NewGuid().ToString() } // }; ////ParallelQuery<int> //DataTable dtTmp = students.ToDataTable(); getBusinessEntityListResponse = soap.GetBusinessEntityList(getBusinessEntityListRequest); _total = getBusinessEntityListResponse.businessEntityList.total; DataTable dtTmp = getBusinessEntityListResponse.businessEntityList.businessEntity.ToDataTable(); int c = BusinessEntityInsertUdt(dtTmp); for (int j = _count; j < _total + _count; j += _count) { getBusinessEntityListRequest.listOptions = new ListOptions { count = _count.ToString(), offset = j.ToString() //_offset.ToString() }; Console.WriteLine($"{_count} {j}"); var watch = System.Diagnostics.Stopwatch.StartNew(); getBusinessEntityListResponse = soap.GetBusinessEntityList(getBusinessEntityListRequest); watch.Stop(); Console.WriteLine($"GET {lostTime} : {watch.ElapsedMilliseconds}"); watch = System.Diagnostics.Stopwatch.StartNew(); dtTmp = getBusinessEntityListResponse.businessEntityList.businessEntity.ToDataTable(); watch.Stop(); Console.WriteLine($"ToDataTable() {lostTime} : {watch.ElapsedMilliseconds}"); watch = System.Diagnostics.Stopwatch.StartNew(); c = BusinessEntityInsertUdt(dtTmp); watch.Stop(); Console.WriteLine($"BusinessEntityInsertUdt(dtTmp) {lostTime} : {watch.ElapsedMilliseconds}"); } //getBusinessEntityListResponse.businessEntityList.total //2931499 } catch (Exception ex) { Console.WriteLine(ex); } }