public bool Close() { try { _client.Wyloguj(_sid); if (_client != null) { _client.Close(); return(true); } } catch (Exception e) { throw new BiRClientSetUpException("Błąd podczas zamykania połączenia z usługą BiR", e); } return(false); }
public GusCompanyInfo GetCompanyByNip(string nip) { nip = NormalizeNip(nip); UslugaBIRzewnPublClient client = null; #if NETSTANDARD2_0 //var a = new MessageEncodingBindingElement(); var binding = new CustomBinding(); binding.Elements.Add(new TextMessageEncodingBindingElement()); binding.Elements.Add(new HttpsTransportBindingElement { AllowCookies = true, MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue }); client = new UslugaBIRzewnPublClient(binding, new EndpointAddress(Address)); #else //client = new UslugaBIRzewnPublClient( // new WSHttpBinding(SecurityMode.Transport) { MessageEncoding = WSMessageEncoding.Mtom }, // new EndpointAddress(Address)); //client = new UslugaBIRzewnPublClient( // new WSHttpBinding(SecurityMode.Transport) { MessageEncoding = WSMessageEncoding.Mtom }, // new EndpointAddress(Address)); var binding = new CustomBinding(); binding.Elements.Add(new MtomMessageEncodingBindingElement()); binding.Elements.Add(new HttpsTransportBindingElement { AllowCookies = true, MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue }); client = new UslugaBIRzewnPublClient(binding, new EndpointAddress(Address)); #endif using (var scope = new OperationContextScope(client.InnerChannel)) { var sid = client.Zaloguj(_userKey); var props = new HttpRequestMessageProperty(); props.Headers.Add("sid", sid); OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = props; var result = client.DaneSzukaj(new ParametryWyszukiwania() { Nip = nip }); client.Wyloguj(sid); try { var doc = new XmlDocument(); doc.LoadXml(result); var json = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.None, true); var response = JsonConvert.DeserializeObject <SearchDataResponse>(json); if (response?.Data != null) { response.Data.Nip = nip; } return(response?.Data); } catch { } } return(null); }
private void Logout() { client.Wyloguj(sid); }
private void buttonSearch_Click(object sender, EventArgs e) { labelErrorMsg.Visible = false; UslugaBIRzewnPublClient polaczenie = new UslugaBIRzewnPublClient(); string sid = polaczenie.Zaloguj("abcde12345abcde12345"); try { //Środowisko testowe usługi BIR1.1 OperationContextScope scope = new OperationContextScope(polaczenie.InnerChannel); HttpRequestMessageProperty requestMessageProperty = new HttpRequestMessageProperty(); requestMessageProperty.Headers.Add("sid", sid); OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessageProperty; StringBuilder sb = new StringBuilder(); foreach (object o in listBoxNIP.SelectedItems) { sb.AppendLine(o.ToString()); } string s = sb.ToString(); ParametryWyszukiwania parametryWyszukiwania = new ParametryWyszukiwania(); parametryWyszukiwania.Nipy = s; DataSet dataSet = new DataSet(); StringReader sr = new StringReader(polaczenie.DaneSzukajPodmioty(parametryWyszukiwania)); string przekazanieKomunikatu = polaczenie.GetValue("KomunikatKod"); int zwracanaWartosc = Convert.ToInt32(przekazanieKomunikatu); dataSet.ReadXml(sr); PrepareDataGridView1ForData(); if (zwracanaWartosc == 4) { labelErrorMsg.Visible = true; labelErrorMsg.Text = "Nie znaleziono żadnych podmiotów gospodarczych."; } else { dataGridView1.AutoGenerateColumns = false; dataGridView1.ColumnCount = 6; dataGridView1.Columns[0].Name = "Regon"; dataGridView1.Columns[0].HeaderText = "REGON"; dataGridView1.Columns[0].DataPropertyName = "Regon"; dataGridView1.Columns[1].HeaderText = "Nip"; dataGridView1.Columns[1].Name = "NIP"; dataGridView1.Columns[1].DataPropertyName = "Nip"; dataGridView1.Columns[2].Name = "Nazwa"; dataGridView1.Columns[2].HeaderText = "Nazwa"; dataGridView1.Columns[2].DataPropertyName = "Nazwa"; dataGridView1.Columns[3].Name = "Ulica"; dataGridView1.Columns[3].HeaderText = "Ulica"; dataGridView1.Columns[3].DataPropertyName = "Ulica"; dataGridView1.Columns[4].Name = "Miejscowosc"; dataGridView1.Columns[4].HeaderText = "Miejscowość"; dataGridView1.Columns[4].DataPropertyName = "Miejscowosc"; dataGridView1.Columns[5].Name = "KodPocztowy"; dataGridView1.Columns[5].HeaderText = "Kod Pocztowy"; dataGridView1.Columns[5].DataPropertyName = "KodPocztowy"; dataGridView1.DataSource = dataSet.Tables[0]; } } catch (Exception) { string error = "Usługa BIR1 niedostępna lub żaden identyfikator NIP nie został dodany do listy wyszukiwania."; string caption = "Błąd"; MessageBox.Show(error, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } polaczenie.Wyloguj(sid); }
public void Wylogoj(string adres) { klient.Wyloguj(adres); }